agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
57 lines (56 loc) • 1.9 kB
TypeScript
/**
* llmExtractor — LLM-backed beat extractor.
*
* Uses an LLMProvider (typically a cheap model like Claude Haiku or
* GPT-4o-mini) to produce semantically rich beats. One extraction LLM
* call per turn. Opt-in — default is `heuristicExtractor()` which is
* free.
*
* The extractor asks the LLM for a JSON response in this shape:
*
* ```json
* {
* "beats": [
* {
* "summary": "User revealed their name is Alice",
* "importance": 0.9,
* "refs": ["msg-1-0"],
* "category": "identity"
* }
* ]
* }
* ```
*
* The extractor parses, clamps importance via `asImportance()`, and
* returns the beats. Malformed responses fall back to an empty array
* — a bad extraction should not break the agent turn.
*
* Usage:
* ```ts
* import { anthropic } from 'agentfootprint';
* import { llmExtractor, narrativePipeline, InMemoryStore } from 'agentfootprint/memory';
*
* const pipeline = narrativePipeline({
* store: new InMemoryStore(),
* extractor: llmExtractor({ provider: yourLLMProvider }),
* });
* ```
*/
import type { LLMProvider } from '../../provider-contract/types.js';
import type { BeatExtractor } from './extractor.js';
export interface LLMExtractorConfig {
/** The provider used for extraction. Typically a cheap/fast model. */
readonly provider: LLMProvider;
/**
* Override the system prompt. Defaults to a one-paragraph instruction
* that elicits the JSON shape described in the module docs.
*/
readonly systemPrompt?: string;
/**
* Dev-mode logger invoked when the LLM response fails to parse.
* Defaults to `console.warn` — production consumers can route the
* signal to their telemetry pipeline.
*/
readonly onParseError?: (error: unknown, rawContent: string) => void;
}
export declare function llmExtractor(config: LLMExtractorConfig): BeatExtractor;