agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
61 lines (60 loc) • 3.22 kB
TypeScript
/**
* scoreLexicalInfluence — the DETERMINISTIC, zero-dependency influence
* scorer: the same four-signal FDL frame as `scoreInfluence`
* (fa / avg / persist / depth, adaptive weights, composite, stable desc
* sort), with ONE substitution — cosine-over-embeddings becomes set-cosine
* over word tokens. Nothing here embeds; nothing here calls the network.
*
* ## Honest claim (same discipline as `scoreInfluence`, one rung blinder)
*
* Every returned `InfluenceScore.signals` / `weights` / `adapted` is
* GENUINELY computed — nothing is fabricated. But the FA signal here means
* "shares words with the final answer", NOT "semantically close" and NOT
* "caused". It is cheaper and BLINDER than `'semantic-alignment'`: a
* paraphrase (different words, same meaning) is a miss. The claim-ladder
* guarantee is unchanged — a scorer only reorders suspects; ablation alone
* convicts. So the worst a lexical ranking does is confirm slower, never
* wrong.
*
* English / ASCII by construction (the tokenizer splits on non-alphanumerics
* and folds a single trailing plural `s`) — use `'semantic-alignment'` for
* other languages.
*/
import type { Embedder, EvidenceInput, InfluenceScore, InfluenceWeights } from './types.js';
/**
* Args for `scoreLexicalInfluence` — a SUPERTYPE of `ScoreInfluenceArgs`:
* everything the embedding scorer takes, with `embedder` optional and NEVER
* called. That supertype relationship is what makes `scoreLexicalInfluence`
* assignable to `InfluenceScorer` (parameter contravariance) while remaining
* honestly callable with no embedder at all.
*/
export interface ScoreLexicalInfluenceArgs {
/** Evidence items (tool results / context sources) with ancestors. */
readonly evidence: readonly EvidenceInput[];
/** The final answer text the evidence is scored against. */
readonly finalAnswerText: string;
/** Accepted only for `InfluenceScorer` compatibility. IGNORED — this scorer never embeds. */
readonly embedder?: Embedder;
/** Composite weights (same frame as `scoreInfluence`). Default 0.40/0.30/0.20/0.10. */
readonly weights?: InfluenceWeights;
/** PERSIST threshold on the LEXICAL overlap scale (set-cosine, 0..1). Default 0.30. */
readonly persistenceThreshold?: number;
/** Accepted for compatibility; unused (nothing async to abort — resolves immediately). */
readonly signal?: AbortSignal;
}
/**
* Score every evidence item on the four FDL signals — the LEXICAL kernel
* (set-cosine over word tokens instead of embedding cosine) — and rank by
* composite, descending. Ties keep input order (stable sort).
*
* Deterministic: same inputs → byte-identical output, every run, every
* machine. Zero dependencies, zero network, sync-fast (async only to satisfy
* the `InfluenceScorer` seam). Never touches `args.embedder` or `args.signal`.
*
* Honest claim: ranked WORD-OVERLAP proxies — cheaper and blinder than the
* embedding scorer (paraphrase = miss). NOT causal attribution — see module
* docs.
*
* @throws on duplicate evidence ids or invalid weights.
*/
export declare function scoreLexicalInfluence(args: ScoreLexicalInfluenceArgs): Promise<InfluenceScore[]>;