Billing implements reserve -> commit -> refund against bl_quota and bl_ledger with row-level locking and idempotency keys; the refund commits on its own transaction so a failed request cannot silently keep a user's quota. Task implements the unified task centre over the state machine. Identity issues and resolves users. Remaining domains are placeholders whose READMEs state what belongs there and what must not.
44 lines
1.7 KiB
Markdown
44 lines
1.7 KiB
Markdown
# `packages/agent/` — 穿搭 Agent
|
||
|
||
**职责**(架构 §4.1):会话管理、意图识别、上下文组装、生成编排。
|
||
**不负责**:知识检索实现(调 `packages/retrieval`)。
|
||
|
||
## 已实现
|
||
|
||
只有 `service.py` 里那条最小编排:配额预扣 → LLM 网关 → 成本落库 →
|
||
提交或退还。这是**垂直切片**,用来证明地基通了,不是 Agent 功能。
|
||
|
||
## 架构 §7.2 的完整链路(九步,目前只做了第 5 步)
|
||
|
||
| 步骤 | 状态 |
|
||
| --- | --- |
|
||
| ① 输入审核(TMS + 备案关键词库),fail-close | ❌ CR-06 |
|
||
| ② 意图识别(含越界:医疗、身材评判) | ❌ FR-AGT-02 |
|
||
| ③ 上下文组装(token 预算严格分配) | 部分:只有固定前缀 + 当前输入 |
|
||
| ④ 混合检索 | ❌ FR-AGT-04 |
|
||
| ⑤ LLM 生成(流式 SSE) | 部分:非流式 |
|
||
| ⑥ 生成后校验(禁忌违反 = 0、色值在板内) | ❌ FR-AGT-05 |
|
||
| ⑦ 输出审核 | ❌ CR-06 |
|
||
| ⑧ 落库 message + retrieval_trace + rule_hits + 成本 | 部分:只有成本 |
|
||
| ⑨ 异步偏好抽取 → 写 L2 记忆 | ❌ FR-MEM-03 |
|
||
|
||
表 `ag_conversation` / `ag_message` / `ag_feedback` 尚未创建。
|
||
|
||
## Token 预算(架构 §7.2,必须硬性限制)
|
||
|
||
| 部分 | 预算 |
|
||
| --- | --- |
|
||
| 系统提示词(固定前缀,放最前以命中缓存) | ≤ 800 |
|
||
| 画像摘要 | ≤ 500 |
|
||
| 会话摘要 | ≤ 400 |
|
||
| 检索知识 | ≤ 1500 |
|
||
| 用户当前输入 | ≤ 500 |
|
||
| **输入合计** | **≤ 3700** |
|
||
| 输出 | ≤ 800 |
|
||
|
||
超预算时**按优先级裁剪而不是报错**(FR-AGT-03)。
|
||
|
||
## Prompt 注入防护(NFR-SEC-04)
|
||
|
||
用户输入与系统提示词严格分区;输出侧校验;**禁止用户内容影响工具调用决策**。
|