""" 测试脚本 - 获取Agent状态 """ import requests import json import sys # 配置 BASE_URL = "http://localhost:8000" def test_get_agent_status(): """测试获取Agent状态""" print("=" * 50) print("测试: 获取AI Agent状态") print("=" * 50) # 测试的Agent名称列表 agent_names = ["test-echo-1", "test-chat-1", "test-code-1"] for agent_name in agent_names: print(f"\n查询Agent: {agent_name}") try: response = requests.get(f"{BASE_URL}/agents/{agent_name}/status") print(f"状态码: {response.status_code}") if response.status_code == 200: result = response.json() print("✅ 查询成功!") print(f"响应: {json.dumps(result, indent=2, ensure_ascii=False)}") elif response.status_code == 404: print(f"⚠️ Agent不存在") print(f"错误: {response.text}") else: print(f"❌ 查询失败!") print(f"错误: {response.text}") except Exception as e: print(f"❌ 请求失败: {str(e)}") print("-" * 50) if __name__ == "__main__": try: # 先检查服务是否可用 print("检查服务状态...") response = requests.get(f"{BASE_URL}/") print(f"服务状态: {response.json()}\n") test_get_agent_status() except requests.exceptions.ConnectionError: print("❌ 无法连接到服务。请确保服务正在运行: python app.py") sys.exit(1)