feat: 将 Agent 接入运行时镜像挂载式部署

This commit is contained in:
2026-09-20 17:34:25 +08:00
parent 5393ad3423
commit 67c2d58c32
20 changed files with 499 additions and 40 deletions
+16 -2
View File
@@ -9,7 +9,7 @@ cd apps/agent
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # JWT_SECRET / Mongo / Redis(与 Server 同库) / SERVER_BASE_URL / MCP
# 默认 AGENT_ENV=dev,加载 .env.dev;也可 cp .env.dev .env 做本地覆盖
uvicorn api.main:app --reload --host 0.0.0.0 --port 8200
```
@@ -18,13 +18,27 @@ API 前缀:`/api/agent/...`(会话/聊天/记忆;与前端代理 `/api/age
**模型 API 配置不在本服务**:浏览器走 Java `GET/PUT /api/company/agent-llm-settings`(凭证 + 多模型勾选;`POST .../probe-models` 拉目录);Agent 经 Redis `agent:llm:rt:{companyId}` 或内部接口拉**默认模型**明文注入。
## 分环境配置
与后端 `application-{profile}.yml` 对应,由 `AGENT_ENV` 选择文件:
| AGENT_ENV | 配置文件 | 端口 | Redis DB(对齐 Server) |
|-----------|----------|------|-------------------------|
| `dev`(默认) | `.env.dev` | 8200 | 2 |
| `test` | `.env.test` | 8201 | 3 |
| `pre` | `.env.pre` | 8202 | 0 |
| `prod` | `.env.prod` | 8203 | 0 |
若存在 gitignore 的 `.env`,仅在 `AGENT_ENV=dev` 时覆盖同名变量。部署时 compose 注入 `AGENT_ENV=test|pre|prod`。
## 环境变量要点
| 变量 | 说明 |
|------|------|
| `AGENT_ENV` | 选择 `.env.{env}` |
| `JWT_SECRET` | 与 Java `jwt.secret` 一致 |
| `MONGO_URI` / `MONGO_DB` | Agent 独立库(sessions / messages / memory) |
| `REDIS_URL` | **与 Server 同 DB**,读 LLM 运行时缓存 |
| `REDIS_URL` | **与同环境 Server 同 DB**,读 LLM 运行时缓存 `agent:llm:rt:*` |
| `SERVER_BASE_URL` | Java 根地址,内部拉 `/api/internal/agent/llm-runtime` |
| `MCP_BASE_URL` / `MCP_BEARER_TOKEN` | 调 Server `/mcp`,并带 `X-Agent-Company-Id` / `X-Agent-User-Id` |
| `LLM_FALLBACK_*` | 仅本地:公司未配置时的 OpenAI Compatible fallback |