From a418c6f782a61aa670689aff9eb3aae38577b1b5 Mon Sep 17 00:00:00 2001 From: Pavan Kumar <66913595+ascender1729@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:43:06 +0000 Subject: [PATCH] feat: enhance test integration with timestamped logging and request workflow --- examples/mcp_example/test_integration.py | 53 +++++++----------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/examples/mcp_example/test_integration.py b/examples/mcp_example/test_integration.py index 102ad828..6806feaf 100644 --- a/examples/mcp_example/test_integration.py +++ b/examples/mcp_example/test_integration.py @@ -1,9 +1,8 @@ - from swarms import Agent from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT from swarms.tools.mcp_integration import MCPServerSseParams import logging -import time +from datetime import datetime def setup_agent(name: str, description: str, servers: list) -> Agent: """Setup an agent with MCP server connections""" @@ -23,7 +22,7 @@ def main(): headers={"Content-Type": "application/json"}, timeout=10.0 ) - + calc_server = MCPServerSseParams( url="http://0.0.0.0:6275", headers={"Content-Type": "application/json"}, @@ -31,58 +30,34 @@ def main(): ) # Initialize specialized agents - coordinator = setup_agent( - "Coordinator", - "Analyzes tasks and coordinates between specialized agents", - [math_server, calc_server] - ) - math_agent = setup_agent( "Math-Agent", "Handles mathematical calculations", [math_server] ) - - business_agent = setup_agent( - "Business-Agent", - "Handles business calculations", - [calc_server] - ) print("\nMulti-Agent MCP Test Environment") print("Type 'exit' to quit\n") - + while True: try: - user_input = input("\nEnter your request (or Ctrl+C to exit): ") - except KeyboardInterrupt: - print("\nExiting gracefully...") - break - + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + user_input = input(f"\n[{timestamp}] Enter your request (or Ctrl+C to exit): ") + if user_input.lower() == 'exit': break - - # Coordinator analyzes task - print("\nCoordinator analyzing task...") - coordinator_response = coordinator.run( - f"Analyze this task and determine required calculations: {user_input}" - ) - print(f"\nCoordinator's plan: {coordinator_response}") - - # Route to appropriate agent(s) - if "profit" in user_input.lower() or "margin" in user_input.lower(): - print("\nRouting to Business Agent...") - result = business_agent.run(user_input) - print(f"\nBusiness calculation result: {result}") - + if any(op in user_input.lower() for op in ['add', 'subtract', 'multiply', 'divide']): - print("\nRouting to Math Agent...") + print(f"\n[{timestamp}] Processing math request...") result = math_agent.run(user_input) - print(f"\nMath calculation result: {result}") + print(f"\n[{timestamp}] Math calculation result: {result}") + except KeyboardInterrupt: + print("\nExiting gracefully...") + break except Exception as e: - print(f"Error processing request: {e}") + print(f"[{timestamp}] Error processing request: {e}") if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - main() + main() \ No newline at end of file