基于 LangChain 和 FastAPI 的多智能体管理系统,支持 MCP (Model Context Protocol) 和多种 LLM 提供商。
- 多智能体管理: 支持创建和管理多个独立的智能体实例
- 独立配置: 每个智能体可配置独立的 LLM、系统提示词和参数
- 智能体路由: 通过
agent_id路由到不同的智能体 - 生命周期管理: 启动、停止、创建、删除智能体
- 智能对话: 集成 LangChain Agent,支持工具调用和复杂推理
- MCP 支持: 通过 Model Context Protocol 集成外部工具和服务
- MCP Inspector: 基于 Vue3 的可视化 MCP 服务器测试工具
- 多模型支持: 兼容 OpenAI API 格式的 LLM 提供商
- 流式响应: 支持实时流式输出
- RESTful API: 简洁易用的 HTTP 接口
- 异步架构: 基于 FastAPI 的高性能异步处理
- 智能体管理界面: 创建、编辑、启动、停止智能体
- 对话测试界面: 与不同智能体进行实时对话
- MCP Inspector: 可视化 MCP 工具测试
- Python 3.12+
- Conda (推荐) 或 venv
git clone https://github.com/wishfay/agentService.git
cd agentServiceconda create -n agent python=3.12 -y
conda activate agent使用 pip:
pip install -r requirements.txt或使用 conda:
conda env update -f environment.ymlcp .env.example .env编辑 .env 文件,配置你的 LLM 提供商:
OPENAI_API_BASE=https://open.bigmodel.cn/api/paas/v4/
OPENAI_API_KEY=your-zhipuai-api-key
MODEL_NAME=glm-4-flashOPENAI_API_BASE=http://localhost:11434/v1
OPENAI_API_KEY=sk-dummy
MODEL_NAME=llama3.2OPENAI_API_BASE=https://api.openai.com/v1
OPENAI_API_KEY=your-openai-api-key
MODEL_NAME=gpt-4在 .env 文件中添加 MCP 服务器配置:
MCP_SERVERS__weather__transport=http
MCP_SERVERS__weather__url=http://localhost:8000/mcp
MCP_SERVERS__database__transport=stdio
MCP_SERVERS__database__command=python
MCP_SERVERS__database__args=["/path/to/mcp_server.py"]PYTHONPATH=/path/to/agentService python -m app.mainchmod +x scripts/start.sh
./scripts/start.sh服务将在 http://0.0.0.0:8000 启动。
nohup python -m app.main > /tmp/agent_service.log 2>&1 &
echo $! > /tmp/agent_service.pidkill $(cat /tmp/agent_service.pid)curl http://localhost:8080/agents/响应:
{
"agents": [
{
"agent_id": "default",
"name": "通用助手",
"description": "默认的通用对话助手",
"status": "running",
"message_count": 0,
"created_at": "2026-01-28T23:18:17.165040",
"last_used": null
}
]
}curl -X POST http://localhost:8080/agents/coder/startcurl -X POST http://localhost:8080/agents/coder/stopcurl -X POST http://localhost:8080/agents/ \
-H "Content-Type: application/json" \
-d '{
"agent_id": "translator",
"name": "翻译助手",
"description": "专业翻译助手",
"llm": {
"model": "glm-4-flash",
"temperature": 0.3
},
"system_prompt": "你是一个专业的翻译助手。",
"runtime": {
"auto_start": false
}
}'curl -X DELETE http://localhost:8080/agents/translatorcurl -X POST http://localhost:8080/chat/ \
-H "Content-Type: application/json" \
-d '{
"message": "你好,请介绍一下你自己",
"agent_id": "coder"
}'响应:
{
"response": "我是一个专业的编程助手...",
"session_id": "default",
"agent_id": "coder",
"tool_calls": []
}curl -X POST http://localhost:8080/chat/ \
-H "Content-Type: application/json" \
-d '{"message": "你好"}'curl http://localhost:8080/healthcurl http://localhost:8000/tools/import requests
# 发送消息
response = requests.post(
"http://localhost:8000/chat/",
json={"message": "法国的首都是什么?"}
)
data = response.json()
print(data["response"])import requests
import json
response = requests.post(
"http://localhost:8000/chat/stream/",
json={"message": "介绍一下人工智能"},
stream=True
)
for line in response.iter_lines():
if line:
data = json.loads(line)
if data["type"] == "content":
print(data["content"], end="", flush=True)python -m uvicorn app.main:app --host 0.0.0.0 --port 8080cd web-ui
npm install
npm run dev打开浏览器访问:http://localhost:3000
-
智能体管理: 创建、编辑、启动、停止和删除智能体
- 可视化配置 LLM 参数
- 自定义系统提示词
- 查看智能体运行状态和统计信息
-
对话测试: 与不同智能体实时对话
- 选择运行中的智能体
- 查看对话历史
- 实时响应
-
MCP Inspector: 可视化 MCP 工具测试
- 连接管理: 支持 HTTP、Stdio、SSE 传输方式
- Resources: 浏览和读取服务器资源
- Prompts: 测试提示模板生成
- Tools: 调用工具并查看执行结果
- Notifications: 实时查看服务器日志
智能体配置文件存放在 agents/ 目录:
agents/
├── default.yaml # 默认通用助手
├── coder.yaml # 编程助手
└── custom.yaml # 自定义智能体配置示例:
agent_id: my-agent
name: "我的智能体"
description: "智能体描述"
llm:
model: "glm-4-flash"
temperature: 0.7
# 可选:覆盖全局配置
# base_url: "https://api.example.com/v1"
# api_key: "your-api-key"
system_prompt: |
你是一个有帮助的助手。
runtime:
auto_start: true # 服务启动时自动启动agentService/
├── agents/ # 智能体配置文件目录
│ ├── default.yaml # 默认智能体配置
│ └── coder.yaml # 编程助手配置
├── api/ # API 路由
│ ├── routes/
│ │ ├── chat.py # 聊天接口(支持多智能体)
│ │ ├── agents.py # 智能体管理接口
│ │ ├── health.py # 健康检查
│ │ └── tools.py # 工具管理
├── app/ # FastAPI 应用
│ ├── config.py # 配置管理
│ ├── main.py # 应用入口
│ └── schemas.py # Pydantic 模型
├── core/ # 核心逻辑
│ ├── agent.py # 单智能体服务(向后兼容)
│ ├── agent_instance.py # 智能体实例类
│ ├── agent_manager.py # 多智能体管理器
│ ├── llm.py # LLM 管理
│ └── mcp.py # MCP 客户端
├── inspector/ # MCP Inspector 后端
│ ├── manager.py # Inspector 管理器
│ └── routes.py # Inspector API 路由
├── web-ui/ # Web UI (Vue3)
│ ├── src/
│ │ ├── api/ # API 客户端
│ │ │ ├── agents.ts # 智能体 API
│ │ │ ├── chat.ts # 聊天 API
│ │ │ └── inspector.ts
│ │ ├── components/ # Vue 组件
│ │ │ ├── AgentCard.vue
│ │ │ ├── AgentConfigDialog.vue
│ │ │ └── ...
│ │ ├── stores/ # Pinia 状态管理
│ │ │ ├── agents.ts
│ │ │ ├── chat.ts
│ │ │ └── inspector.ts
│ │ ├── types/ # TypeScript 类型
│ │ │ ├── agent.ts
│ │ │ └── inspector.ts
│ │ └── views/ # 页面组件
│ │ ├── AgentsView.vue
│ │ ├── ChatView.vue
│ │ └── ...
│ └── package.json
├── deployment/ # 部署配置
│ ├── agent-service.service
│ ├── supervisor.conf
│ └── README.md
├── tests/ # 测试文件
├── scripts/ # 脚本
├── .env.example # 环境变量示例
├── requirements.txt # Python 依赖
├── environment.yml # Conda 环境配置
└── README.md
pytest tests/项目使用 Python 类型注解和异步编程最佳实践。
后端:
- Web 框架: FastAPI 0.128+
- Agent 框架: LangChain 1.2+
- LLM 集成: langchain-openai
- MCP 支持: langchain-mcp-adapters
- 数据验证: Pydantic 2.10+
- ASGI 服务器: Uvicorn
前端 (Inspector UI):
- 框架: Vue 3 + TypeScript
- 构建工具: Vite 5+
- UI 组件: Element Plus
- 状态管理: Pinia
- HTTP 客户端: Axios
欢迎提交 Issue 和 Pull Request!
MIT License
- GitHub: @wishfay
- Email: wishfay@nudt.edu.cn