agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
37 lines (36 loc) • 1.89 kB
TypeScript
/**
* resilienceHooks — turns a resilience decorator's `ResilienceReport`
* into an already-declared typed event, emitted from inside the run.
*
* Pattern: Adapter (GoF) — one translation function, fact → event.
* Role: The seam between `src/resilience/` (which knows nothing about
* runs, scopes or events) and the in-run LLM call sites (which
* hold a live scope). The decorator REPORTS; this maps the
* report to `typedEmit`, so correlation ids come from
* footprintjs's traversal rather than being synthesized.
* Emits: agentfootprint.fallback.triggered
* agentfootprint.error.retried
* agentfootprint.error.recovered
* agentfootprint.error.circuit_changed (9.32.0)
*
* Why here and not in the decorators: a decorator is constructed by the
* consumer BEFORE any run exists, so it can never reach a scope. Passing
* the hooks object per call is what lets the report cross that boundary.
*
* Every declared payload field is filled from a report field of the same
* name — nothing is synthesized. `FallbackTriggeredPayload.kind` is the
* literal `'provider'`; its `'tool'`/`'skill'` arms stay unused.
*/
import type { LLMCallHooks } from '../../provider-contract/types.js';
import { type EmitableScope } from './typedEmit.js';
import { type ReplayReportScope } from './replayHooks.js';
/**
* Build the per-call hooks object for one stage. Hoist it once per stage
* rather than per attempt — it is stateless and safe to reuse across
* reliability-loop iterations.
*
* @example
* const providerHooks = resilienceHooks(scope);
* const response = await provider.complete(request, providerHooks);
*/
export declare function resilienceHooks(scope: EmitableScope & ReplayReportScope, receiptMinted?: boolean, onReplayPersisted?: LLMCallHooks['onReplayPrepared']): LLMCallHooks;