182 lines
3.6 KiB
Markdown
182 lines
3.6 KiB
Markdown
# A2A AI Search Agent
|
||
|
||
基于 LiteLLM 和 A2A (Agent2Agent) 协议的智能搜索 Agent API 服务。
|
||
|
||
## 🚀 功能特性
|
||
|
||
- ✅ **A2A 协议兼容** - 完全支持 Google Agent2Agent 协议
|
||
- ✅ **多轮对话** - 维护对话上下文,支持连续对话
|
||
- ✅ **流式响应** - 支持 SSE 流式输出
|
||
- ✅ **LiteLLM 集成** - 统一的 LLM 调用接口
|
||
- ✅ **生产就绪** - 适用于 AKS (Azure Kubernetes Service) 部署
|
||
|
||
## 📁 项目结构
|
||
|
||
```
|
||
a2a-ai-search-agent/
|
||
├── config.py # 配置管理
|
||
├── agent.py # Agent 核心逻辑
|
||
├── a2a_server.py # A2A 协议 API 服务
|
||
├── requirements.txt # Python 依赖
|
||
├── Dockerfile # Docker 镜像
|
||
├── deploy.sh # 部署脚本
|
||
└── k8s/ # Kubernetes 配置
|
||
├── deployment.yaml
|
||
├── service.yaml
|
||
├── configmap.yaml
|
||
└── secret.yaml
|
||
```
|
||
|
||
## 🔧 配置
|
||
|
||
**环境变量:**
|
||
- `LITELLM_API_KEY` - LiteLLM API 密钥(必需)
|
||
- `LITELLM_MODEL` - 模型名称(如: taiji/gpt-4o-mini)
|
||
|
||
**LiteLLM 服务地址:**
|
||
```
|
||
https://litellm.graystone-fb459c5d.southeastasia.azurecontainerapps.io
|
||
```
|
||
|
||
## 🐳 Docker 部署
|
||
|
||
### 构建镜像
|
||
|
||
```bash
|
||
docker build -t a2a-ai-search-agent:latest .
|
||
```
|
||
|
||
### 运行容器
|
||
|
||
```bash
|
||
docker run -d \
|
||
-p 9000:9000 \
|
||
-e LITELLM_API_KEY="your-api-key" \
|
||
-e LITELLM_MODEL="taiji/gpt-4o-mini" \
|
||
a2a-ai-search-agent:latest
|
||
```
|
||
|
||
## ☸️ Kubernetes 部署
|
||
|
||
### 推送到 ACR
|
||
|
||
```bash
|
||
# 登录 ACR
|
||
docker login agnettaiji.azurecr.io -u agnettaiji -p 'YOUR_PASSWORD'
|
||
|
||
# 打标签
|
||
docker tag a2a-ai-search-agent:latest agnettaiji.azurecr.io/xiaohei-agent:latest
|
||
|
||
# 推送
|
||
docker push agnettaiji.azurecr.io/xiaohei-agent:latest
|
||
```
|
||
|
||
### 部署到 AKS
|
||
|
||
```bash
|
||
# 方式1: 使用脚本
|
||
./deploy.sh
|
||
|
||
# 方式2: 手动部署
|
||
kubectl apply -f k8s/configmap.yaml
|
||
kubectl apply -f k8s/secret.yaml
|
||
kubectl apply -f k8s/deployment.yaml
|
||
kubectl apply -f k8s/service.yaml
|
||
```
|
||
|
||
### 查看部署状态
|
||
|
||
```bash
|
||
# 查看 Pod
|
||
kubectl get pods -l app=xiaohei-agent
|
||
|
||
# 查看 Service 和外网 IP
|
||
kubectl get svc xiaohei-agent-service
|
||
|
||
# 实时监控外网 IP 分配
|
||
kubectl get svc xiaohei-agent-service -w
|
||
```
|
||
|
||
## 📡 API 端点
|
||
|
||
### 健康检查
|
||
```bash
|
||
GET /health
|
||
```
|
||
|
||
### Agent Card (A2A 发现)
|
||
```bash
|
||
GET /.well-known/agent.json
|
||
```
|
||
|
||
**响应示例:**
|
||
```json
|
||
{
|
||
"name": "xiaohei-agent",
|
||
"description": "一个基于LiteLLM的智能Agent,支持A2A协议",
|
||
"version": "1.0.0",
|
||
"capabilities": {
|
||
"text": true,
|
||
"streaming": true,
|
||
"push_notifications": false
|
||
},
|
||
"skills": [
|
||
{
|
||
"id": "general-assistant",
|
||
"name": "通用助手",
|
||
"description": "回答问题、提供建议、协助完成各种任务"
|
||
}
|
||
]
|
||
}
|
||
```
|
||
|
||
### 发送消息 (非流式)
|
||
|
||
```bash
|
||
POST /message/send
|
||
Content-Type: application/json
|
||
|
||
{
|
||
"jsonrpc": "2.0",
|
||
"id": "request-1",
|
||
"method": "message/send",
|
||
"params": {
|
||
"message": {
|
||
"role": "user",
|
||
"parts": [{"kind": "text", "text": "你好"}],
|
||
"messageId": "msg-1"
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
### 发送消息 (流式)
|
||
|
||
```bash
|
||
POST /message/stream
|
||
Content-Type: application/json
|
||
|
||
{
|
||
"jsonrpc": "2.0",
|
||
"id": "request-1",
|
||
"method": "message/stream",
|
||
"params": {
|
||
"message": {
|
||
"role": "user",
|
||
"parts": [{"kind": "text", "text": "你好"}],
|
||
"messageId": "msg-1"
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
## 🔗 相关资源
|
||
|
||
- [A2A 协议规范](https://github.com/a2aproject/A2A)
|
||
- [LiteLLM 文档](https://docs.litellm.ai/)
|
||
- [Google Agent2Agent 介绍](https://developers.googleblog.com/en/a2a-a-new-era-of-agent-interoperability)
|
||
|
||
## 📄 许可证
|
||
|
||
MIT License
|