#!/usr/bin/env python3
"""
Check Agent Status - Comprehensive status report
"""
import requests
import json
from datetime import datetime
def check_server_health():
"""Check server health and basic info."""
try:
response = requests.get("http://localhost:8000/api/health", timeout=5)
if response.status_code == 200:
return response.json()
else:
return {"error": f"HTTP {response.status_code}"}
except Exception as e:
return {"error": str(e)}
def check_agents_list():
"""Get detailed agent list."""
try:
response = requests.get("http://localhost:8000/api/agents", timeout=5)
if response.status_code == 200:
return response.json()
else:
return {"error": f"HTTP {response.status_code}"}
except Exception as e:
return {"error": str(e)}
def test_individual_agent(command, agent_name):
"""Test individual agent functionality."""
try:
response = requests.post(
"http://localhost:8000/api/mcp/command",
json={"command": command},
timeout=15
)
if response.status_code == 200:
result = response.json()
return {
"status": result.get("status", "unknown"),
"agent_used": result.get("agent_used", "none"),
"message": result.get("message", ""),
"result": result.get("result", ""),
"city": result.get("city", ""),
"email_sent": result.get("email_sent", False),
"reminder": result.get("reminder", {}),
"weather_data": result.get("weather_data", {}),
"raw_response": result
}
else:
return {"error": f"HTTP {response.status_code}"}
except Exception as e:
return {"error": str(e)}
def main():
"""Main status check function."""
print("π COMPREHENSIVE AGENT STATUS REPORT")
print("=" * 80)
print(f"π Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("=" * 80)
# 1. Server Health Check
print("\nπ SERVER HEALTH CHECK")
print("-" * 50)
health = check_server_health()
if "error" in health:
print(f"β Server Error: {health['error']}")
print("π‘ Try running: python connect_everything.py")
return
print(f"β
Server Status: {health.get('status', 'unknown')}")
print(f"π Server Type: {health.get('server', 'unknown')}")
print(f"β‘ Ready: {health.get('ready', False)}")
print(f"π€ Agents Loaded: {health.get('agents_loaded', 0)}")
print(f"π Available Agents: {', '.join(health.get('available_agents', []))}")
print(f"β° Timestamp: {health.get('timestamp', 'unknown')}")
# 2. Detailed Agent Information
print("\nπ€ DETAILED AGENT INFORMATION")
print("-" * 50)
agents_info = check_agents_list()
if "error" in agents_info:
print(f"β Agents List Error: {agents_info['error']}")
else:
agents = agents_info.get("agents", {})
total_agents = agents_info.get("total_agents", 0)
print(f"π Total Agents: {total_agents}")
for agent_id, agent_data in agents.items():
print(f"\n πΉ {agent_id.upper()}")
print(f" Status: {agent_data.get('status', 'unknown')}")
print(f" Class: {agent_data.get('class_name', 'unknown')}")
print(f" Keywords: {', '.join(agent_data.get('keywords', []))}")
# 3. Individual Agent Testing
print("\nπ§ͺ INDIVIDUAL AGENT TESTING")
print("-" * 50)
test_cases = [
("Calculate 20% of 500", "Math Agent"),
("What is the weather in Mumbai?", "Weather Agent"),
("Send email to test@example.com", "Gmail Agent"),
("Create reminder for tomorrow", "Calendar Agent"),
("Analyze this text: Hello world", "Document Agent")
]
working_agents = 0
total_tests = len(test_cases)
for command, agent_name in test_cases:
print(f"\nπ Testing {agent_name}")
print(f" Command: {command}")
result = test_individual_agent(command, agent_name)
if "error" in result:
print(f" β Error: {result['error']}")
else:
status = result.get("status", "unknown")
agent_used = result.get("agent_used", "none")
if status == "success":
print(f" β
Status: SUCCESS")
print(f" π€ Agent Used: {agent_used}")
working_agents += 1
# Show specific results
if result.get("result"):
print(f" π Result: {result['result']}")
if result.get("city"):
print(f" π City: {result['city']}")
weather = result.get("weather_data", {})
if weather:
temp = weather.get("temperature", "N/A")
desc = weather.get("description", "N/A")
print(f" π‘οΈ Weather: {temp}Β°C, {desc}")
if result.get("reminder"):
print(f" π
Reminder: Created")
if "email" in result.get("message", "").lower():
print(f" π§ Email: Prepared")
else:
print(f" β οΈ Status: {status}")
print(f" π¬ Message: {result.get('message', 'No message')}")
# 4. Summary
print("\n" + "=" * 80)
print("π FINAL STATUS SUMMARY")
print("=" * 80)
success_rate = (working_agents / total_tests) * 100 if total_tests > 0 else 0
print(f"π§ Server: {'β
Running' if health.get('status') == 'ok' else 'β Issues'}")
print(f"π€ Total Agents: {health.get('agents_loaded', 0)}")
print(f"β
Working Agents: {working_agents}/{total_tests}")
print(f"π Success Rate: {success_rate:.1f}%")
if success_rate >= 80:
print(f"β‘ Overall Status: β
EXCELLENT")
print(f"π Your MCP system is performing excellently!")
elif success_rate >= 60:
print(f"β‘ Overall Status: β‘ GOOD")
print(f"π Your MCP system is working well!")
elif success_rate >= 40:
print(f"β‘ Overall Status: β οΈ FAIR")
print(f"π§ Some agents need attention")
else:
print(f"β‘ Overall Status: β NEEDS ATTENTION")
print(f"π§ Multiple agents require troubleshooting")
print(f"\nπ Access Points:")
print(f" β’ Web Interface: http://localhost:8000")
print(f" β’ API Documentation: http://localhost:8000/docs")
print(f" β’ Health Check: http://localhost:8000/api/health")
print(f"\nπ To restart system: python connect_everything.py")
if __name__ == "__main__":
main()