Files
ecom-dmb/apps/agent/README.md
T

52 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Ecom DMB Agent(Python / FastAPI / LangGraph)
设计见 [DESIGN.md](./DESIGN.md)。
## 本地运行
```bash
cd apps/agent
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 默认 AGENT_ENV=dev,加载 .env.dev;也可 cp .env.dev .env 做本地覆盖
uvicorn api.main:app --reload --host 0.0.0.0 --port 8200
```
健康检查:`GET http://localhost:8200/health`
API 前缀:`/api/agent/...`(会话/聊天/记忆;与前端代理 `/api/agent` 对齐)
**模型 API 配置不在本服务**:浏览器走 Java `GET/PUT /api/company/agent-llm-providers`(凭证 + 协议 `apiStyle` + 多模型);Agent 经 Redis `agent:llm:rt:{companyId}:{providerId}:{model}` 或内部接口拉明文注入。按提供商 `api_style` 走 Chat Completions 或 Responses;Responses 同选型可续 `previous_response_id`(切换模型清链,失效则 Mongo rebuild,见 DESIGN §11)。
## 分环境配置
与后端 `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 运行时缓存 `agent:llm:rt:*` |
| `SERVER_BASE_URL` | Java 根地址,内部拉 `/api/internal/agent/llm-runtime` |
| `MCP_BASE_URL` / `MCP_BEARER_TOKEN` | 调 Server `/mcp`;Bearer 须与 Java `AGENT_MCP_TOKEN` / `ecom.agent.mcp.bearer-token` 一致,空则不加载 MCP 工具 |
| `LLM_FALLBACK_*` | 仅本地:公司未配置时的 OpenAI Compatible fallback |
| `CHAT_HISTORY_FETCH_LIMIT` | 从 Mongo 最多拉多少条再按 token 裁剪(默认 200) |
| `LLM_DEFAULT_CONTEXT_WINDOW` | 无法估计时的默认上下文(默认 128000) |
| `CONTEXT_RESERVE_OUTPUT_TOKENS` / `CONTEXT_RESERVE_TOOL_TOKENS` | 预留给生成与本轮工具 |
## 分层
`api` → `application` → `domain` ← `infrastructure`;编排在 `agent/`(工具装载 / 图预留)