forked from zhanggangyong/agent_management
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
"""
|
|
测试脚本 - 删除Agent
|
|
"""
|
|
import requests
|
|
import json
|
|
import sys
|
|
|
|
# 配置
|
|
BASE_URL = "http://localhost:8000"
|
|
|
|
|
|
def test_delete_agent():
|
|
"""测试删除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.delete(f"{BASE_URL}/agents/{agent_name}")
|
|
|
|
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")
|
|
|
|
# 警告
|
|
print("⚠️ 警告: 此脚本将删除测试Agents!")
|
|
confirm = input("确认继续? (yes/no): ")
|
|
|
|
if confirm.lower() == "yes":
|
|
test_delete_agent()
|
|
else:
|
|
print("已取消")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ 无法连接到服务。请确保服务正在运行: python app.py")
|
|
sys.exit(1)
|