多代理系统

一个由多个代理(如DbAgent、MailerAgent和ReportAgent)组成的系统,用于协调执行任务如存储报告和发送通知,支持Postgres和SMTP/MailHog,也可通过n8n工作流进行后端操作。

  • by iyswarrya
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 iyswarrya/mcp_agent_demo

使用说明

微型多智能体系统(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保持不变;只有后端发生了变化。

  1. 开始n8n(和postgres+mailhog): docker compose up -d postgres mailhog n8n
  2. 在n8n中,导入 workflows/n8n_db_email_workflow.json,设置Postgres和MailHog SMTP凭据,并激活工作流。 → 一步一步: docs/N8N_SETUP.md
  3. 产生 .env: N8N_WEBHOOK_URL=http://localhost:5678/webhook/db-email-report
  4. 跑 仅 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.