Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate agent description #57

Merged
merged 24 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2fb4ace
add prompt_prefix for MotleyAgentParent
Jul 2, 2024
a4c67f0
add prompt_prefix for crewai agents
Jul 2, 2024
8bf5b2c
add prompt_prefix for langchain agents
Jul 2, 2024
4a3b509
add prompt_prefix for llama_index agents
Jul 2, 2024
52e3c75
change sequence of the prompt_prefix argument
Jul 2, 2024
fa34eea
add prompt_prefix for ReactToolCallingAgent
Jul 2, 2024
b916889
update tests agents
Jul 2, 2024
aeec6ae
update delegation_demo example
Jul 2, 2024
c526bfa
update delegation_demo example db_path for integration tests
Jul 2, 2024
24826df
update single_llama_index example
Jul 2, 2024
20fb556
update integration tests cache
Jul 2, 2024
1523bae
update single_llama_index integration test data
Jul 2, 2024
d2e57bd
update blog with images.ipynb and update integration test cache
Jul 2, 2024
e904d4d
update math via python code with a single agent.ipynb and update inte…
Jul 2, 2024
19d21e1
removing unnecessary changes
Jul 2, 2024
17548fc
update run_integration_tests
Jul 2, 2024
4ed3da7
update cache for Math via python code with a single agent.ipynb run_i…
Jul 2, 2024
02838ea
update old examples
Jul 2, 2024
c3c1798
update examples
Jul 2, 2024
30a6f7e
update CrewAIMotleyAgent set prompt_prefix default None
Jul 3, 2024
e639c0c
replace backstory to prompt_prefix for examples
Jul 3, 2024
f936b2e
update cache for delegation_demo integration_test
Jul 3, 2024
d7cb834
update cache for blog_with_images_ipynb integration_test
Jul 3, 2024
4ee824a
update cache for math_via_python_code_with_a_single_agent_ipynb integ…
Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/Advanced output handling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -558,7 +558,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
5 changes: 3 additions & 2 deletions examples/Blog with Images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"id": "16b8ccc4-b34b-47c3-94ee-cbd82ef4c8f2",
"metadata": {},
"source": [
"We use this example of creating a web search-based blog with illustrations to show how to \n\n",
"We use this example of creating a web search-based blog with illustrations to show how to \n",
"\n",
"* instantiate one agent each from Langchain, CrewAI, and LlamaIndex\n",
"* give agents as tools to other agents\n",
"* create tasks and link them using the >> operator"
Expand Down Expand Up @@ -115,7 +116,7 @@
"# You can give agents as tools to other agents\n",
"writer = ReActMotleyAgent(\n",
" name=\"AI writer agent\",\n",
" description=\"\"\"Conduct a comprehensive analysis of the latest advancements in AI in 2024.\n",
" prompt_prefix=\"\"\"Conduct a comprehensive analysis of the latest advancements in AI in 2024.\n",
" Identify key trends, breakthrough technologies, and potential industry impacts.\n",
" Your final answer MUST be a full analysis report\"\"\",\n",
" tools=[researcher],\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/Caching and observability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"\n",
"writer = ReActMotleyAgent(\n",
" name=\"writer\",\n",
" description=\"Using the results of a web search, write an article on the latest advancements in AI in 2024.\",\n",
" prompt_prefix=\"Using the results of a web search, write an article on the latest advancements in AI in 2024.\",\n",
" tools=[duckduckgo_search],\n",
")\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/Validating agent output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -259,7 +259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
22 changes: 14 additions & 8 deletions examples/delegation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
motleycrew_location = os.path.realpath(WORKING_DIR / "..")
sys.path.append(motleycrew_location)

if "Dropbox" in WORKING_DIR.parts and platform.system() == "Windows":
# On Windows, kuzu has file locking issues with Dropbox
DB_PATH = os.path.realpath(os.path.expanduser("~") + "/Documents/research_db")
if __name__ == '__main__':
if "Dropbox" in WORKING_DIR.parts and platform.system() == "Windows":
# On Windows, kuzu has file locking issues with Dropbox
DB_PATH = os.path.realpath(os.path.expanduser("~") + "/Documents/research_db")
else:
DB_PATH = os.path.realpath(WORKING_DIR / "research_db")

else:
DB_PATH = os.path.realpath(WORKING_DIR / "research_db")
DB_PATH = os.path.realpath(WORKING_DIR / "tests/research_db")


def main():
Expand All @@ -43,25 +47,27 @@ def main():
researcher = CrewAIMotleyAgent(
role="Senior Research Analyst",
goal="Uncover cutting-edge developments in AI and data science, doing web search if necessary",

backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
verbose=True,
tools=[search_tool],
)

# You can give agents as tools to other agents
writer = ReActMotleyAgent(
name="AI writer agent",
description="You are an experienced writer with a passion for technology.",
prompt_prefix="You are an experienced writer with a passion for technology.",
description="Experienced writer with a passion for technology.",
tools=[researcher],
verbose=True,
)

# Illustrator
illustrator = ReActLlamaIndexMotleyAgent(
name="Illustrator",
description="Create beautiful and insightful illustrations for a blog post",
prompt_prefix="Create beautiful and insightful illustrations for a blog post",
tools=[DallEImageGeneratorTool(os.path.realpath("./images"))],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/llama_index_output_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def check_output(output: str):

# TODO: add LlamaIndex native tools
researcher = ReActLlamaIndexMotleyAgent(
description="Your goal is to uncover cutting-edge developments in AI and data science",
prompt_prefix="Your goal is to uncover cutting-edge developments in AI and data science",
tools=[search_tool],
output_handler=output_handler,
verbose=True,
Expand Down
4 changes: 2 additions & 2 deletions examples/old/delegation_crewai.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def main():
backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
description="Tool Research Analysis",
delegation=False,
verbose=True,
tools=[search_tool],
Expand Down Expand Up @@ -77,7 +78,7 @@ def main():
agent=writer,
)

[analysis_report_task, literature_summary_task] >> blog_post_task
# [analysis_report_task, literature_summary_task] >> blog_post_task

# Get your crew to work!
result = crew.run()
Expand All @@ -89,6 +90,5 @@ def main():

if __name__ == "__main__":
configure_logging(verbose=True)

load_dotenv()
main()
2 changes: 1 addition & 1 deletion examples/old/single_llama_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main():

# TODO: add LlamaIndex native tools
researcher = ReActLlamaIndexMotleyAgent(
description="Your goal is to uncover cutting-edge developments in AI and data science",
prompt_prefix="Your goal is to uncover cutting-edge developments in AI and data science",
tools=[search_tool],
verbose=True,
)
Expand Down
9 changes: 8 additions & 1 deletion motleycrew/agents/crewai/crewai.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class CrewAIMotleyAgentParent(MotleyAgentParent):
def __init__(
self,
goal: str,
prompt_prefix: str | None = None,
description: str | None = None,
name: str | None = None,
agent_factory: MotleyAgentFactory[CrewAIAgentWithConfig] | None = None,
tools: Sequence[MotleySupportedTool] | None = None,
Expand All @@ -32,6 +34,8 @@ def __init__(

Args:
goal (str):
prompt_prefix (:obj:`str`, optional):
description (:obj:`str`, optional):
name (:obj:`str`, optional):
agent_factory (:obj:`MotleyAgentFactory`, optional):
tools (:obj:`Sequence[MotleySupportedTool]`, optional:
Expand All @@ -46,7 +50,8 @@ def __init__(

ensure_module_is_installed("crewai")
super().__init__(
description=goal,
prompt_prefix=prompt_prefix,
description=description or goal,
name=name,
agent_factory=agent_factory,
tools=tools,
Expand Down Expand Up @@ -132,6 +137,8 @@ def from_agent(

wrapped_agent = CrewAIMotleyAgentParent(
goal=agent.goal,
prompt_prefix=agent.prompt_prefix,
description=agent.description,
name=agent.role,
tools=tools,
verbose=verbose,
Expand Down
25 changes: 15 additions & 10 deletions motleycrew/agents/crewai/crewai_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@
from motleycrew.common import MotleySupportedTool
from motleycrew.common import LLMFramework
from motleycrew.common.llms import init_llm
from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
from motleycrew.agents.crewai import CrewAIMotleyAgentParent
from motleycrew.agents.crewai import CrewAIAgentWithConfig


class CrewAIMotleyAgent(CrewAIMotleyAgentParent):
def __init__(
self,
role: str,
goal: str,
backstory: str,
delegation: bool = False,
tools: Sequence[MotleySupportedTool] | None = None,
llm: Optional[Any] = None,
output_handler: MotleySupportedTool | None = None,
verbose: bool = False,
self,
role: str,
goal: str,
backstory: str,
prompt_prefix: str | None = None,
description: str | None = None,
delegation: bool = False,
tools: Sequence[MotleySupportedTool] | None = None,
llm: Optional[Any] = None,
output_handler: MotleySupportedTool | None = None,
verbose: bool = False,
):
""" Description

Args:
role (str):
goal (str):
backstory (str):
prompt_prefix (str):
description (str, optional):
delegation (bool):
tools (:obj:`Sequence[MotleySupportedTool]`, optional):
llm (:obj:'Any', optional):
Expand Down Expand Up @@ -60,6 +63,8 @@ def agent_factory(tools: dict[str, MotleyTool]):

super().__init__(
goal=goal,
prompt_prefix=prompt_prefix,
description=description,
name=role,
agent_factory=agent_factory,
tools=tools,
Expand Down
9 changes: 8 additions & 1 deletion motleycrew/agents/langchain/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class LangchainMotleyAgent(MotleyAgentParent, LangchainOutputHandlingAgentMixin):
def __init__(
self,
prompt_prefix: str | None = None,
description: str | None = None,
name: str | None = None,
agent_factory: MotleyAgentFactory[AgentExecutor] | None = None,
Expand All @@ -28,6 +29,7 @@ def __init__(
"""Description

Args:
prompt_prefix (:obj:`str`, optional):
description (:obj:`str`, optional):
name (:obj:`str`, optional):
agent_factory (:obj:`MotleyAgentFactory`, optional):
Expand All @@ -40,6 +42,7 @@ def __init__(
See Langchain `RunnableWithMessageHistory` get_session_history param for more details.
"""
super().__init__(
prompt_prefix=prompt_prefix,
description=description,
name=name,
agent_factory=agent_factory,
Expand Down Expand Up @@ -139,6 +142,7 @@ def invoke(
def from_agent(
agent: AgentExecutor,
goal: str,
description: str | None = None,
tools: Sequence[MotleySupportedTool] | None = None,
verbose: bool = False,
) -> "LangchainMotleyAgent":
Expand All @@ -147,6 +151,7 @@ def from_agent(
Args:
agent (AgentExecutor):
goal (str):
description (:obj:`str`, optional)
tools(:obj:`Sequence[MotleySupportedTool]`, optional):
verbose (bool):

Expand All @@ -160,6 +165,8 @@ def from_agent(
if tools or agent.tools:
tools = list(tools or []) + list(agent.tools or [])

wrapped_agent = LangchainMotleyAgent(description=goal, tools=tools, verbose=verbose)
wrapped_agent = LangchainMotleyAgent(
prompt_prefix=goal, description=description, tools=tools, verbose=verbose
)
wrapped_agent._agent = agent
return wrapped_agent
3 changes: 3 additions & 0 deletions motleycrew/agents/langchain/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ReActMotleyAgent(LangchainMotleyAgent):
def __init__(
self,
tools: Sequence[MotleySupportedTool],
prompt_prefix: str | None = None,
description: str | None = None,
name: str | None = None,
prompt: str | None = None,
Expand All @@ -41,6 +42,7 @@ def __init__(

Args:
tools (Sequence[MotleySupportedTool]):
prompt_prefix (:obj:`str`, optional):
description (:obj:`str`, optional):
name (:obj:`str`, optional):
prompt (:obj:`str`, optional): Prompt to use. If not provided, uses hwchase17/react.
Expand Down Expand Up @@ -88,6 +90,7 @@ def agent_factory(
return agent_executor

super().__init__(
prompt_prefix=prompt_prefix,
description=description,
name=name,
agent_factory=agent_factory,
Expand Down
2 changes: 2 additions & 0 deletions motleycrew/agents/langchain/tool_calling_react.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class ReActToolCallingAgent(LangchainMotleyAgent):
def __init__(
self,
tools: Sequence[MotleySupportedTool],
prompt_prefix: str | None = None,
description: str | None = None,
name: str | None = None,
think_prompt: ChatPromptTemplate | None = None,
Expand Down Expand Up @@ -319,6 +320,7 @@ def agent_factory(
return agent_executor

super().__init__(
prompt_prefix=prompt_prefix,
description=description,
name=name,
agent_factory=agent_factory,
Expand Down
10 changes: 9 additions & 1 deletion motleycrew/agents/llama_index/llama_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LlamaIndexMotleyAgent(MotleyAgentParent):

def __init__(
self,
prompt_prefix: str | None = None,
description: str | None = None,
name: str | None = None,
agent_factory: MotleyAgentFactory[AgentRunner] | None = None,
Expand All @@ -37,6 +38,7 @@ def __init__(
"""Description

Args:
prompt_prefix (:obj:`str`, optional):
description (:obj:`str`, optional):
name (:obj:`str`, optional):
agent_factory (:obj:`MotleyAgentFactory`, optional):
Expand All @@ -45,6 +47,7 @@ def __init__(
"""
super().__init__(
description=description,
prompt_prefix=prompt_prefix,
name=name,
agent_factory=agent_factory,
tools=tools,
Expand All @@ -55,6 +58,7 @@ def __init__(
def run_step_decorator(self):
"""Decorator for inclusion in the call chain of the agent, the output handler tool"""
ensure_module_is_installed("llama_index")

def decorator(func):
def wrapper(
task_id: str,
Expand Down Expand Up @@ -133,6 +137,7 @@ def invoke(
def from_agent(
agent: AgentRunner,
description: Optional[str] = None,
prompt_prefix: Optional[str] = None,
tools: Sequence[MotleySupportedTool] | None = None,
verbose: bool = False,
) -> "LlamaIndexMotleyAgent":
Expand All @@ -141,13 +146,16 @@ def from_agent(
Args:
agent (AgentRunner):
description (:obj:`str`, optional):
prompt_prefix (:obj:`str`, optional):
tools (:obj:`Sequence[MotleySupportedTool]`, optional):
verbose (:obj:`bool`, optional):

Returns:
LlamaIndexMotleyAgent:
"""
ensure_module_is_installed("llama_index")
wrapped_agent = LlamaIndexMotleyAgent(description=description, tools=tools, verbose=verbose)
wrapped_agent = LlamaIndexMotleyAgent(
description=description, prompt_prefix=prompt_prefix, tools=tools, verbose=verbose
)
wrapped_agent._agent = agent
return wrapped_agent
Loading
Loading