Files
Agent-Intent/intent/classifier.go
weichenandCursor 3130190acb
ci / vet-and-test (pull_request) Failing after 2s
ci / docker-checkout-hostgateway (pull_request) Successful in 2s
Reject invalid classifier refinements and scope slot validators
Why: Refine could swap handlers or emit out-of-range scores, Ambiguous tops skipped slot extraction, and the process-global validator map coupled independent registries.
Evidence: GOWORK=off go vet ./... && go test -count=1 ./... && go test -race ./... passed, including TestRecognizeClassifierRejectsBadRefinement, TestRecognizeClassifierRebuildsTamperedHandler, TestRecognizeClassifierRefinedTopGetsSlots, and TestScopedSlotValidatorsDoNotInterfere. error-code-system and logging-system advanced to a3ee67b and 49b5d8b (docs-only).
Impact: illegal Refine results stay Ambiguous; a resolved Top is slotted; Options.SlotValidators wins over the deprecated global table.
Refs: I1, I2, I6
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-03 00:47:16 +00:00

16 lines
873 B
Go

package intent
import "context"
// Classifier 是可选的 L2 重打分扩展点,典型由宿主用其 LLM 客户端实现。
// 只在规则裁决为 Ambiguous 时被调用;实现自担延迟与成本。
// 返回错误时识别保持 Ambiguous,不会使 Recognize 失败(识别确定性不受实现影响)。
// 宿主应保证 Refine 幂等且无副作用:同样的输入与候选应得到同样的重排结果。
type Classifier interface {
// Refine 对候选重打分/重排。返回的 ID 集合必须与输入完全相同且不能重复;
// Confidence 必须是有限值并落在 [0,1],越界会被拒绝而不是截断。
// 除 Confidence 以外的字段会被按 ID 从原候选重建,改写不生效。
// 校验失败时识别保持 Ambiguous。
Refine(ctx context.Context, input string, candidates []Candidate) ([]Candidate, error)
}