From 63bbc34a5431c45dbd206dd695d7b2f1117a7fd1 Mon Sep 17 00:00:00 2001 From: Pavan Kumar <66913595+ascender1729@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:17:50 +0000 Subject: [PATCH] fix: update stock server setup and multi-agent routing logic - Fixed initialization issues in `mock_stock_server.py` - Modified `mock_multi_agent.py` to handle responses from both math and stock servers - Enhanced agent prompts and results processing for multi-server context --- examples/mcp_example/mock_multi_agent.py | 14 +++++++------- examples/mcp_example/mock_stock_server.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/mcp_example/mock_multi_agent.py b/examples/mcp_example/mock_multi_agent.py index e9a47cf6..bc8fb679 100644 --- a/examples/mcp_example/mock_multi_agent.py +++ b/examples/mcp_example/mock_multi_agent.py @@ -13,7 +13,7 @@ class MathAgent: self.agent = Agent( agent_name=name, - agent_description="Math processing agent", + agent_description=f"{'Calculator' if name == 'Calculator' else 'Stock Analyst'} agent specializing in {'mathematical calculations' if name == 'Calculator' else 'stock market analysis'}. For Calculator: use add, multiply, divide operations. For Stock Analyst: use moving averages and percentage change calculations.", system_prompt=f"You are {name}, a math processing agent. You have access to these mathematical operations ONLY: addition, multiplication, and division. Only suggest calculations using these available tools. Do not attempt to solve problems requiring other operations like percentages, square roots, or advanced math. When users ask about capabilities, list only the basic operations you can perform.", max_loops=1, mcp_servers=[self.server], @@ -75,12 +75,12 @@ class MultiAgentMathSystem: results = asyncio.run(self.process_task(user_input)) - print("\nResult:") - result = results[0] # We now only have one result - if "error" in result: - print(f"\nCalculator encountered an error: {result['error']}") - else: - print(f"\nCalculation: {result['response']}") + print("\nResults:") + for result in results: + if "error" in result: + print(f"\n{result['agent']} encountered an error: {result['error']}") + else: + print(f"\n{result['agent']}: {result['response']}") except Exception as e: print(f"System error: {str(e)}") diff --git a/examples/mcp_example/mock_stock_server.py b/examples/mcp_example/mock_stock_server.py index da8f5e32..0c251f2e 100644 --- a/examples/mcp_example/mock_stock_server.py +++ b/examples/mcp_example/mock_stock_server.py @@ -27,4 +27,4 @@ def calculate_percentage_change(old_value: float, new_value: float) -> float: if __name__ == "__main__": print("Starting Mock Stock Server on port 8001...") - mcp.run(transport="sse", host="0.0.0.0", port=8001) + mcp.run(transport="sse", port=8001)