diff --git a/attached_assets/Pasted--Math-Calculator-Ready-Available-operations-add-multiply-divide-Example-add-5-and-3-or-mu-1745164619960.txt b/attached_assets/Pasted--Math-Calculator-Ready-Available-operations-add-multiply-divide-Example-add-5-and-3-or-mu-1745164619960.txt new file mode 100644 index 00000000..73e4c26c --- /dev/null +++ b/attached_assets/Pasted--Math-Calculator-Ready-Available-operations-add-multiply-divide-Example-add-5-and-3-or-mu-1745164619960.txt @@ -0,0 +1,54 @@ + +Math Calculator Ready! +Available operations: add, multiply, divide +Example: 'add 5 and 3' or 'multiply 4 by 6' +Type 'exit' to quit + +Enter math operation: add 2 and 3 +╭─────────────────────────────── Agent Name Math Agent [Max Loops: 1 ] ────────────────────────────────╮ +│ Math Agent: {"tool_name": "add", "a": 2, "b": 3} │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ +2025-04-20 15:56:47 | ERROR | swarms.tools.mcp_integration:_call_one_server:475 - Error calling server: ClientSession.__init__() missing 2 required positional arguments: 'read_stream' and 'write_stream' +╭─────────────────────── Agent Name Math Agent - Tool Executor [Max Loops: 1 ] ────────────────────────╮ +│ Math Agent - Tool Executor: No result from tool execution │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────── Agent Name Math Agent - Agent Analysis [Max Loops: 1 ] ───────────────────────╮ +│ Math Agent - Agent Analysis: {"tool_name": "add", "a": 0, "b": 0} │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ +Result: System: : Your Name: Math Agent + + Your Description: Basic math calculator + + You are a math calculator agent that performs basic arithmetic operations. + +Available operations: +- Addition: add numbers together +- Multiplication: multiply numbers +- Division: divide numbers (checks for division by zero) + +You must respond with the operation and numbers in this exact format: +{"tool_name": "", "a": , "b": } + +Example: +User: "add 5 and 3" +You: {"tool_name": "add", "a": 5, "b": 3} + +Parse the numbers as integers. Only return the operation format, no other text. + + +Human:: add 2 and 3 + + +Math Agent: {"tool_name": "add", "a": 2, "b": 3} + + +error: No result from tool execution + + +Tool Executor: No result from tool execution + + +Math Agent: {"tool_name": "add", "a": 0, "b": 0} + + +Enter math operation: \ No newline at end of file diff --git a/swarms/prompts/agent_prompts.py b/swarms/prompts/agent_prompts.py index 93eef830..f8554063 100644 --- a/swarms/prompts/agent_prompts.py +++ b/swarms/prompts/agent_prompts.py @@ -1,28 +1,20 @@ # Agent prompts for MCP testing and interactions -MATH_AGENT_PROMPT = '''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 - -Available tools and their JSON formats: -- Addition: {"tool_name": "add", "a": , "b": } -- Multiplication: {"tool_name": "multiply", "a": , "b": } -- Division: {"tool_name": "divide", "a": , "b": } - -IMPORTANT: -1. Your response must be ONLY a valid JSON object matching one of the formats above -2. Do not include any additional text, explanations, or formatting -3. Convert all numbers to integers -4. Do not include any markdown, code blocks, or other formatting - -Example interaction: +MATH_AGENT_PROMPT = '''You are a math calculator agent that performs basic arithmetic operations. + +Available operations: +- Addition: add numbers together +- Multiplication: multiply numbers +- Division: divide numbers (checks for division by zero) + +You must respond with the operation and numbers in this exact format: +{"tool_name": "", "a": , "b": } + +Example: User: "add 5 and 3" You: {"tool_name": "add", "a": 5, "b": 3} -Remember to use the available MCP tools for calculations rather than doing them directly.''' +Parse the numbers as integers. Only return the operation format, no other text.''' FINANCE_AGENT_PROMPT = """You are a financial analysis agent with access to stock market data services. Key responsibilities: diff --git a/swarms/tools/mcp_integration.py b/swarms/tools/mcp_integration.py index b046b3b5..320385ff 100644 --- a/swarms/tools/mcp_integration.py +++ b/swarms/tools/mcp_integration.py @@ -20,7 +20,12 @@ from anyio.streams.memory import ( from mcp.types import CallToolResult, JSONRPCMessage # Kept for backward compatibility, might be removed later from swarms.utils.any_to_str import any_to_str - +from mcp import ( + ClientSession as OldClientSession, # Kept for backward compatibility with stdio + StdioServerParameters, + Tool as MCPTool, + stdio_client, +) class MCPServer(abc.ABC): """Base class for Model Context Protocol servers.""" @@ -500,9 +505,3 @@ async def _batch(params: List[MCPServerSseParams], payload: dict[str, Any] | str return [] -from mcp import ( - ClientSession as OldClientSession, # Kept for backward compatibility with stdio - StdioServerParameters, - Tool as MCPTool, - stdio_client, -) \ No newline at end of file