微型多智能体系统(MCP+A2A)
三个代理设置:
- ReportAgent(A2A服务器) –接收任务“存储报告+通知”;编排DbAgent和MailerAgent。
- DbAgent(MCP) –仅限Postgres:
insert_report,list_reports. - 邮件代理(MCP) –仅限SMTP/MailHog:
send_email.
前提条件
- Python 3.10+
- Postgres和MailHog(例如通过docker compose)
设置
cd mcp-http-agent-demo
python -m venv .venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
pip install -r requirements.txt
cp .env.example .env
# Set OPENAI_API_KEY in .env启动Postgres和MailHog(以及可选的n8n):
docker compose up -d postgres mailhog运行多代理系统
终端1–DbAgent(MCP,端口8001)
python -m multi_agent.db_agent.server终端2–邮件代理(MCP,端口8002)
python -m multi_agent.mailer_agent.server终端3–ReportAgent(A2A HTTP,端口8000)
python -m multi_agent.report_agent.server终端4-客户端代理(呼叫ReportAgent)
python -m agent.run_agent流量: User → ClientAgent(工具)→ ReportAgent HTTP→ 报告代理(LLM+MCP)→ DbAgent+邮件代理.
使用n8n作为后端
您可以使用 n8n工作流程 而不是DbAgent+MailerAgent。客户端和ReportAgent保持不变;只有后端发生了变化。
- 开始n8n(和postgres+mailhog):
docker compose up -d postgres mailhog n8n - 在n8n中,导入
workflows/n8n_db_email_workflow.json,设置Postgres和MailHog SMTP凭据,并激活工作流。 → 一步一步: docs/N8N_SETUP.md - 产生
.env:N8N_WEBHOOK_URL=http://localhost:5678/webhook/db-email-report - 跑 仅 ReportAgent和客户端(不需要DbAgent或MailerAgent或
OPENAI_API_KEY对于ReportAgent):
- python -m multi_agent.report_agent.server - python -m agent.run_agent
ReportAgent将POST到n8n webhook进行“存储报告+通知”。 GET http://localhost:8000/health 显示 "backend": "n8n" 或 "DbAgent+MailerAgent (MCP)".
可选的环境变量(请参见 .env.example): POSTGRES_*, SMTP_*, REPORT_AGENT_URL, DB_AGENT_URL, MAILER_AGENT_URL, N8N_WEBHOOK_URL.
