ADK A2A概念ElevenLabs集成
FastAPI模板演示了Google ADK与MCP和A2A(代理到代理)协议。集成了Notion和ElevenLabs的多代理系统。
该项目演示了一个使用谷歌代理开发工具包(ADK)的多代理系统,该系统集成了用于信息检索的Notion和用于文本到语音转换的ElevenLabs。
该系统展示了一个完全解耦的Agent到Agent(A2A)架构。
请使用随附的 YouTube速成课程视频.
备注:此存储库包含与教程系列一起使用的起始代码。有关完整实施,请查看 lesson-complete 支。🔨 生成器包
对于那些希望深入了解ADK开发的人来说,我创建了一个可选的构建器包,其中包括:
- host agent和worker agent的完整源代码
- ADK开发和A2A模式的备忘单
- .cursor/用于一致提示工程的规则
- 全面的pytest测试套件
- 完整的课程计划
您可以在以下网址获得Builder Pack 崇祯树公路网/l/adk-builder-pack-1.
☕ 支持项目
如果你发现这个教程系列和代码库对你的AI代理开发之旅有帮助,可以考虑给我买杯咖啡!您的支持帮助我创建了更多关于人工智能和代理开发的教育内容。
建筑
该系统由以下部分组成:
- ElevenLabsAgent(A2A服务):用于文本到语音转换的工作代理。
- 通知代理(A2A服务):从Notion检索信息的工作代理。
- HostAgent(A2A服务):协调Notion和ElevenLabs代理的协调代理。
- 流线型用户界面:提供了两个单独的用户界面来演示不同的架构模式:
- 嵌入式运行程序UI:UI在同一进程中运行HostAgent。 - A2A客户端用户界面:UI作为单独的、解耦的服务与HostAgent通信。
参见 LESSON.md 详细的架构分解和设计决策。
先决条件
- Python 3.13+
- 通知帐户和API密钥
- ElevenLabs帐户和API密钥
uv包管理器(推荐)或pip
项目结构
adk-a2a-mcp/
├── host_agent/ # Coordinator Agent
│ ├── agent.py # Agent definition (with delegate_task tool)
│ ├── agent_executor.py # Handles session management (context_id -> session_id)
│ ├── prompt.py # Orchestration instructions
│ ├── remote_connections.py # A2A client logic
│ ├── tools.py # ADK Tools for A2A delegation
│ ├── test_client.py # Standalone test client
│ └── __main__.py # A2A service entry point
├── notion_agent/ # Worker Agent
│ ├── agent.py
│ ├── agent_executor.py
│ ├── prompt.py
│ ├── test_client.py
│ └── __main__.py
├── elevenlabs_agent/ # Worker Agent
│ ├── agent.py
│ ├── agent_executor.py
│ ├── prompt.py
│ ├── test_client.py
│ └── __main__.py
├── ui/ # Streamlit UIs
│ ├── app.py # Embedded Runner UI
│ └── a2a_app.py # Decoupled A2A Client UI
├── scripts/
│ └── start_agents.py # Convenience script to launch all agent services
├── tests/ # Pytest integration tests
│ ├── test_host_agent.py
│ ├── test_notion_agent.py
│ └── test_elevenlabs_agent.py
├── logs/ # Agent logs are stored here
├── .env.example # Example environment variables
├── pyproject.toml # Project config and dependencies (single source of truth)
└── README.md # This file设置
- 克隆存储库:
git clone
cd adk-a2a-mcp- 创建并激活虚拟环境:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- 从单一真实来源安装依赖关系,
pyproject.toml:
uv pip install -e ".[dev]"- 创建一个
.env文件,并添加您的API密钥:
cp .env.example .env
# Now edit .env and add your keys这 .env 文件应包含:
NOTION_API_KEY="your_notion_api_key_here"
ELEVENLABS_API_KEY="your_elevenlabs_api_key_here"
ANTHROPIC_API_KEY="your_anthropic_api_key_here" # Required for some agents
# A2A Service URLs (defaults)
HOST_AGENT_A2A_URL="http://localhost:8001"
NOTION_AGENT_A2A_URL="http://localhost:8002"
ELEVENLABS_AGENT_A2A_URL="http://localhost:8003"运行整个系统
这是运行整个多代理系统的推荐方式。
- 启动所有代理服务:
提供了一个方便的脚本,用于在后台启动Host、Notion和ElevenLabs代理。他们的日志将保存到 logs/ 目录。
python scripts/start_agents.py您可以通过以下方式查看代理的状态 ps aux | grep _agent.
- 运行UI应用程序:
从两个UI中选择一个与系统交互。
- 对于解耦A2A UI(建议用于测试完整架构):
streamlit run ui/a2a_app.py --server.port 8080- 对于嵌入式Runner UI:
streamlit run ui/app.py --server.port 8080- 停止服务:
您可以通过以下方式停止后台代理进程:
pkill -f "_agent"测试单个代理(独立)
对于开发和调试,独立测试每个代理至关重要。每个代理都有一个 test_client.py 其直接与其A2A服务通信。
- 启动目标代理的服务例如,要测试Notion代理:
python -m notion_agent --port 8002- 在单独的终端中,运行其测试客户端:
python notion_agent/test_client.py对其他代理遵循相同的模式:
- python -m elevenlabs_agent --port 8003 -> python elevenlabs_agent/test_client.py - python -m host_agent --port 8001 -> python host_agent/test_client.py
自动化集成测试(pytest)
这 tests/ 目录包含集成测试,这些测试使用 pytest每个测试文件(例如。, tests/test_notion_agent.py)负责:
- 在子流程中自动启动所需代理的A2A服务。
- 从相应的逻辑执行
test_client.py反对正在运行的服务。 - 断言通信成功,代理行为符合预期。
要运行所有集成测试,请执行以下操作:
pytest -v要运行特定代理的测试,请执行以下操作:
pytest -v tests/test_notion_agent.py开发工作流程
- 代码格式化:
black .&&isort . - 类型检查:
mypy . - 测试:
pytest
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
本软件按“原样”提供,不提供任何明示或暗示的保证。
