Files
meida_backend/packages/agent/README.md
T
xsl 7bcbb8d40b
CI / lint / typecheck / import-linter / tests / secrets (push) Canceled after 0s
feat(agent,report): 会话持久化与画像注入、报告反馈与预约留资——PM/开发双Agent迭代1-3
- agent: ag_conversation/ag_message 表(迁移0007),上下文组装注入最近报告画像摘要
  (report.profile.latest_profile_summary 经 apps 层闭包注入,同层不互调),历史带最近
  AGENT_HISTORY_TURNS=10 轮;POST/GET /agent/conversations 与消息历史接口
- agent 修复:ChatRequest.conversation_id 改 str(雪花ID超2^53,JS Number丢精度);
  _build_context 挪进 reserve commit 后同一 try,异常走 refund 兜底
- report: rp_feedback(维度反馈 upsert,认同率/修正率 SQL 可算,T-P3-21 最小版——
  L1 记忆未建,不回写结论)+ rp_reservation(预约留资幂等,T-P3-22,预约率口径
  行数/full_report.card_view 去重曝光,门槛≥8%),迁移0008
- 测试:全量 606 passed;ruff/mypy/lint-imports 全绿;E2E 真实 deepseek-v4-flash 验证
  画像注入与历史携带
2026-09-11 21:50:58 +08:00

45 lines
2.0 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.
# `packages/agent/` — 穿搭 Agent
**职责**(架构 §4.1):会话管理、意图识别、上下文组装、生成编排。
**不负责**:知识检索实现(调 `packages/retrieval`)。
## 已实现
只有 `service.py` 里那条最小编排:配额预扣 → LLM 网关 → 成本落库 →
提交或退还。这是**垂直切片**,用来证明地基通了,不是 Agent 功能。
## 架构 §7.2 的完整链路(九步,目前只做了第 5 步)
| 步骤 | 状态 |
| --- | --- |
| ① 输入审核(TMS + 备案关键词库),fail-close | ❌ CR-06 |
| ② 意图识别(含越界:医疗、身材评判) | ❌ FR-AGT-02 |
| ③ 上下文组装(token 预算严格分配) | 部分:画像摘要 + 最近 N 轮历史(`AGENT_HISTORY_TURNS`,默认 10);检索知识与会话摘要未做 |
| ④ 混合检索 | ❌ FR-AGT-04 |
| ⑤ LLM 生成(流式 SSE) | 部分:非流式 |
| ⑥ 生成后校验(禁忌违反 = 0、色值在板内) | ❌ FR-AGT-05 |
| ⑦ 输出审核 | ❌ CR-06 |
| ⑧ 落库 message + retrieval_trace + rule_hits + 成本 | 部分:ag_message 双行 + 成本已实现;retrieval_trace / rule_hits 列已建、待步骤④填充 |
表 `ag_conversation` / `ag_message` 已建(迁移 0007,T-P4-01);`ag_feedback` 尚未创建。
画像摘要经 `report.profile.latest_profile_summary` 由 apps 层闭包注入
(agent 与 report 同层,不允许直接互调)。
## Token 预算(架构 §7.2,必须硬性限制)
| 部分 | 预算 |
| --- | --- |
| 系统提示词(固定前缀,放最前以命中缓存) | ≤ 800 |
| 画像摘要 | ≤ 500 |
| 会话摘要 | ≤ 400 |
| 检索知识 | ≤ 1500 |
| 用户当前输入 | ≤ 500 |
| **输入合计** | **≤ 3700** |
| 输出 | ≤ 800 |
超预算时**按优先级裁剪而不是报错**(FR-AGT-03)。
## Prompt 注入防护(NFR-SEC-04)
用户输入与系统提示词严格分区;输出侧校验;**禁止用户内容影响工具调用决策**。