多代理客户服务系统

一个结合Agent-to-Agent (A2A)通信和Model Context Protocol (MCP)进行数据库操作的多代理客户服务系统。

  • by worldtu
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 worldtu/Multi-Agent-Customer-Service-System-with-A2A-and-MCP

使用说明

基于A2A和MCP的多Agent客户服务系统

一种多代理客户服务系统,将agent到agent(A2A)通信与模型上下文协议(MCP)相结合,用于数据库操作。

建筑

MCP服务器:通过模型上下文协议进行数据库操作

  • 工具: get_customer, list_customers, update_customer, create_ticket, get_customer_history

A2A代理:

  • 路由器代理:路由查询并协调工作流
  • 客户数据代理:通过MCP处理数据库操作
  • 支援谍员:提供格式化的支持响应

需求

  • Python 3.10+
  • 虚拟环境

设置

1.创建虚拟环境

cd Multi-Agent-Customer-Service-System-with-A2A-and-MCP

python -m venv venv

# Activate
source venv/bin/activate  # macOS/Linux
# or
venv\Scripts\activate  # Windows

2.安装依赖项

所有必需的Python包都列在 requirements.txt:

pip install -r requirements.txt

3.配置环境

创建 .env 文件:

cp .env.example .env

编辑 .env 并添加:

  • GOOGLE_API_KEY (必填)
  • NGROK_AUTHTOKEN (可选)

4.初始化数据库

python database_setup.py

跑步

启动所有服务

source venv/bin/activate
python run_all.py

按Ctrl+C停止。

手动启动(可选)

1号航站楼:

python run_mcp_server.py

2号航站楼:

python run_agents.py

3号航站楼:

python test_system.py

项目结构

Multi-Agent-Customer-Service-System-with-A2A-and-MCP/
│
├── requirements.txt              # Python package dependencies
├── .env.example                  # Environment variables template
├── .gitignore                    # Git ignore rules
│
├── config.py                     # System configuration
├── database_setup.py             # Database initialization script
│
├── run_all.py                    # 🚀 ONE-COMMAND LAUNCHER
├── run_mcp_server.py             # Start MCP server only
├── run_agents.py                 # Start A2A agents only
├── test_system.py                # Run test suite
│
├── mcp/                          # MCP Server
│   ├── __init__.py
│   ├── tools.py                  # Database operations (get, list, update, create, history)
│   └── server.py                 # Flask server with SSE
│
├── agents/                       # A2A Agents
│   ├── __init__.py
│   ├── router_agent.py           # Orchestrator (routes queries)
│   ├── customer_data_agent.py    # Specialist (database operations)
│   └── support_agent.py          # Specialist (customer support)
│
├── client/                       # A2A Client
│   ├── __init__.py
│   └── a2a_client.py             # Multi-hop communication
│
└── utils/                        # Utilities
    ├── __init__.py
    ├── json_parser.py            # JSON extraction & parsing
    └── logger.py                 # Colored logging

查询示例

简单的客户查找

查询:

Get customer information for ID 5

输出:

Here is the information for customer ID 5:

- Name: Charlie Brown
- Email: charlie.brown@email.com
- Phone: +1-555-0105
- Status: Active
- Account created: 2025-11-16

复杂的多客户查询

查询:

Show me all active customers who have open tickets

输出:

Here are all active customers with open tickets:

1. Alice Williams (alice.w@techcorp.com):
   - Ticket #2: Database connection timeout errors (High priority, In Progress)
   - Ticket #24: Feature request: integration with Slack (Low priority, Open)

2. Charlie Brown (charlie.brown@email.com):
   - Ticket #8: Email notifications not being received (Medium priority, Open)

3. Edward Norton (e.norton@business.net):
   - Ticket #7: Payment processing failing for all transactions (High priority, Open)

信息缺失升级

查询:

I've been charged twice, please refund immediately!

输出:

I understand you've been charged twice and need an immediate refund. To help you with this, 
I need your customer ID. Could you please provide it?

使用客户ID升级

查询:

I'm customer 2. I've been charged twice, please refund immediately!

输出:

I've created a high-priority ticket (#35) for your urgent refund request regarding the duplicate 
charge. Our billing team has been notified and will process your refund within 24-48 hours. 
You'll receive an email confirmation once the refund is initiated.

Ticket Details:
- Ticket ID: #35
- Priority: High
- Status: Open
- Created: 2025-11-16 03:15:30

多意图查询

查询:

I'm customer 4. Update my email to new@email.com and show my ticket history

输出:

Your email has been successfully updated to new@email.com.

Here is your ticket history (2 tickets total):

1. Ticket #2: Database connection timeout errors
   - Status: In Progress
   - Priority: High
   - Created: 2025-11-16 01:21:36

2. Ticket #24: Feature request: integration with Slack
   - Status: Open
   - Priority: Low
   - Created: 2025-11-16 01:21:36

环境变量

变量 必填 描述
GOOGLE_API_KEY 是 谷歌人工智能API密钥
GOOGLE_CLOUD_PROJECT 否 GCP项目ID
NGROK_AUTHTOKEN 否 用于公共MCP访问

故障排除

# Reinstall dependencies
pip install -r requirements.txt --force-reinstall

# Check MCP server
curl http://127.0.0.1:5000/health

# Verify environment
python -c "from config import *; print(GOOGLE_API_KEY)"