Letta聊天机器人与Ollama和MCP集成
该项目提供了一个完整的基于Docker的设置,用于运行具有本地Ollama模型和MCP(模型上下文协议)服务器集成的Letta聊天机器人。
🚀 快速开始
先决条件
- 启用MCP工具包的Docker桌面
- Ollama在您的主机上运行
- Docker Compose
开始一切
# Start in production mode
./start-docker.sh
# Or start in development mode (with hot reloading)
./start-docker.sh dev🐳 建筑
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Letta ADE │ │ Docker MCP │ │ MCP Servers │
│ (Container) │◄──►│ Gateway │◄──►│ (Containers) │
│ Port: 8283 │ │ Port: 8080 │ │ - Wikipedia │
└─────────────────┘ └──────────────────┘ │ - Google Maps │
▲ │ - Playwright │
│ │ - Paper Search│
▼ └─────────────────┘
┌─────────────────┐
│ Chatbot UI │
│ (Container) │
│ Port: 3002 │
└─────────────────┘
▲
│
▼
┌─────────────────┐
│ Ollama │
│ (Host) │
│ Port: 11434 │
└─────────────────┘ 📋 服务
1.Letta服务器(容器化)
- 图像:
letta/letta:latest - 端口:
8283:8283 - 特性:
- 通过以下方式连接到主机Ollama host.docker.internal:11434 - 支持Docker模型运行器端点 - 用于网络搜索的Exa API集成
2.聊天机器人UI(容器化)
- 构建:Next.js应用程序
- 端口:
3001:3000 - 特性:
- 基于React的现代聊天界面 - 代理创建和管理 - 用户会话管理
3.Docker MCP网关(主机)
- 命令:
docker mcp gateway run --port 8080 --transport streaming - 端口:
8080 - 特性:
- 提供63个MCP工具 - 实时通信的流传输 - 访问谷歌地图、维基百科、剧作家和论文搜索
4.Ollama(主持人)
- 端口:
11434 - 模型:
- LLM gpt-oss:20b - 嵌入: nomic-embed-text
🔧 配置
环境变量
📖 看 设置.md 有关详细的设置说明
环境设置
- 复制环境模板文件:
cp .env.template .env
cp .env.docker.template .env.docker- 编辑
.env.docker使用您的实际API密钥:
# Letta Server Configuration
LETTA_API_KEY=your-letta-api-key-here
OLLAMA_BASE_URL=http://host.docker.internal:11434
MODEL_RUNNER_ENDPOINT=http://model-runner.docker.internal/engines/v1
EXA_API_KEY=your-exa-api-key-here # Optional for web search
# Chatbot UI Configuration
LETTA_BASE_URL=http://letta-server:8283
USE_COOKIE_BASED_AUTHENTICATION=true
NEXT_PUBLIC_CREATE_AGENTS_FROM_UI=true
# MCP Gateway Configuration (Optional)
GOOGLE_MAPS_API_KEY=your-google-maps-api-key-here
GOOGLE_MAPS_CX=your-google-maps-cx-here注: 永不承诺.env或.env.docker文件到版本控制。他们已经进去了.gitignore.
代理配置
默认代理设置(letta-chatbot-web/default-agent.json)
{
"DEFAULT_MEMORY_BLOCKS": [
{
"label": "human",
"value": "The human's name is [Your Name]"
},
{
"label": "persona",
"value": "You are a helpful AI assistant with access to web search and memory tools. You can help with research, answer questions, and remember information across conversations."
}
],
"DEFAULT_LLM": "ollama/gpt-oss:20b",
"DEFAULT_EMBEDDING": "ollama/nomic-embed-text"
}🌐 接入点
所有服务运行后,您可以访问:
- Letta ADE: http://localhost:8283
- 聊天机器人用户界面: http://localhost:3001
- MCP网关: http://localhost:8080/mcp
- 奥拉玛: http://localhost:11434
🔌 MCP集成
可用MCP工具(共63个)
- 谷歌地图:8个定位服务工具
- 剧作家:21个网络自动化工具
- 维基百科:11个工具+9个资源模板
- 论文搜索23种学术研究工具
将MCP网关连接到Letta ADE
- Letta ADE开放时间:http://localhost:8283
- 转到MCP服务器配置
- 使用以下命令添加新服务器:
- 服务器类型: Streamable HTTP - 服务器名称: docker_mcp_gateway - 服务器URL: http://host.docker.internal:8080/mcp
🛠️ 发展
发展模式
./start-docker.sh dev这将以热重新加载的方式启动处于开发模式的聊天机器人。
查看日志
# Production mode
docker-compose logs -f
# Development mode
docker-compose -f docker-compose.dev.yml logs -f停止服务
# Production mode
docker-compose down --volumes --remove-orphans
# Development mode
docker-compose -f docker-compose.dev.yml down --volumes --remove-orphans📁 项目结构
├── docker-compose.yml # Production Docker Compose
├── docker-compose.dev.yml # Development Docker Compose
├── start-docker.sh # Startup script
├── config.yaml # MCP Gateway configuration
├── registry.yaml # MCP server registry
├── tools.yaml # MCP tools configuration
├── letta-chatbot-web/ # Next.js chatbot application
│ ├── Dockerfile # Production Dockerfile
│ ├── Dockerfile.dev # Development Dockerfile
│ ├── default-agent.json # Default agent configuration
│ ├── .env.local # Environment variables
│ └── src/ # Source code
└── README.md # This file🚨 故障排除
常见问题
- 端口冲突
- 确保端口3002、8080、8283和11434可用 - 使用 lsof -i : 检查端口使用情况
- Ollama连接
- 验证Ollama是否在主机上运行: curl http://localhost:11434/api/tags - 检查模型是否已加载: ollama list
- MCP网关连接
- 确保MCP网关正在运行: docker mcp gateway run --port 8080 --transport streaming - 测试连接: curl http://localhost:8080/mcp
- Docker网络
- 使用 host.docker.internal 用于容器到主机的通信 - 验证Docker桌面网络是否已启用
重置所有内容
# Stop and remove all containers, networks, and volumes
docker-compose down --volumes --remove-orphans
docker-compose -f docker-compose.dev.yml down --volumes --remove-orphans
# Remove any orphaned containers
docker container prune -f
docker network prune -f
docker volume prune -f🔄 更新
更新Letta
docker-compose pull letta-server
docker-compose up -d letta-server更新聊天机器人
# Development
docker-compose -f docker-compose.dev.yml build chatbot
docker-compose -f docker-compose.dev.yml up -d chatbot
# Production
docker-compose build chatbot
docker-compose up -d chatbot📚 额外资源
🤝 贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 测试开发和生产模式
- 提交拉取请求
📄 许可证
该项目根据MIT许可证获得许可。
