该项目使用LangGraph和模型上下文协议(MCP)实现了一个小型编码代理团队。代理通过MCP服务器提供工具和能力,并通过统一网关进行访问。
该代理团队的整体目标是根据需求和代码上下文创建多个功能实现;人类操作员可以选择他们喜欢的方法并继续进行,而放弃其他方法。
该项目起源于2024年11月12日在纽约举行的Anthropic MCP黑客马拉松,并已发展成为独立项目。
系统由三个主要组件组成:
MCP网关服务器:一个服务器,它:
MCP服务器:提供特定能力的单个服务器:
编码代理:有三个代理协作完成编码任务:
# 安装代理包
pip install -e .
# 安装网关包
cd gateway
pip install -e .
cd ..
代理支持通过环境变量配置多个LLM提供商:
# LLM配置 - 支持多个提供商:
LLM_MODEL=provider/model-name
# 支持的提供商和示例模型:
# - Anthropic: anthropic/claude-3-5-sonnet-20240620
# - OpenAI: openai/gpt-4
# - OpenRouter: openrouter/openai/gpt-4o-mini
# - Google: google/gemini-1.5-pro
# 不同提供商的API密钥
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
OPENROUTER_API_KEY=your_openrouter_api_key
GOOGLE_API_KEY=your_google_api_key
# OpenRouter配置(如果使用OpenRouter)
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
网关服务器通过gateway/config.json进行配置。默认情况下,它启动两个MCP服务器:
{
"mcp": {
"servers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/directory"
]
},
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
}
可以从官方MCP服务器存储库添加更多服务器。
cd gateway
python -m mcp_gateway.server
服务器默认将在端口8808上启动。
代理连接到网关的配置位于langgraph.json中:
{
"dependencies": ["."],
"graphs": {
"agent": "./src/react_agent/graph.py:graph"
},
"env": ".env",
"mcp": {
"gateway_url": "http://localhost:8808"
}
}
在LangGraph Studio中打开文件夹!代理将自动:
代理可以访问来自两个MCP服务器的工具:
read_file:读取文件内容write_file:创建或更新文件list_directory:列出目录内容search_files:查找匹配模式的文件create_entities:向知识图谱添加实体create_relations:链接实体search_nodes:查询知识图谱gateway/config.jsonsrc/react_agent/prompts.py中的系统提示src/react_agent/graph.py中的代理推理本项目采用MIT许可证 - 详情见LICENSE文件。