Checkpoint before assistant change: Fixes a math calculator error

Updated agent prompts and MCP integration to fix an error in the math calculator functionality; specifically addressing issues in `swarms/prompts/agent_prompts.py` and `swarms/tools/mcp_integration.py`.  The `ClientSession` initialization was also corrected.

Replit-Commit-Author: Assistant
pull/819/head
DP37 3 months ago committed by ascender1729
parent c490e82e34
commit d46da9c8bb

@ -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": "<operation>", "a": <first_number>, "b": <second_number>}
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:

@ -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": <number>, "b": <number>}
- Multiplication: {"tool_name": "multiply", "a": <number>, "b": <number>}
- Division: {"tool_name": "divide", "a": <number>, "b": <number>}
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": "<operation>", "a": <first_number>, "b": <second_number>}
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:

@ -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,
)
Loading…
Cancel
Save