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 import Agent
from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT
from swarms.tools.mcp_integration import MCPServerSseParams from swarms.tools.mcp_integration import MCPServerSseParams
import logging import logging
import time from datetime import datetime
def setup_agent(name: str, description: str, servers: list) -> Agent: def setup_agent(name: str, description: str, servers: list) -> Agent:
"""Setup an agent with MCP server connections""" """Setup an agent with MCP server connections"""
@ -23,7 +22,7 @@ def main():
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},
timeout=10.0 timeout=10.0
) )
calc_server = MCPServerSseParams( calc_server = MCPServerSseParams(
url="http://0.0.0.0:6275", url="http://0.0.0.0:6275",
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},
@ -31,58 +30,34 @@ def main():
) )
# Initialize specialized agents # Initialize specialized agents
coordinator = setup_agent(
"Coordinator",
"Analyzes tasks and coordinates between specialized agents",
[math_server, calc_server]
)
math_agent = setup_agent( math_agent = setup_agent(
"Math-Agent", "Math-Agent",
"Handles mathematical calculations", "Handles mathematical calculations",
[math_server] [math_server]
) )
business_agent = setup_agent(
"Business-Agent",
"Handles business calculations",
[calc_server]
)
print("\nMulti-Agent MCP Test Environment") print("\nMulti-Agent MCP Test Environment")
print("Type 'exit' to quit\n") print("Type 'exit' to quit\n")
while True: while True:
try: try:
user_input = input("\nEnter your request (or Ctrl+C to exit): ") timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
except KeyboardInterrupt: user_input = input(f"\n[{timestamp}] Enter your request (or Ctrl+C to exit): ")
print("\nExiting gracefully...")
break
if user_input.lower() == 'exit': if user_input.lower() == 'exit':
break 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']): 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) 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: except Exception as e:
print(f"Error processing request: {e}") print(f"[{timestamp}] Error processing request: {e}")
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
main() main()
Loading…
Cancel
Save