使用说明
DeepDraft——多智能体研究与写作(MCP+LangGraph)
DeepDraft是一个 多智能体系统 它采用LangGraph代理、模型上下文协议(MCP)工具服务器和Streamlit UI,自动研究网络、创建大纲、编写完整文档,然后对其进行总结。
技能:多代理编排、MCP工具服务器、LangGraph图、Streamlit UI。
它的作用
该系统将工作分解为 专业代理商 按顺序运行:
- 记录员代理人 → 以用户为主题,构建一个清晰的结构化大纲
- 文档编写代理 → 使用大纲编写完整的格式化文档
- 摘要代理 → 摘录5-8个关键要点
所有代理通过共享 MCP服务器 这暴露了受控工具(web搜索、web抓取、文件读/写)——代理无法直接访问互联网或文件系统。
建筑
User Input (Streamlit Chat)
↓
Note-Taker Agent ← LangGraph node: generates structured outline
↓ calls MCP tools: web_search, scrape_webpage
Doc-Writer Agent ← LangGraph node: writes full document from outline
↓ calls MCP tools: create_outline, write_document
Summary Extraction ← Extracts key points from final_content
↓
Streamlit UI ← Streams Outline → Full Document → Summary Points
↓
MCP Server (Tool Layer) ← web_search (Tavily) · scrape_webpage · file I/O
代理管道
flowchart TD
U([User Topic]) --> NTA[Note-Taker Agent]
NTA -->|outline_points| DWA[Doc-Writer Agent]
DWA -->|final_content + summary_points| UI[Streamlit UI]
subgraph MCP_SERVER["MCP Tool Server"]
T1[web_search - Tavily]
T2[scrape_webpage]
T3[create_outline - file write]
T4[write_document - file write]
T5[read / edit document]
end
NTA --> T1
NTA --> T2
NTA --> T3
DWA --> T4
DWA --> T5
技术栈
| 组件 | 技术 |
|---|---|
| 代理编排 | LangGraph(基于图的异步代理执行) |
| 工具服务器 | MCP(模型上下文协议) |
| 网络搜索 | Tavilly搜索API |
| LLM | 谷歌双子座(通过LangChain) |
| UI | 流媒体聊天界面 |
| 语言 | Python 3.10+(始终异步/等待) |
项目结构
Multiagent_MCP/
├── app.py # Streamlit UI: chat loop, agent invocation, message rendering
├── main.py # CLI entry point
├── agents/
│ ├── note_taker_agent.py # Agent 1: research + outline generation
│ └── doc_writer_agent.py # Agent 2: full document writing + summary extraction
├── graph/ # LangGraph graph definitions and state schemas
├── mcp_server/ # MCP tool server: web search, scraping, file I/O tools
├── client/ # MCP client for agent-to-tool-server communication
├── temp/ # Generated outputs: outline.txt, answer.txt
└── requirements.txt
设置和运行
# 1. Clone and install
git clone https://github.com/gnanadeep52/Multiagent_MCP.git
cd Multiagent_MCP
pip install -r requirements.txt
# 2. Create .env file
echo "GOOGLE_API_KEY=your_google_api_key" >> .env
echo "TAVILY_API_KEY=your_tavily_api_key" >> .env
# 3. Launch the Streamlit app
streamlit run app.py
在聊天框中键入任何主题。系统将返回: 大纲→ 完整文档→ 关键总结点.
关键设计决策
为什么选择MCP而不是直接工具调用?
MCP在代理(逻辑)和工具(功能)之间创建了一个干净的分离。代理不能直接访问web或文件系统——它们必须通过工具服务器。这反映了生产代理架构,其中工具访问是可审计和受控的。
为什么在简单的链上使用LangGraph?
LangGraph允许有状态、有条件的代理执行。每个节点(代理)向前传递结构化状态,使文档编写者能够使用记录者的确切大纲,而不是重新生成它。
为什么整个过程都是异步的?
这两个代理都异步运行,以避免在长时间的工具调用(网络搜索、抓取)期间阻塞Streamlit UI。这使界面在多步骤生成过程中保持响应。
示例输出
主题: “RAG在生产中是如何工作的?”
大纲:
-
- 什么是RAG及其重要性
-
- 核心组件:检索器、矢量存储、LLM
-
- 生产挑战:延迟、新鲜度、评估
-
- AWS基岩+OpenSearch生产模式
-
- 监测和漂移检测
完整文档: 完整的降价报告(约800字)
关键总结点: 6个简明要点