feat: enhance test integration with timestamped logging and request workflow

pull/819/head
Pavan Kumar 2 days ago committed by ascender1729
parent 64c79523f3
commit a418c6f782

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