Files
2026-03-15 15:34:11 +00:00
..
2026-03-15 15:34:11 +00:00
2026-03-15 15:34:11 +00:00
2026-02-05 16:01:34 +00:00
2026-03-15 15:34:11 +00:00
2026-03-15 15:34:11 +00:00
2026-02-05 16:01:34 +00:00

Agent 模板

基于 Pydantic AI 的轻量级 Agent 模板。

快速开始

1. 复制模板

cp -r _template your_agent_name
cd your_agent_name
# 全局替换 "your_agent" 为你的 agent 名称

2. 修改核心文件

  • src/server/mcp_server.py - 添加你的 MCP 工具
  • src/server/api_server.py - 添加你的 API 端点(可选)

3. 本地测试

python run_api_server.py

4. 构建镜像

docker build -t your-agent:latest .

5. 注册到 Agent Manager

在 k8s_manager.py 中添加:

# TEMPLATE_PORTS
"your_agent": 8000,

# image_map
"your_agent": "agnettaiji.azurecr.io/ai-agents/your-agent:latest",

在 app.py 的 valid_templates 中添加 "your_agent"。

项目结构

your_agent/
├── Dockerfile
├── common/
│   ├── __init__.py
│   └── agent_callback_utils.py  # callback 工具
├── requirements.txt
├── run_api_server.py      # 启动脚本
└── src/
    ├── __init__.py
    └── server/
        ├── __init__.py
        ├── api_server.py   # FastAPI + MCP HTTP
        └── mcp_server.py   # MCP 工具定义

环境变量

变量 必需 说明
LITELLM_GATEWAY_URL 是 LiteLLM Gateway URL
LITELLM_MODEL 否 模型名称,默认 taiji/gpt-4o-mini
API_PORT 否 端口,默认 8000
POD_NAME 否 Agent 名称,用于 callback 中的 agentName
USER_ID 否 用户 ID,用于 callback 中的 userId
AGENT_CALLBACK_URL 否 回调地址,默认指向 Agent Manager 计费回调接口

Callback 模板说明

  • 模板已内置 common/agent_callback_utils.py
  • src/server/api_server.py 已示范在 tools/call 和业务 API 中使用 CallbackContextManager
  • 以后新增业务接口时,优先复用 run_with_callback(...) 来包裹真实工具调用