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

38 lines
1.6 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
cp .env.example .env # JWT_SECRET / Mongo / Redis(与 Server 同库) / SERVER_BASE_URL / MCP
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-settings`(MySQL 加密落库);Agent 经 Redis `agent:llm:rt:{companyId}` 或内部接口拉明文注入。
## 环境变量要点
| 变量 | 说明 |
|------|------|
| `JWT_SECRET` | 与 Java `jwt.secret` 一致 |
| `MONGO_URI` / `MONGO_DB` | Agent 独立库(sessions / messages / memory) |
| `REDIS_URL` | **与 Server 同 DB**,读 LLM 运行时缓存 |
| `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 |
| `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/`(工具装载 / 图预留)