Add AgentSessionService and refactor agent routes

Move session-related responsibilities into a new application-layer AgentSessionService (and AgentSessionFeedbackResult dataclass), provide a bootstrap factory (get_agent_session_service), and update agent API routes to call the service instead of accessing ConversationStore directly. Routes now translate ValueError into 404 responses and use service methods for get/list/history/delete/feedback. Also update package exports and docs/READMEs to declare the backend architecture authority, enforce api -> application -> domain ports -> infrastructure boundaries, and call out legacy services/workflows as migration-only. These changes centralize session logic in the application layer and tighten architecture guidance for future backend work.
This commit is contained in:
ash66
2026-05-22 09:50:30 +08:00
parent 37f7a60b0a
commit 091a02c522
8 changed files with 223 additions and 33 deletions

View File

@@ -2,6 +2,13 @@
`backend` 是当前正式使用的 FastAPI 后端目录,入口为 `app.main:app`
## 架构约束入口
- Backend authoritative architecture 文档:`docs/architecture/backend-project-architecture.md`
- Backend migration RFC`docs/rfc/backend-api-parsing-embedding-migration-requirements.md`
- 后续 backend 新增功能和重构默认遵守:`api -> application -> domain ports -> infrastructure`
- `backend/app/services/*``backend/app/workflows/*` 为迁移期 legacy 目录,除迁移或兼容修复外,不应新增业务编排逻辑。
## 启动
```bash
@@ -34,10 +41,15 @@ PYTHONPATH=backend uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
```text
backend/
├── app/
│ ├── api/ # FastAPI 路由与模型
│ ├── config/ # 配置与日志
│ ├── services/ # 文档处理、LLM、RAG、存储
── workers/ # 任务相关代码
│ ├── api/ # FastAPI 路由与 transport models
│ ├── application/ # 用例编排层
│ ├── domain/ # 核心业务模型与稳定端口
── infrastructure/ # 外部系统适配器
│ ├── shared/ # composition root 与横切支撑
│ ├── config/ # 配置与日志
│ ├── services/ # legacy façade / 兼容入口
│ ├── workflows/ # legacy workflow 入口
│ └── workers/ # 任务相关代码
├── .env.example
├── requirements.txt
└── main.py
@@ -46,4 +58,13 @@ backend/
## 说明
- 路由前缀保持为 `/api/v1`,以兼容当前前端。
- `backend/app/api/routes/docs.py``rag.py``compliance.py``status.py` 仍保留在仓库中,但不再作为主路由入口
- 当前主业务链路入口是 `documents``knowledge``agent`
- `compliance.py` 当前仍被挂载,但尚未满足目标架构约束;在迁移前不应继续扩展业务编排。
- `docs.py``rag.py` 为遗留/非主入口,不应继续扩展。
## 开发约束
- backend 开发前先阅读 `docs/architecture/backend-project-architecture.md`
- 新增业务能力默认落在 `application` 层,由 `api` 调用,不要直接写进 route。
- route 不应直接访问 MinIO、Milvus、Parser SDK、LLM SDK 或 `ConversationStore`
- `backend/app/shared/bootstrap.py` 是当前 composition root依赖装配优先收口到这里。