UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

40 lines (39 loc) • 2.23 kB
/** * llmClassifier — an {@link IntentScorer} that asks a model which declared * intent the new message is (SG-C tier 2). ONE call per turn, off the hot * loop, in the RouteTurn stage — never inside the ReAct iterations. * * **Constrained enum, never free text.** The pick runs through * {@link constrainedEnumPick} (extracted from this module in 9.19.0 so the * tier-3 decider shares the same discipline): when the provider declares * forced-tool support for that model it rides a forced synthetic tool whose single * argument is `enum: [...candidateIds, 'none']` (the same machinery the * `'tool-forced'` output strategy uses); on any other provider it is a * strict single-line parse validated against the enum, ONE structured * re-ask, then `'none'`. An off-enum answer is a parse failure, not a route * — this scorer can never emit an id it wasn't given. * * Output maps to scores the framework can judge: picked id → 1, others → 0; * `'none'` → all 0. `floor: 0` (so `'none'` is honestly "unmatched") and * `categorical: true` (one id or none — a pick is decisive by construction, * never diluted by the near-tie margin; see `routingPolicy.ts`). * * One of the two injection-engine scorer modules that import * `provider-contract/types` (the other is `constrainedEnumPick`, its machinery) — * kept out of `entryScorer.ts` so the keyword/embedding paths stay * adapter-free. */ import type { LLMProvider } from '../provider-contract/types.js'; import type { IntentScorer } from './intentScorer.js'; export interface LlmClassifierOptions { /** Model to classify with. Name it for any real provider — left unset, the * request carries an empty model id, which only the mock tolerates. */ readonly model?: string; /** Recent-turns window (count of prior conversational turns shown to the * classifier). Absent = current message only. */ readonly window?: number; /** Prompt budget: examples listed per intent. Default 5. */ readonly maxExamplesPerIntent?: number; } /** Build the classifier. See the module header for the enum discipline. */ export declare function llmClassifier(provider: LLMProvider, options?: LlmClassifierOptions): IntentScorer;