From 4b0c5a973da5a5f7b99580472faf13eb763ecf11 Mon Sep 17 00:00:00 2001 From: User Date: Mon, 8 Jul 2024 11:38:23 +0300 Subject: [PATCH 1/6] replace CrewAIMotleyAgent to ReactMotleyAgent in math_crewai --- examples/old/math_crewai.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/old/math_crewai.py b/examples/old/math_crewai.py index 51b093b8..5576d01c 100644 --- a/examples/old/math_crewai.py +++ b/examples/old/math_crewai.py @@ -1,7 +1,7 @@ from dotenv import load_dotenv from motleycrew import MotleyCrew -from motleycrew.agents.crewai import CrewAIMotleyAgent +from motleycrew.agents.langchain import ReActMotleyAgent from motleycrew.tools import PythonREPLTool from motleycrew.common import configure_logging @@ -11,15 +11,14 @@ def main(): repl_tool = PythonREPLTool() # Define your agents with roles and goals - solver1 = CrewAIMotleyAgent( - role="High School Math Teacher", - goal="Generate great solutions to math problems", - backstory="""You are a high school math teacher with a passion for problem-solving. - To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly, - using sympy, then use the REPL tool to evaluate that code, and then - use the output to generate a human-readable solution.""", + solver1 = ReActMotleyAgent( + name="High School Math Teacher", + prompt_prefix="""You are a high school math teacher with a passion for problem-solving. + To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly, + using sympy, then use the REPL tool to evaluate that code, and then + use the output to generate a human-readable solution.""", verbose=True, - delegation=False, + description="Generate great solutions to math problems", tools=[repl_tool], ) From ca533485ed50797e0dd7d7f397aa6249f9100a5e Mon Sep 17 00:00:00 2001 From: User Date: Mon, 8 Jul 2024 11:44:02 +0300 Subject: [PATCH 2/6] replace CrewAIMotleyAgent to ReactMotleyAgent in aider_code_generation --- examples/aider_code_generation.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/aider_code_generation.py b/examples/aider_code_generation.py index 90c6e773..e3864ef0 100644 --- a/examples/aider_code_generation.py +++ b/examples/aider_code_generation.py @@ -7,7 +7,7 @@ from langchain_community.tools import ShellTool -from motleycrew.agents.crewai import CrewAIMotleyAgent +from motleycrew.agents.langchain import ReActMotleyAgent from motleycrew.common import configure_logging from motleycrew.tasks import SimpleTask from motleycache import logger @@ -41,11 +41,10 @@ def main(): aider_tool = AiderTool(fnames=target_files, git_dname=git_repo_path, auto_commits=False) shell_tool = ShellTool() - developer = CrewAIMotleyAgent( - role="Software Engineer", - goal="Writing unit tests", - backstory="You are a lead software engineer working in a big tech company.", - delegation=False, + developer = ReActMotleyAgent( + name="Software Engineer", + description="Writing unit tests", + prompt_prefix="You are a lead tester working in a big tech company, your main goal is to write and run tests", verbose=True, tools=[aider_tool, shell_tool], ) From 45519ccd0b826f9601b4a00a04eb0b83a1a3e21a Mon Sep 17 00:00:00 2001 From: User Date: Mon, 8 Jul 2024 13:05:27 +0300 Subject: [PATCH 3/6] replace CrewAIMotleyAgent to ReActLlamaIndexMotleyAgent in Math via python code with as single agent.ipynb --- ... via python code with a single agent.ipynb | 565 +++--------------- 1 file changed, 88 insertions(+), 477 deletions(-) diff --git a/examples/Math via python code with a single agent.ipynb b/examples/Math via python code with a single agent.ipynb index 69d7e0d2..b446bc61 100644 --- a/examples/Math via python code with a single agent.ipynb +++ b/examples/Math via python code with a single agent.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 20, "id": "51527a55-d470-4509-9930-01466e3f78f3", "metadata": {}, "outputs": [ @@ -28,7 +28,7 @@ "True" ] }, - "execution_count": 1, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -49,7 +49,7 @@ " sys.path.append(motleycrew_location)\n", "\n", "from motleycrew import MotleyCrew\n", - "from motleycrew.agents.crewai import CrewAIMotleyAgent\n", + "from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent\n", "from motleycrew.tools import PythonREPLTool\n", "from motleycrew.common import configure_logging\n", "from motleycrew.tasks import SimpleTask\n", @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 21, "id": "9f527af7-a6ad-4259-88a2-43c8dacdb8ea", "metadata": {}, "outputs": [ @@ -68,414 +68,94 @@ "name": "stderr", "output_type": "stream", "text": [ - "2024-05-24 11:28:55,150 - INFO - No db_path provided, creating temporary directory for database\n", - "2024-05-24 11:28:55,150 - INFO - Using Kuzu graph store with path: C:\\Users\\Egor\\AppData\\Local\\Temp\\tmpu9yewyeu\\kuzu_db\n", - "2024-05-24 11:28:55,168 - INFO - Node table MotleyGraphNode does not exist in the database, creating\n", - "2024-05-24 11:28:55,180 - INFO - Relation table dummy from MotleyGraphNode to MotleyGraphNode does not exist in the database, creating\n", - "2024-05-24 11:28:55,192 - INFO - Node table TaskNode does not exist in the database, creating\n", - "2024-05-24 11:28:55,203 - INFO - Property name not present in table for label TaskNode, creating\n", - "2024-05-24 11:28:55,215 - INFO - Property done not present in table for label TaskNode, creating\n", - "2024-05-24 11:28:55,227 - INFO - Inserting new node with label TaskNode: name='solve math problem' done=False\n", - "2024-05-24 11:28:55,243 - INFO - Node created OK\n", - "2024-05-24 11:28:55,245 - INFO - Relation table task_is_upstream from TaskNode to TaskNode does not exist in the database, creating\n", - "2024-05-24 11:28:55,255 - WARNING - Multithreading is not implemented yet, will run in single thread\n", - "2024-05-24 11:28:55,277 - INFO - Available tasks: [SimpleTask(name=solve math problem, done=False)]\n", - "2024-05-24 11:28:55,277 - INFO - Processing task: SimpleTask(name=solve math problem, done=False)\n", - "2024-05-24 11:28:55,291 - INFO - Got a matching unit for task SimpleTask(name=solve math problem, done=False)\n", - "2024-05-24 11:28:55,292 - INFO - Processing task: TaskUnit(status=pending)\n", - "2024-05-24 11:28:55,293 - INFO - Assigned unit TaskUnit(status=pending) to agent Agent(name=High School Math Teacher), dispatching\n", - "2024-05-24 11:28:55,293 - INFO - Node TaskUnit(status=running) does not exist, creating\n", - "2024-05-24 11:28:55,294 - INFO - Node table SimpleTaskUnit does not exist in the database, creating\n", - "2024-05-24 11:28:55,305 - INFO - Property status not present in table for label SimpleTaskUnit, creating\n", - "2024-05-24 11:28:55,318 - INFO - Property output not present in table for label SimpleTaskUnit, creating\n", - "2024-05-24 11:28:55,318 - WARNING - No known Cypher type matching annotation typing.Optional[typing.Any], will use JSON string\n", - "2024-05-24 11:28:55,331 - INFO - Property name not present in table for label SimpleTaskUnit, creating\n", - "2024-05-24 11:28:55,344 - INFO - Property prompt not present in table for label SimpleTaskUnit, creating\n", - "2024-05-24 11:28:55,358 - INFO - Property message_history not present in table for label SimpleTaskUnit, creating\n", - "2024-05-24 11:28:55,359 - WARNING - No known Cypher type matching annotation typing.List[str], will use JSON string\n", - "2024-05-24 11:28:55,375 - INFO - Inserting new node with label SimpleTaskUnit: TaskUnit(status=running)\n", - "2024-05-24 11:28:55,376 - WARNING - No known Cypher type matching annotation typing.List[str], will use JSON string\n", - "2024-05-24 11:28:55,394 - INFO - Node created OK\n", - "2024-05-24 11:28:55,398 - INFO - Relation from TaskUnit(status=running) to name='solve math problem' done=False does not exist, creating\n", - "2024-05-24 11:28:55,401 - INFO - Relation table task_unit_belongs from SimpleTaskUnit to TaskNode does not exist in the database, creating\n", - "2024-05-24 11:28:55,411 - INFO - Creating relation task_unit_belongs from SimpleTaskUnit:0 to TaskNode:0\n", - "2024-05-24 11:28:55,429 - INFO - Relation created OK\n", - "2024-05-24 11:28:55,432 - WARNING - Lunary public key is not set, tracking will be disabled\n" + "2024-07-08 13:02:43,218 - motleycrew - INFO - No db_path provided, creating temporary directory for database\n", + "2024-07-08 13:02:43,219 - motleycrew - INFO - Using Kuzu graph store with path: C:\\Users\\User\\AppData\\Local\\Temp\\tmp926r1y8q\\kuzu_db\n", + "2024-07-08 13:02:43,249 - motleycrew - INFO - Node table MotleyGraphNode does not exist in the database, creating\n", + "2024-07-08 13:02:43,259 - motleycrew - INFO - Relation table dummy from MotleyGraphNode to MotleyGraphNode does not exist in the database, creating\n", + "2024-07-08 13:02:43,267 - motleycrew - INFO - Node table TaskNode does not exist in the database, creating\n", + "2024-07-08 13:02:43,276 - motleycrew - INFO - Property name not present in table for label TaskNode, creating\n", + "2024-07-08 13:02:43,284 - motleycrew - INFO - Property done not present in table for label TaskNode, creating\n", + "2024-07-08 13:02:43,292 - motleycrew - INFO - Node table SimpleTaskUnit does not exist in the database, creating\n", + "2024-07-08 13:02:43,300 - motleycrew - INFO - Property status not present in table for label SimpleTaskUnit, creating\n", + "2024-07-08 13:02:43,310 - motleycrew - INFO - Property output not present in table for label SimpleTaskUnit, creating\n", + "2024-07-08 13:02:43,311 - motleycrew - WARNING - No known Cypher type matching annotation typing.Optional[typing.Any], will use JSON string\n", + "2024-07-08 13:02:43,319 - motleycrew - INFO - Property name not present in table for label SimpleTaskUnit, creating\n", + "2024-07-08 13:02:43,329 - motleycrew - INFO - Property prompt not present in table for label SimpleTaskUnit, creating\n", + "2024-07-08 13:02:43,337 - motleycrew - INFO - Property message_history not present in table for label SimpleTaskUnit, creating\n", + "2024-07-08 13:02:43,338 - motleycrew - WARNING - No known Cypher type matching annotation typing.List[str], will use JSON string\n", + "2024-07-08 13:02:43,347 - motleycrew - INFO - Relation table SimpleTaskUnit_belongs from SimpleTaskUnit to TaskNode does not exist in the database, creating\n", + "2024-07-08 13:02:43,357 - motleycrew - INFO - Inserting new node with label TaskNode: name='solve math problem' done=False\n", + "2024-07-08 13:02:43,366 - motleycrew - INFO - Node created OK\n", + "2024-07-08 13:02:43,368 - motleycrew - INFO - Relation table task_is_upstream from TaskNode to TaskNode does not exist in the database, creating\n", + "2024-07-08 13:02:43,395 - motleycrew - INFO - Available tasks: [SimpleTask(name=solve math problem, done=False)]\n", + "2024-07-08 13:02:43,414 - motleycrew - INFO - Available tasks: [SimpleTask(name=solve math problem, done=False)]\n", + "2024-07-08 13:02:43,415 - motleycrew - INFO - Processing task: SimpleTask(name=solve math problem, done=False)\n", + "2024-07-08 13:02:43,444 - motleycrew - INFO - Got a matching unit for task SimpleTask(name=solve math problem, done=False)\n", + "2024-07-08 13:02:43,445 - motleycrew - INFO - Processing unit: TaskUnit(status=pending)\n", + "2024-07-08 13:02:43,445 - motleycrew - INFO - Assigned unit TaskUnit(status=pending) to agent ReActLlamaIndexMotleyAgent(name=High School Math Teacher), dispatching\n", + "2024-07-08 13:02:43,445 - motleycrew - INFO - Node TaskUnit(status=running) does not exist, creating\n", + "2024-07-08 13:02:43,447 - motleycrew - INFO - Inserting new node with label SimpleTaskUnit: TaskUnit(status=running)\n", + "2024-07-08 13:02:43,447 - motleycrew - WARNING - No known Cypher type matching annotation typing.List[str], will use JSON string\n", + "2024-07-08 13:02:43,458 - motleycrew - INFO - Node created OK\n", + "2024-07-08 13:02:43,486 - motleycrew - INFO - Relation from TaskUnit(status=running) to name='solve math problem' done=False does not exist, creating\n", + "2024-07-08 13:02:43,490 - motleycrew - INFO - Creating relation SimpleTaskUnit_belongs from SimpleTaskUnit:0 to TaskNode:0\n", + "2024-07-08 13:02:43,498 - motleycrew - INFO - Relation created OK\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ + "\u001b[1;3;38;5;200mThought: The current language of the user is: English. I need to use a tool to help me answer the question.\n", + "Action: python_repl\n", + "Action Input: {'command': \"from sympy import symbols, Eq, solve\\nx, y = symbols('x y')\\nequation1 = Eq(725*x + 727*y, 1500)\\nequation2 = Eq(729*x + 731*y, 1508)\\nsolution = solve((equation1, equation2), (x, y))\\nx_value = solution[x]\\ny_value = solution[y]\\nx_minus_y = x_value - y_value\\nsolution, x_minus_y\"}\n", + "\u001b[0m\u001b[1;3;34mObservation: \n", + "\u001b[0m\u001b[1;3;38;5;200mThought: I need to re-run the code to get the solution and the value of \\( x - y \\).\n", + "Action: python_repl\n", + "Action Input: {'command': \"from sympy import symbols, Eq, solve\\nx, y = symbols('x y')\\nequation1 = Eq(725*x + 727*y, 1500)\\nequation2 = Eq(729*x + 731*y, 1508)\\nsolution = solve((equation1, equation2), (x, y))\\nx_value = solution[x]\\ny_value = solution[y]\\nx_minus_y = x_value - y_value\\nprint(solution, x_minus_y)\"}\n", + "\u001b[0m\u001b[1;3;34mObservation: {x: -23, y: 25} -48\n", "\n", - "\n", - "\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:28:56,705 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3mTo solve the system of equations given by:\n", - "1. \\( 725x + 727y = 1500 \\)\n", - "2. \\( 729x + 731y = 1508 \\)\n", - "\n", - "We will use the method of elimination to find the values of \\( x \\) and \\( y \\). First, we will eliminate \\( y \\) by subtracting the first equation from the second. This will give us an equation in terms of \\( x \\) only.\n", - "\n", - "Let's calculate the coefficients and constants after subtraction:\n", - "- Coefficient of \\( x \\): \\( 729 - 725 \\)\n", - "- Coefficient of \\( y \\): \\( 731 - 727 \\)\n", - "- Constant term: \\( 1508 - 1500 \\)\n", - "\n", - "```\n", - "Use Tool: python_repl(command=\"print(729 - 725, 731 - 727, 1508 - 1500)\")\n", - "```\u001b[0m" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:06,112 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", - "2024-05-24 11:29:06,115 - WARNING - Python REPL can execute arbitrary code. Use with caution.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[93m \n", - "\n", - "4 4 8\n", - "\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:06,962 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3mFrom the result of the subtraction, we have the simplified equation:\n", - "\\[ 4x + 4y = 8 \\]\n", - "\n", - "To simplify further, we divide the entire equation by 4:\n", - "\\[ x + y = 2 \\]\n", - "\n", - "Now, we have a new system of equations:\n", - "1. \\( x + y = 2 \\)\n", - "2. \\( 725x + 727y = 1500 \\)\n", - "\n", - "We can solve this system using substitution or elimination. Let's use substitution. We express \\( y \\) in terms of \\( x \\) from the first equation:\n", - "\\[ y = 2 - x \\]\n", - "\n", - "Substitute \\( y = 2 - x \\) into the second equation:\n", - "\\[ 725x + 727(2 - x) = 1500 \\]\n", - "\n", - "Expanding and simplifying this equation will give us the value of \\( x \\). Let's calculate it:\n", - "\n", - "```\n", - "Use Tool: python_repl(command=\"from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq)\")\n", - "```\u001b[0m" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:17,493 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[93m \n", - "\n", - "\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:19,615 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3m```\n", - "Use Tool: python_repl(command=\"from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq)\")\n", - "```\u001b[0m" + "\u001b[0m" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "2024-05-24 11:29:24,848 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" + "2024-07-08 13:02:55,572 - motleycrew - WARNING - No known Cypher type matching annotation typing.Optional[typing.Any], will use JSON string\n", + "2024-07-08 13:02:55,579 - motleycrew - INFO - Task unit TaskUnit(status=running) completed, marking as done\n", + "2024-07-08 13:02:55,607 - motleycrew - INFO - Available tasks: []\n", + "2024-07-08 13:02:55,624 - motleycrew - INFO - Available tasks: []\n", + "2024-07-08 13:02:55,626 - motleycrew - INFO - Nothing left to do, exiting\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[93m \n", - "\n", - "I already used the python_repl tool with input from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq). So I already know that and must stop using it with same input. \n", - "I could give my best complete final answer if I'm ready, using exaclty the expected format bellow:\n", + "\u001b[1;3;38;5;200mThought: I can answer without using any more tools. I'll use the user's language to answer\n", + "Answer: To solve the system of equations:\n", + "\\[ 725x + 727y = 1500 \\]\n", + "\\[ 729x + 731y = 1508 \\]\n", "\n", - "```\n", - "Final Answer: [my expected final answer, entire content of my most complete final answer goes here]\n", - "```\n", - "I MUST use these formats, my jobs depends on it!\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:25,688 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3m```\n", - "Use Tool: python_repl(command=\"from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq)\")\n", - "```\u001b[0m" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:32,854 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[93m \n", - "\n", - "I already used the python_repl tool with input from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq). So I already know that and must stop using it with same input. \n", - "I could give my best complete final answer if I'm ready, using exaclty the expected format bellow:\n", - "\n", - "```\n", - "Final Answer: [my expected final answer, entire content of my most complete final answer goes here]\n", - "```\n", - "I MUST use these formats, my jobs depends on it!\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:33,853 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3m```\n", - "Use Tool: python_repl(command=\"from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq)\")\n", - "```\u001b[0m" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:38,556 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[93m \n", - "\n", - "I already used the python_repl tool with input from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq). So I already know that and must stop using it with same input. \n", - "I could give my best complete final answer if I'm ready, using exaclty the expected format bellow:\n", - "\n", - "```\n", - "Final Answer: [my expected final answer, entire content of my most complete final answer goes here]\n", - "```\n", - "I MUST use these formats, my jobs depends on it!\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:39,509 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3m```\n", - "Use Tool: python_repl(command=\"from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq)\")\n", - "```\u001b[0m" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:42,264 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[91m \n", - "\n", - "It seems we encountered an unexpected error while trying to use the tool. This was the error: PythonREPL.run() missing 1 required positional argument: 'command'\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:43,180 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3m```\n", - "Use Tool: python_repl(command=\"from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq)\")\n", - "```\u001b[0m" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:48,477 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[93m \n", - "\n", - "I already used the python_repl tool with input from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq). So I already know that and must stop using it with same input. \n", - "I could give my best complete final answer if I'm ready, using exaclty the expected format bellow:\n", - "\n", - "```\n", - "Final Answer: [my expected final answer, entire content of my most complete final answer goes here]\n", - "```\n", - "I MUST use these formats, my jobs depends on it!\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:49,566 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3m```\n", - "Use Tool: python_repl(command=\"from sympy import symbols, Eq, solve; x = symbols('x'); eq = Eq(725*x + 727*(2 - x), 1500); solve(eq)\")\n", - "```\u001b[0m" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:54,281 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[93m \n", - "\n", - "[-23]\n", - "\n", - "\u001b[00m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-05-24 11:29:55,181 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", - "2024-05-24 11:30:04,021 - WARNING - No known Cypher type matching annotation typing.Optional[typing.Any], will use JSON string\n", - "2024-05-24 11:30:04,039 - INFO - Task unit TaskUnit(status=running) completed, marking as done\n", - "2024-05-24 11:30:04,077 - INFO - Available tasks: []\n", - "2024-05-24 11:30:04,077 - INFO - Nothing left to do, exiting\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32;1m\u001b[1;3mFinal Answer: To solve the system of equations given by:\n", - "1. \\( 725x + 727y = 1500 \\)\n", - "2. \\( 729x + 731y = 1508 \\)\n", - "\n", - "We first subtract the first equation from the second to eliminate \\( y \\), resulting in:\n", - "\\[ 4x + 4y = 8 \\]\n", - "which simplifies to:\n", - "\\[ x + y = 2 \\]\n", - "\n", - "Using this in conjunction with the first equation, we substitute \\( y = 2 - x \\) into \\( 725x + 727y = 1500 \\) to get:\n", - "\\[ 725x + 727(2 - x) = 1500 \\]\n", - "Solving this equation gives \\( x = -23 \\).\n", - "\n", - "Substituting \\( x = -23 \\) back into \\( x + y = 2 \\), we find:\n", - "\\[ -23 + y = 2 \\]\n", + "we first solve for \\( x \\) and \\( y \\). Using the sympy library, we find:\n", + "\\[ x = -23 \\]\n", "\\[ y = 25 \\]\n", "\n", - "Thus, the values are:\n", - "\\[ x = -23, \\quad y = 25, \\quad x - y = -23 - 25 = -48 \\]\n", - "\n", - "Therefore, \\( x = -23 \\), \\( y = 25 \\), and \\( x - y = -48 \\).\u001b[0m\n", + "Next, we calculate \\( x - y \\):\n", + "\\[ x - y = -23 - 25 = -48 \\]\n", "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" + "Thus, the values are:\n", + "\\[ x = -23 \\]\n", + "\\[ y = 25 \\]\n", + "\\[ x - y = -48 \\]\n", + "\u001b[0m" ] }, { "data": { "text/plain": [ - "'To solve the system of equations given by:\\n1. \\\\( 725x + 727y = 1500 \\\\)\\n2. \\\\( 729x + 731y = 1508 \\\\)\\n\\nWe first subtract the first equation from the second to eliminate \\\\( y \\\\), resulting in:\\n\\\\[ 4x + 4y = 8 \\\\]\\nwhich simplifies to:\\n\\\\[ x + y = 2 \\\\]\\n\\nUsing this in conjunction with the first equation, we substitute \\\\( y = 2 - x \\\\) into \\\\( 725x + 727y = 1500 \\\\) to get:\\n\\\\[ 725x + 727(2 - x) = 1500 \\\\]\\nSolving this equation gives \\\\( x = -23 \\\\).\\n\\nSubstituting \\\\( x = -23 \\\\) back into \\\\( x + y = 2 \\\\), we find:\\n\\\\[ -23 + y = 2 \\\\]\\n\\\\[ y = 25 \\\\]\\n\\nThus, the values are:\\n\\\\[ x = -23, \\\\quad y = 25, \\\\quad x - y = -23 - 25 = -48 \\\\]\\n\\nTherefore, \\\\( x = -23 \\\\), \\\\( y = 25 \\\\), and \\\\( x - y = -48 \\\\).'" + "'To solve the system of equations:\\n\\\\[ 725x + 727y = 1500 \\\\]\\n\\\\[ 729x + 731y = 1508 \\\\]\\n\\nwe first solve for \\\\( x \\\\) and \\\\( y \\\\). Using the sympy library, we find:\\n\\\\[ x = -23 \\\\]\\n\\\\[ y = 25 \\\\]\\n\\nNext, we calculate \\\\( x - y \\\\):\\n\\\\[ x - y = -23 - 25 = -48 \\\\]\\n\\nThus, the values are:\\n\\\\[ x = -23 \\\\]\\n\\\\[ y = 25 \\\\]\\n\\\\[ x - y = -48 \\\\]'" ] }, "metadata": {}, @@ -487,18 +167,17 @@ "repl_tool = PythonREPLTool()\n", "\n", "# Define your agents with roles and goals\n", - "solver = CrewAIMotleyAgent(\n", - " role=\"High School Math Teacher\",\n", - " goal=\"Generate great solutions to math problems\",\n", - " backstory=\"\"\"You are a high school math teacher with a passion for problem-solving.\n", + "solver = ReActLlamaIndexMotleyAgent(\n", + " name=\"High School Math Teacher\",\n", + " prompt_prefix=\"\"\"You are a high school math teacher with a passion for problem-solving.\n", "To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly,\n", - "using sympy, then use the REPL tool to evaluate that code, and then\n", + "using sympy library, then use the REPL tool to evaluate that code, and then\n", "use the output to generate a human-readable solution in LaTeX format. \n", "Don't use dashes to indicate bullet points, don't output any backticks, just the LaTeX\"\"\",\n", - " verbose=True,\n", - " delegation=False,\n", - " tools=[repl_tool],\n", - ")\n", + " verbose=True,\n", + " description=\"Generate great solutions to math problems\",\n", + " tools=[repl_tool],\n", + " )\n", "\n", "problems = [\n", " \"Problem: If $725x + 727y = 1500$ and $729x+ 731y = 1508$, \"\n", @@ -522,14 +201,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 22, "id": "2cc1f331-bb24-488d-9387-890c015d8fb2", "metadata": {}, "outputs": [ { "data": { "text/latex": [ - "To solve the system of equations given by:" + "To solve the system of equations:" ], "text/plain": [ "" @@ -541,7 +220,7 @@ { "data": { "text/latex": [ - "1. \\( 725x + 727y = 1500 \\)" + "\\[ 725x + 727y = 1500 \\]" ], "text/plain": [ "" @@ -553,7 +232,7 @@ { "data": { "text/latex": [ - "2. \\( 729x + 731y = 1508 \\)" + "\\[ 729x + 731y = 1508 \\]" ], "text/plain": [ "" @@ -575,19 +254,7 @@ { "data": { "text/latex": [ - "We first subtract the first equation from the second to eliminate \\( y \\), resulting in:" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "\\[ 4x + 4y = 8 \\]" + "we first solve for \\( x \\) and \\( y \\). Using the sympy library, we find:" ], "text/plain": [ "" @@ -599,7 +266,7 @@ { "data": { "text/latex": [ - "which simplifies to:" + "\\[ x = -23 \\]" ], "text/plain": [ "" @@ -611,7 +278,7 @@ { "data": { "text/latex": [ - "\\[ x + y = 2 \\]" + "\\[ y = 25 \\]" ], "text/plain": [ "" @@ -633,19 +300,7 @@ { "data": { "text/latex": [ - "Using this in conjunction with the first equation, we substitute \\( y = 2 - x \\) into \\( 725x + 727y = 1500 \\) to get:" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "\\[ 725x + 727(2 - x) = 1500 \\]" + "Next, we calculate \\( x - y \\):" ], "text/plain": [ "" @@ -657,7 +312,7 @@ { "data": { "text/latex": [ - "Solving this equation gives \\( x = -23 \\)." + "\\[ x - y = -23 - 25 = -48 \\]" ], "text/plain": [ "" @@ -679,7 +334,7 @@ { "data": { "text/latex": [ - "Substituting \\( x = -23 \\) back into \\( x + y = 2 \\), we find:" + "Thus, the values are:" ], "text/plain": [ "" @@ -691,7 +346,7 @@ { "data": { "text/latex": [ - "\\[ -23 + y = 2 \\]" + "\\[ x = -23 \\]" ], "text/plain": [ "" @@ -712,54 +367,10 @@ "metadata": {}, "output_type": "display_data" }, - { - "data": { - "text/latex": [], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "Thus, the values are:" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "\\[ x = -23, \\quad y = 25, \\quad x - y = -23 - 25 = -48 \\]" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, { "data": { "text/latex": [ - "Therefore, \\( x = -23 \\), \\( y = 25 \\), and \\( x - y = -48 \\)." + "\\[ x - y = -48 \\]" ], "text/plain": [ "" @@ -777,7 +388,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "65199e11-e903-470a-942e-855a83ea263e", "metadata": {}, "outputs": [], @@ -788,9 +399,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", - "name": "python3" + "name": ".venv" }, "language_info": { "codemirror_mode": { @@ -802,7 +413,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.8" } }, "nbformat": 4, From 618c370695b1af334a86628322ee988d246b8abc Mon Sep 17 00:00:00 2001 From: User Date: Mon, 8 Jul 2024 13:07:11 +0300 Subject: [PATCH 4/6] replace ReActMotleyAgent to ReActLlamaIndexMotleyAgent in math_crewai --- examples/old/math_crewai.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/old/math_crewai.py b/examples/old/math_crewai.py index 5576d01c..2ae9e92f 100644 --- a/examples/old/math_crewai.py +++ b/examples/old/math_crewai.py @@ -1,7 +1,7 @@ from dotenv import load_dotenv from motleycrew import MotleyCrew -from motleycrew.agents.langchain import ReActMotleyAgent +from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent from motleycrew.tools import PythonREPLTool from motleycrew.common import configure_logging @@ -11,7 +11,7 @@ def main(): repl_tool = PythonREPLTool() # Define your agents with roles and goals - solver1 = ReActMotleyAgent( + solver1 = ReActLlamaIndexMotleyAgent( name="High School Math Teacher", prompt_prefix="""You are a high school math teacher with a passion for problem-solving. To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly, From e736b8741f61f1c71f181ff160f8be138ed6abf2 Mon Sep 17 00:00:00 2001 From: User Date: Mon, 8 Jul 2024 13:31:02 +0300 Subject: [PATCH 5/6] replace ReActLlamaIndexMotleyAgent to ReActMotleyAgent in math_crewai --- examples/old/math_crewai.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/old/math_crewai.py b/examples/old/math_crewai.py index 2ae9e92f..1120b666 100644 --- a/examples/old/math_crewai.py +++ b/examples/old/math_crewai.py @@ -1,7 +1,7 @@ from dotenv import load_dotenv from motleycrew import MotleyCrew -from motleycrew.agents.llama_index import ReActLlamaIndexMotleyAgent +from motleycrew.agents.langchain import ReActMotleyAgent from motleycrew.tools import PythonREPLTool from motleycrew.common import configure_logging @@ -11,14 +11,14 @@ def main(): repl_tool = PythonREPLTool() # Define your agents with roles and goals - solver1 = ReActLlamaIndexMotleyAgent( + solver1 = ReActMotleyAgent( name="High School Math Teacher", - prompt_prefix="""You are a high school math teacher with a passion for problem-solving. + prompt_prefix="Generate great solutions to math problems", + description="""You are a high school math teacher with a passion for problem-solving. To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly, using sympy, then use the REPL tool to evaluate that code, and then use the output to generate a human-readable solution.""", verbose=True, - description="Generate great solutions to math problems", tools=[repl_tool], ) From 10dcec4040672fccd5a4f96121b5413a2399e6a6 Mon Sep 17 00:00:00 2001 From: User Date: Mon, 8 Jul 2024 14:21:57 +0300 Subject: [PATCH 6/6] =?UTF-8?q?change=20metadata=20in=20math=5Fvia=5Fpytho?= =?UTF-8?q?n=5Fcode=5Fwith=5Fa=5Fsingle=5Fagent=5Fipynb=E2=80=A6=20integra?= =?UTF-8?q?tion=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/Math via python code with a single agent.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Math via python code with a single agent.ipynb b/examples/Math via python code with a single agent.ipynb index b446bc61..4e4bc11d 100644 --- a/examples/Math via python code with a single agent.ipynb +++ b/examples/Math via python code with a single agent.ipynb @@ -399,9 +399,9 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": ".venv" + "name": "python3" }, "language_info": { "codemirror_mode": {