信息去重 Agent
基于 Pydantic AI 的信息去重 Agent,专注于从一堆信息中识别并合并"本质相同"的内容。
核心功能
- 语义去重:不只是文字相同,而是识别本质含义相同的信息
- 聚类分组:将相似信息归为一组,保留最具代表性的表述
- 差异分析:识别看似相同实则有细微差异的信息
快速开始
1. 本地测试
cd dedup_agent
python run_api_server.py
2. 构建镜像
docker build -t dedup-agent:latest .
API 使用
MCP 工具调用
{
"method": "tools/call",
"params": {
"name": "deduplicate_info",
"arguments": {
"items": [
"苹果公司发布了新款 iPhone",
"Apple 推出最新 iPhone 系列",
"微软发布 Windows 更新",
"苹果今天发布了 iPhone 新产品"
]
}
}
}
REST API
curl -X POST http://localhost:8000/api/v1/deduplicate \
-H "Content-Type: application/json" \
-H "api-key: your-api-key" \
-d '{
"items": [
"苹果公司发布了新款 iPhone",
"Apple 推出最新 iPhone 系列",
"微软发布 Windows 更新"
]
}'
项目结构
dedup_agent/
├── Dockerfile
├── requirements.txt
├── run_api_server.py # 启动脚本
├── README.md
└── src/
├── __init__.py
└── server/
├── __init__.py
├── api_server.py # FastAPI + MCP HTTP
└── mcp_server.py # MCP 工具定义(去重逻辑)
环境变量
| 变量 | 必需 | 说明 |
|---|---|---|
| OPENAI_BASE_URL | 否 | LiteLLM Gateway URL |
| OPENAI_API_KEY | 是 | API Key |
| MODEL_NAME | 否 | 模型名称,默认 taiji/gpt-4o-mini |
| API_PORT | 否 | 端口,默认 8000 |
响应示例
{
"success": true,
"groups": [
{
"representative": "苹果公司发布了新款 iPhone",
"members": [
"苹果公司发布了新款 iPhone",
"Apple 推出最新 iPhone 系列",
"苹果今天发布了 iPhone 新产品"
],
"essence": "苹果发布新iPhone"
},
{
"representative": "微软发布 Windows 更新",
"members": ["微软发布 Windows 更新"],
"essence": "微软Windows更新"
}
],
"total_input": 4,
"total_groups": 2,
"dedup_ratio": "50%"
}