diff --git a/attached_assets/Pasted--Math-Agent-System-Initialized-Available-operations-2025-04-20-11-08-41-WARNING-swarms-st-1745147456240.txt b/attached_assets/Pasted--Math-Agent-System-Initialized-Available-operations-2025-04-20-11-08-41-WARNING-swarms-st-1745147456240.txt new file mode 100644 index 00000000..100bdecb --- /dev/null +++ b/attached_assets/Pasted--Math-Agent-System-Initialized-Available-operations-2025-04-20-11-08-41-WARNING-swarms-st-1745147456240.txt @@ -0,0 +1,118 @@ + +Math Agent System Initialized + +Available operations: +2025-04-20 11:08:41 | WARNING | swarms.structs.agent:llm_handling:646 - Model name is not provided, using gpt-4o-mini. You can configure any model from litellm if desired. +Math Agent: add, multiply, divide + +Enter your query (or 'exit' to quit): add 2 and 3 +╭─────────────────────────────────────────────────────── Agent Name Math Agent [Max Loops: 1 ] ───────────────────────────────────────────────────────╮ +│ Math Agent: {"tool_name": "add", "a": 2, "b": 3} │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +/home/runner/workspace/swarms/structs/agent.py:1110: RuntimeWarning: coroutine 'batch_mcp_flow' was never awaited + out = self.mcp_execution_flow(response) +RuntimeWarning: Enable tracemalloc to get the object allocation traceback +╭─────────────────────────────────────────────── Agent Name Math Agent - Tool Executor [Max Loops: 1 ] ───────────────────────────────────────────────╮ +│ Math Agent - Tool Executor: │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭────────────────────────────────────────────── Agent Name Math Agent - Agent Analysis [Max Loops: 1 ] ───────────────────────────────────────────────╮ +│ Math Agent - Agent Analysis: It seems like you've provided a reference to a coroutine object, which is not a mathematical query. Please provide a │ +│ specific mathematical question or operation you'd like me to assist you with, and I'll be happy to help! │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ + +Math Agent Response: System: : Your Name: Math Agent + + Your Description: Specialized agent for mathematical computations + + You are a specialized math agent that can perform calculations by calling external math service APIs. +Key responsibilities: +1. Understand mathematical queries and break them down into basic operations +2. Use available math tools (add, multiply, divide) appropriately +3. Provide clear explanations of calculations +4. Handle errors gracefully if operations fail + +Remember to use the available MCP tools for calculations rather than doing them directly. +When you want to use a math tool, reply with a JSON object only: +{"tool_name": "", "a": , "b": } + + +Human:: add 2 and 3 + + +Math Agent: {"tool_name": "add", "a": 2, "b": 3} + + +Tool Executor: + + +Math Agent: It seems like you've provided a reference to a coroutine object, which is not a mathematical query. Please provide a specific mathematical question or operation you'd like me to assist you with, and I'll be happy to help! + + + +Enter your query (or 'exit' to quit): waht tools you have +╭─────────────────────────────────────────────────────── Agent Name Math Agent [Max Loops: 1 ] ───────────────────────────────────────────────────────╮ +│ Math Agent: I have access to three mathematical tools that can perform basic operations: │ +│ │ +│ 1. **Add**: To calculate the sum of two numbers. │ +│ 2. **Multiply**: To calculate the product of two numbers. │ +│ 3. **Divide**: To calculate the quotient of two numbers. │ +│ │ +│ If you have a specific mathematical operation or question in mind, please let me know, and I'll assist you with it! │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────── Agent Name Math Agent - Tool Executor [Max Loops: 1 ] ───────────────────────────────────────────────╮ +│ Math Agent - Tool Executor: [MCP-error] Expecting value: line 1 column 1 (char 0) │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +2025-04-20 11:09:41 | ERROR | swarms.structs.agent:mcp_execution_flow:2807 - MCP flow failed: Expecting value: line 1 column 1 (char 0) +╭────────────────────────────────────────────── Agent Name Math Agent - Agent Analysis [Max Loops: 1 ] ───────────────────────────────────────────────╮ +│ Math Agent - Agent Analysis: It seems there was an error with the math service. Please provide me with a mathematical query or operation you'd like │ +│ to perform, and I'll assist you with it. │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ + +Math Agent Response: System: : Your Name: Math Agent + + Your Description: Specialized agent for mathematical computations + + You are a specialized math agent that can perform calculations by calling external math service APIs. +Key responsibilities: +1. Understand mathematical queries and break them down into basic operations +2. Use available math tools (add, multiply, divide) appropriately +3. Provide clear explanations of calculations +4. Handle errors gracefully if operations fail + +Remember to use the available MCP tools for calculations rather than doing them directly. +When you want to use a math tool, reply with a JSON object only: +{"tool_name": "", "a": , "b": } + + +Human:: add 2 and 3 + + +Math Agent: {"tool_name": "add", "a": 2, "b": 3} + + +Tool Executor: + + +Math Agent: It seems like you've provided a reference to a coroutine object, which is not a mathematical query. Please provide a specific mathematical question or operation you'd like me to assist you with, and I'll be happy to help! + + +Human:: waht tools you have + + +Math Agent: I have access to three mathematical tools that can perform basic operations: + +1. **Add**: To calculate the sum of two numbers. +2. **Multiply**: To calculate the product of two numbers. +3. **Divide**: To calculate the quotient of two numbers. + +If you have a specific mathematical operation or question in mind, please let me know, and I'll assist you with it! + + +Tool Executor: [MCP-error] Expecting value: line 1 column 1 (char 0) + + +Math Agent: It seems there was an error with the math service. Please provide me with a mathematical query or operation you'd like to perform, and I'll assist you with it. + + + +Enter your query (or 'exit' to quit): \ No newline at end of file diff --git a/attached_assets/Pasted-The-log-tells-us-two-separate-things-are-still-wrong-Symptom-Root-cause-1-line-fix--1745147451946.txt b/attached_assets/Pasted-The-log-tells-us-two-separate-things-are-still-wrong-Symptom-Root-cause-1-line-fix--1745147451946.txt new file mode 100644 index 00000000..cfe48bd8 --- /dev/null +++ b/attached_assets/Pasted-The-log-tells-us-two-separate-things-are-still-wrong-Symptom-Root-cause-1-line-fix--1745147451946.txt @@ -0,0 +1,92 @@ +The log tells us two separate things are still wrong: + +| Symptom | Root cause | 1‑line fix | +|---------|------------|------------| +| `RuntimeWarning: coroutine 'batch_mcp_flow' was never awaited` | `batch_mcp_flow()` is **async**, but you call it like a plain function. | `out = await batch_mcp_flow(...)` *or* wrap the call in `asyncio.run(…)` if you want to stay sync. | +| `[MCP‑error] Expecting value: line 1 column 1 (char 0)` | The Fast‑MCP mock server replied, but your client tried to `json.loads()` an **empty body** (usually means the HTTP endpoint or headers are wrong). | Point the URL at the server **root** (`http://0.0.0.0:8000`) and send plain JSON‑RPC. | + +Below is a minimal patch that removes both errors without touching the rest of your code‑base. + +--- + +## 1 ️⃣ — make `mcp_execution_flow()` await the coroutine + +```python +# ── swarms/structs/agent.py ───────────────────────────────────────── + +import asyncio # add this at the top if it’s not there + +# … + +def mcp_execution_flow(self, payload: dict): + """ + Forward the tool‑call dict to every MCP server in self.mcp_servers. + Returns the first non‑error response as a string. + """ + try: + # batch_mcp_flow is async ➜ run it synchronously + result = asyncio.run( + batch_mcp_flow(self.mcp_servers, payload) + ) + return any_to_str(result) + except Exception as err: + logger.error(f"MCP flow failed: {err}") + return f"[MCP-error] {err}" +``` + +*(If you prefer your whole agent to stay async, just make +`mcp_execution_flow` itself `async def` and `await batch_mcp_flow` — +then call it with `await` from the `_run` loop.)* + +--- + +## 2 ️⃣ — use the correct Fast‑MCP endpoint + +In the client that spins up the **math agent**: + +```python +math_server = MCPServerSseParams( + url="http://0.0.0.0:8000", # ← root! no “/mcp” + headers={"Content-Type": "application/json"}, + timeout=5.0, + sse_read_timeout=30.0, +) +``` + +⚠️ Fast‑MCP’s `run(transport="sse", port=8000)` already exposes both +the SSE stream and the JSON‑RPC POST endpoint on that root URL. +Adding `/mcp` makes the request hit a 404, so the body is empty — that’s +exactly what the JSON decoder complained about. + +--- + +## 3 ️⃣ — (optional) turn streaming off until everything works + +```python +math_agent = Agent( + # … + streaming_on=False # ← easier to debug; turn back on later +) +``` + +With streaming disabled, `LiteLLM` returns plain strings, so your +`parse_llm_output()` method won’t be handed a +`CustomStreamWrapper` object any more. + +--- + +### Quick test matrix + +| Action | Expected result | +|--------|-----------------| +| `curl -X POST http://0.0.0.0:8000 -d '{"tool_name":"add","a":2,"b":3}' -H 'Content-Type: application/json'` | `{"result":5}` | +| Run `mock_math_server.py` | “Starting Mock Math Server on port 8000…” | +| Run `mcp_client.py`, type `add 2 and 3` | Agent replies something like “2 + 3 = 5”. No coroutine warning. | + +As soon as the round‑trip works once, you can: + +* re‑enable `streaming_on=True` and teach `parse_llm_output()` to turn a + `CustomStreamWrapper` into text (`"".join(token.choices[0].delta.content for token in wrapper)`); +* point the agent at your real MCP servers instead of the mock one. + +Happy hacking! \ No newline at end of file