mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 14:29:19 +08:00
feat: 重构 Agent 目录为 api/agent/infrastructure 分层并更新启动入口
This commit is contained in:
+23
-19
@@ -79,25 +79,25 @@
|
||||
|
||||
```text
|
||||
apps/agent/
|
||||
app/ # 接口层:HTTP / DTO / 鉴权依赖
|
||||
api/ # 接口层:HTTP / DTO / 鉴权依赖
|
||||
application/ # 应用层:用例编排(发消息、列会话、恢复上下文)
|
||||
domain/ # 领域层:Session / Message / Memory 模型与规则(无框架)
|
||||
infrastructure/ # 基础设施:Mongo、LLM、MCP client、JWT 校验
|
||||
graphs/ # LangGraph 图定义(可视为 application 的特殊编排)
|
||||
agent/ # 编排层:工具装载、运行态、LangGraph(预留)
|
||||
infrastructure/ # 基础设施:Mongo/Redis、LLM、MCP、JWT
|
||||
config/ # 配置
|
||||
```
|
||||
|
||||
依赖方向:**app → application → domain ← infrastructure**;`graphs` 只依赖 application/domain 端口,MCP/LLM 走 infrastructure 适配器。
|
||||
依赖方向:**api → application → domain ← infrastructure**;`application` 经 `agent` 装载工具;`agent` 只依赖 domain/config 与 infrastructure 适配器,不写 Mongo。
|
||||
|
||||
### 3.1 分层职责
|
||||
|
||||
| 层 | 包 | 职责 | 禁止 |
|
||||
|----|-----|------|------|
|
||||
| 接口 | `app` | 路由、请求/响应模型、依赖注入、鉴权提取 | 拼 prompt、直连 Mongo、调 MCP SDK |
|
||||
| 接口 | `api` | 路由、请求/响应模型、依赖注入、鉴权提取 | 拼 prompt、直连 Mongo、调 MCP SDK |
|
||||
| 应用 | `application` | 「用户发一条消息」「新建会话」「加载记忆」用例、事务边界(逻辑) | 框架注解泄漏到 domain |
|
||||
| 领域 | `domain` | 会话状态机、记忆条目规则、隔离键不变量 | HTTP、Motor、LangChain 类型 |
|
||||
| 基础设施 | `infrastructure` | Mongo 仓库、MCP、ChatModel、JWT JWKS/本地校验 | 业务用例 if/else 堆砌 |
|
||||
| 图 | `graphs` | LangGraph StateGraph、节点、边 | 写 Mongo 细节(经 repository 端口) |
|
||||
| 编排 | `agent` | 工具装载、Turn State、LangGraph 图(预留) | 写 Mongo 细节、HTTP 路由 |
|
||||
| 基础设施 | `infrastructure` | Mongo/Redis 仓库、MCP、ChatModel、JWT 校验 | 业务用例 if/else 堆砌 |
|
||||
|
||||
---
|
||||
|
||||
@@ -257,12 +257,13 @@ api/agent/ # 调 Agent 服务,非调 Java /api
|
||||
|
||||
```text
|
||||
apps/agent/
|
||||
pyproject.toml / requirements.txt
|
||||
requirements.txt
|
||||
README.md
|
||||
DESIGN.md # 本文
|
||||
app/
|
||||
api/
|
||||
main.py
|
||||
deps.py # 当前用户
|
||||
deps.py # 当前用户 / 用例组装
|
||||
response.py
|
||||
routers/sessions.py
|
||||
routers/chat.py
|
||||
routers/memories.py
|
||||
@@ -270,19 +271,22 @@ apps/agent/
|
||||
session_service.py
|
||||
chat_service.py
|
||||
memory_service.py
|
||||
llm_settings_service.py # 现为 LlmRuntimeService:读 Redis/Server
|
||||
llm_settings_service.py # LlmRuntimeService:读 Redis/Server
|
||||
domain/
|
||||
models.py
|
||||
ports.py
|
||||
agent/
|
||||
runtime.py # 本轮工具装载入口
|
||||
state.py # Turn State(图扩展点)
|
||||
tools/builtin.py
|
||||
graphs/ # LangGraph 预留
|
||||
infrastructure/
|
||||
mongo/
|
||||
redis_cache.py
|
||||
mcp_client.py
|
||||
server_llm_gateway.py
|
||||
jwt_auth.py
|
||||
llm_factory.py
|
||||
graphs/
|
||||
assistant_graph.py
|
||||
auth/jwt.py
|
||||
llm/factory.py
|
||||
llm/gateway.py
|
||||
mcp/client.py
|
||||
persistence/mongo/
|
||||
persistence/redis/
|
||||
config/settings.py
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user