Add the semantic rerank port, examples, and the command generator port (I2) #9

Merged
weichen merged 1 commits from feature/agent-stack-i2 into main 2026-10-07 10:57:50 +00:00
Owner

I2 增量一:语义重排端口、examples 与命令生成端口(分层与评测)

按 Documents 提案 2026-10-07-agent-stack-n1q1i1-plans.md §5 I2 落地库侧第一部分。「快慢分层」成形:规则(快、确定性)→ 语义(中、确定性宿主打分)→ L2 模型(慢)→ fallback 模型命令生成(兜底)。

改动

  • IntentSpec.Examples:示例句(semantic-router 借鉴;向量模型宿主注入,库不做 I/O)。
  • SemanticScorer 端口 + 歧义重排:歧义候选先经宿主打分按 examples 重排——过阈且唯一或分差 ≥ margin 才 matched(标注 refined_by=semantic);不达阈/打分错误/tie 才到 L2 分类器(分层顺序测试在案)。候选只从当前集合选,构造上不可能引入未知 ID。
  • CommandGenerator 端口 + fallback 兜底:规则与语义都未命中时调用宿主生成器;输出校验(start 的 ActionRef 必须在目录 spec ID 或 Handler 集合内、命令种类受限、槽位键在目标 spec 键集内)——幻觉一律 fail-closed 回 fallback;合法 start 合成 Top(携带生成槽位,标注 generated_by)。
  • bug 修复(自己的):生成端口给出的命令不再被 deriveCommands 覆盖。
  • CatalogTopK:priority 降序取 k(文档注明口径是 priority 而非语义相关度)。

验证

  • 全套件绿,新增 10 测:语义重排 matched/不达阈/tie/错误后 L2 接管,生成器合法/五类非法回退/错误回退,CatalogTopK 排序与 k=0 全量。

主任务:Dev 仓 feature/agent-stack-i2。

# I2 增量一:语义重排端口、examples 与命令生成端口(分层与评测) 按 Documents 提案 `2026-10-07-agent-stack-n1q1i1-plans.md` §5 I2 落地库侧第一部分。「快慢分层」成形:**规则(快、确定性)→ 语义(中、确定性宿主打分)→ L2 模型(慢)→ fallback 模型命令生成(兜底)**。 ## 改动 - **`IntentSpec.Examples`**:示例句(semantic-router 借鉴;向量模型宿主注入,库不做 I/O)。 - **`SemanticScorer` 端口 + 歧义重排**:歧义候选先经宿主打分按 examples 重排——过阈且唯一或分差 ≥ margin 才 matched(标注 `refined_by=semantic`);不达阈/打分错误/tie 才到 L2 分类器(分层顺序测试在案)。候选只从当前集合选,构造上不可能引入未知 ID。 - **`CommandGenerator` 端口 + fallback 兜底**:规则与语义都未命中时调用宿主生成器;输出校验(start 的 ActionRef 必须在目录 spec ID 或 Handler 集合内、命令种类受限、槽位键在目标 spec 键集内)——幻觉一律 fail-closed 回 fallback;合法 start 合成 Top(携带生成槽位,标注 generated_by)。 - **bug 修复(自己的)**:生成端口给出的命令不再被 `deriveCommands` 覆盖。 - **`CatalogTopK`**:priority 降序取 k(文档注明口径是 priority 而非语义相关度)。 ## 验证 - 全套件绿,新增 10 测:语义重排 matched/不达阈/tie/错误后 L2 接管,生成器合法/五类非法回退/错误回退,CatalogTopK 排序与 k=0 全量。 主任务:Dev 仓 `feature/agent-stack-i2`。
weichen added 1 commit 2026-10-07 10:57:04 +00:00
Add the semantic rerank port, examples, and the command generator port
ci / vet-and-test (pull_request) Successful in 15s
ci / docker-checkout-hostgateway (pull_request) Successful in 1s
89a43abf87
Why: I2 layering - between rules and the L2 classifier there is now
a deterministic host-scored semantic layer (rules then semantic then
model), and fallback can be rescued by a validated command
generator instead of going straight to the default channel.

Evidence: go vet clean; full suite ok, including ten new tests
(rerank resolve/below-threshold/tie/error-then-L2, generator
valid/invalid/error, catalog top-k).

Impact: IntentSpec gains Examples; Options gains Semantic (with
threshold), Generator; ambiguous candidates rerank through host
scores before L2; fallback validates generated commands
(action/slots/kind fail-closed) and synthesizes Top with slots;
generated commands are no longer overwritten by deriveCommands;
CatalogTopK by priority.

Refs: Documents proposal 2026-10-07-agent-stack-n1q1i1-plans.md I2
weichen merged commit fcf9ec4b2a into main 2026-10-07 10:57:50 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-Intent#9