forked from zhanggangyong/agent_management
173 lines
5.5 KiB
Bash
Executable File
173 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 测试 Azure Blob Agent 多框架版本
|
|
# 用法: ./test_multi_framework.sh
|
|
|
|
set -e
|
|
|
|
echo "🧪 测试 Azure Blob Agent 多框架版本"
|
|
echo "======================================"
|
|
|
|
# 配置
|
|
AGENT_MANAGER_URL="http://localhost:8000"
|
|
OWNER_ID="test-user"
|
|
NAMESPACE="ai-agents"
|
|
|
|
# Azure Storage 连接字符串(从环境变量获取)
|
|
STORAGE_CONN_STRING="${AZURE_STORAGE_CONNECTION_STRING}"
|
|
|
|
if [ -z "$STORAGE_CONN_STRING" ]; then
|
|
echo "❌ 错误: 请设置环境变量 AZURE_STORAGE_CONNECTION_STRING"
|
|
exit 1
|
|
fi
|
|
|
|
# 模型配置(从环境变量获取)
|
|
MODEL_API_KEY="${OPENAI_API_KEY:-sk-test}"
|
|
|
|
echo ""
|
|
echo "📋 配置信息:"
|
|
echo " - Agent Manager: $AGENT_MANAGER_URL"
|
|
echo " - Owner ID: $OWNER_ID"
|
|
echo " - Namespace: $NAMESPACE"
|
|
echo ""
|
|
|
|
# 测试函数
|
|
test_agent() {
|
|
local framework=$1
|
|
local template=$2
|
|
local agent_name=$3
|
|
local extra_config=$4
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "🧪 测试 $framework 版本"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
# 构建请求 JSON
|
|
local request_json=$(cat <<EOF
|
|
{
|
|
"name": "$agent_name",
|
|
"template_name": "$template",
|
|
"owner_id": "$OWNER_ID",
|
|
"namespace": "$NAMESPACE",
|
|
"agent_framework": "$framework",
|
|
"storage_connection_string": "$STORAGE_CONN_STRING",
|
|
"model_provider": "openai",
|
|
"model_name": "gpt-4",
|
|
"model_api_key": "$MODEL_API_KEY",
|
|
"tools_config": {
|
|
"max_iterations": 5
|
|
}
|
|
$extra_config
|
|
}
|
|
EOF
|
|
)
|
|
|
|
echo "📤 创建 Agent..."
|
|
response=$(curl -s -X POST "$AGENT_MANAGER_URL/v2/agents/platform" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$request_json")
|
|
|
|
echo "✅ 响应: $response"
|
|
|
|
# 检查是否创建成功
|
|
if echo "$response" | grep -q "id"; then
|
|
echo "✅ Agent 创建成功"
|
|
|
|
# 等待 Agent 启动
|
|
echo "⏳ 等待 Agent 启动..."
|
|
sleep 10
|
|
|
|
# 获取 Agent 状态
|
|
echo "📊 获取 Agent 状态..."
|
|
status_response=$(curl -s "$AGENT_MANAGER_URL/v2/agents/$agent_name")
|
|
echo "$status_response" | jq '.'
|
|
|
|
# 提取 service_url
|
|
service_url=$(echo "$status_response" | jq -r '.service_url // empty')
|
|
|
|
if [ -n "$service_url" ]; then
|
|
echo "🌐 Service URL: $service_url"
|
|
|
|
# 测试健康检查
|
|
echo "💓 测试健康检查..."
|
|
health_response=$(curl -s "$service_url/health")
|
|
echo "$health_response" | jq '.'
|
|
|
|
# 根据框架测试特定功能
|
|
case $framework in
|
|
"mcp")
|
|
echo "🔧 测试 MCP 工具列表..."
|
|
curl -s "$service_url/mcp/tools" | jq '.'
|
|
|
|
echo "🔧 测试 MCP 工具调用..."
|
|
curl -s -X POST "$service_url/mcp/call" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"tool_name": "list_containers", "parameters": {}}' | jq '.'
|
|
;;
|
|
"a2a")
|
|
echo "🤝 测试 A2A 能力..."
|
|
curl -s "$service_url/a2a/capabilities" | jq '.'
|
|
|
|
echo "🤝 测试 A2A 消息..."
|
|
curl -s -X POST "$service_url/a2a/message" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"message_id": "test-001",
|
|
"from_agent": "test-agent",
|
|
"to_agent": "blob-agent",
|
|
"message_type": "request",
|
|
"action": "list_containers",
|
|
"parameters": {}
|
|
}' | jq '.'
|
|
;;
|
|
"langchain")
|
|
echo "🔗 测试查询..."
|
|
curl -s -X POST "$service_url/query" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"query": "列出所有容器"}' | jq '.'
|
|
;;
|
|
esac
|
|
else
|
|
echo "⚠️ 警告: 未找到 service_url"
|
|
fi
|
|
|
|
# 删除测试 Agent
|
|
echo "🗑️ 删除测试 Agent..."
|
|
delete_response=$(curl -s -X DELETE "$AGENT_MANAGER_URL/v2/agents/$agent_name")
|
|
echo "$delete_response" | jq '.'
|
|
|
|
else
|
|
echo "❌ Agent 创建失败"
|
|
echo "$response"
|
|
return 1
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
# 运行测试
|
|
echo "🚀 开始测试..."
|
|
echo ""
|
|
|
|
# 测试 MCP 版本
|
|
test_agent "mcp" "azure_blob_agent_mcp" "test-blob-mcp" ""
|
|
|
|
# 测试 A2A 版本
|
|
test_agent "a2a" "azure_blob_agent_a2a" "test-blob-a2a" ',
|
|
"query_params": {
|
|
"agent_id": "test-blob-a2a",
|
|
"agent_role": "storage_manager"
|
|
}'
|
|
|
|
# 测试 LangChain 版本(如果已部署)
|
|
# test_agent "langchain" "azure_blob_agent" "test-blob-langchain" ',
|
|
# "environment_vars": {
|
|
# "LITELLM_API_BASE": "http://litellm-service:4000",
|
|
# "LITELLM_MODEL": "gpt-3.5-turbo",
|
|
# "LITELLM_API_KEY": "sk-test"
|
|
# }'
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "✅ 所有测试完成"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|