Files
agent_management/agent_templates/QUICKSTART.md
T
2026-01-12 15:04:11 +00:00

3.9 KiB

🚀 Azure Blob Storage Agent 快速启动

一键启动命令

1. 构建镜像

cd /home/taiji/tools/agent-manager/agent_templates
./build_azure_blob_agent.sh latest

2. 启动 Agent(本地测试)

# 方式 A: 启动时提供连接字符串(推荐)
docker run -d --name azure-blob-agent \
  -p 8080:8080 \
  -e LITELLM_API_BASE=http://20.2.70.108:4000 \
  -e LITELLM_MODEL=gpt-3.5-turbo \
  -e LITELLM_API_KEY=sk-1234 \
  -e AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx;EndpointSuffix=core.windows.net" \
  azure-blob-agent:latest

# 方式 B: 稍后通过 API 连接
docker run -d --name azure-blob-agent \
  -p 8080:8080 \
  -e LITELLM_API_BASE=http://20.2.70.108:4000 \
  -e LITELLM_MODEL=gpt-3.5-turbo \
  -e LITELLM_API_KEY=sk-1234 \
  azure-blob-agent:latest
  
# 然后调用 /connect API 连接

# 方式 C: 如果 LiteLLM 在另一个容器中
docker run -d --name azure-blob-agent \
  --network host \
  -e LITELLM_API_BASE=http://localhost:4000 \
  -e LITELLM_MODEL=gpt-3.5-turbo \
  -e LITELLM_API_KEY=sk-1234 \
  -e AZURE_STORAGE_CONNECTION_STRING="YOUR_CONNECTION_STRING" \
  azure-blob-agent:latest

3. 测试 Agent

方法 1: 使用 Bash 测试脚本

./test_azure_blob_agent.sh

方法 2: 使用 Python 客户端

# 设置连接字符串(可选)
export AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;AccountName=xxx;..."

# 运行客户端
python3 test_client.py

方法 3: 使用 curl 手动测试

# 健康检查
curl http://localhost:8080/health

# 连接到 Azure Storage
curl -X POST http://localhost:8080/connect \
  -H 'Content-Type: application/json' \
  -d '{
    "connection_string": "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;EndpointSuffix=core.windows.net"
  }'

# 执行查询
curl -X POST http://localhost:8080/query \
  -H 'Content-Type: application/json' \
  -d '{"query": "列出所有容器"}'

推送到 ACR

# 登录 ACR
az acr login --name agnettaiji

# 推送镜像
docker tag azure-blob-agent:latest agnettaiji.azurecr.io/ai-agents/azure-blob-agent:latest
docker push agnettaiji.azurecr.io/ai-agents/azure-blob-agent:latest

在 K8s 中部署

使用 agent-manager

# 添加到 k8s_manager.py 的 image_map
"azure_blob_agent": "agnettaiji.azurecr.io/ai-agents/azure-blob-agent:latest"

# 创建 agent
curl -X POST http://localhost:8000/agents \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "my-blob-agent",
    "template": "azure_blob_agent",
    "env": {
      "LITELLM_API_BASE": "http://litellm-service:4000",
      "LITELLM_MODEL": "gpt-3.5-turbo",
      "LITELLM_API_KEY": "sk-1234"
    }
  }'

常见问题

Q: 容器启动失败

# 查看日志
docker logs azure-blob-agent

# 检查 LiteLLM 是否可达
docker exec azure-blob-agent curl http://host.docker.internal:4000/health

Q: 无法连接到 Azure Storage

# 验证连接字符串格式
# 正确格式包含: AccountName, AccountKey, EndpointSuffix

# 测试连接
curl -X POST http://localhost:8080/connect \
  -H 'Content-Type: application/json' \
  -d '{"connection_string": "YOUR_STRING"}' -v

Q: 查询没有响应

# 检查是否已连接
curl http://localhost:8080/health | jq .

# 查看详细日志
docker logs -f azure-blob-agent

文件清单

agent_templates/
├── azure_blob_agent.py              # 主程序
├── azure_blob_agent.Dockerfile      # Docker 镜像
├── build_azure_blob_agent.sh        # 构建脚本
├── test_azure_blob_agent.sh         # Bash 测试脚本
├── test_client.py                   # Python 客户端
├── AZURE_BLOB_AGENT_USAGE.md        # 详细使用文档
└── QUICKSTART.md                    # 本文件

下一步