代理初始化
这个仓库托管了一个连接到OpenAI模型的小型LangGraph代理。它揭示了:
- 快速API
/chat会话命令的端点。 - 代理调用最小MCP风格的时间服务器(也称为FastAPI)来检索当前时间。
- 与聊天端点通信的Streamlit UI。
先决条件
- Python 3.10+
OPENAI_API_KEY在您的环境中(用于代理的LLM调用)。
安装依赖项:
pip install -r requirements.txt运行MCP时间服务器
python time_mcp_server.py
# Serves on http://localhost:8001/time运行LangGraph代理HTTP服务器
export OPENAI_API_KEY=sk-...
python agent_server.py
# Serves chat on http://localhost:8000/chat可选环境变量:
MCP_TIME_SERVER_URL:覆盖MCP时间服务器基本URL(默认http://localhost:8001).OPENAI_MODEL:覆盖OpenAI模型名称(默认gpt-4o-mini).PORT:覆盖代理服务器端口(默认8000).
聊天负载示例:
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "What time is it?", "session_id": "demo"}'流媒体聊天界面
export CHAT_API_URL=http://localhost:8000/chat
streamlit run streamlit_app.pyUI显示对话和可用命令。会话ID将对话分开。
使用Docker Compose运行所有内容
构建并运行所有服务(MCP服务器、代理API、Streamlit UI):
export OPENAI_API_KEY=sk-...
docker compose up --build服务:
- MCP时间服务器已打开
http://localhost:8001/time - 上的代理API
http://localhost:8000/chat - 流线型UI打开
http://localhost:8501
可用命令
get_time:通过MCP时间服务器获取当前时间。list_commands:列出代理可以执行的命令。
