""" 测试脚本 - 列出所有Agents """ import requests import json import sys # 配置 BASE_URL = "http://localhost:8000" def test_list_agents(): """测试列出所有Agent""" print("=" * 50) print("测试: 列出所有AI Agents") print("=" * 50) # 测试1: 列出所有agents print("\n测试1: 列出所有Agents") try: response = requests.get(f"{BASE_URL}/agents") print(f"状态码: {response.status_code}") if response.status_code == 200: result = response.json() print("✅ 查询成功!") print(f"找到 {result['count']} 个Agents") print(f"响应: {json.dumps(result, indent=2, ensure_ascii=False)}") else: print(f"❌ 查询失败!") print(f"错误: {response.text}") except Exception as e: print(f"❌ 请求失败: {str(e)}") print("-" * 50) # 测试2: 按模板类型过滤 templates = ["echo_agent", "chat_agent", "code_agent"] for template in templates: print(f"\n测试2: 列出模板为 {template} 的Agents") try: response = requests.get(f"{BASE_URL}/agents?template={template}") print(f"状态码: {response.status_code}") if response.status_code == 200: result = response.json() print("✅ 查询成功!") print(f"找到 {result['count']} 个 {template} Agents") print(f"响应: {json.dumps(result, indent=2, ensure_ascii=False)}") 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_list_agents() except requests.exceptions.ConnectionError: print("❌ 无法连接到服务。请确保服务正在运行: python app.py") sys.exit(1)