UNPKG

agentfootprint

Version:

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

34 lines • 1.67 kB
import { applyOutputSchema } from '../../../answer-validation/outputSchema.js'; import { recordFindings } from '../findings/ledger.js'; import { negativeRecordOf } from './capture.js'; import { observeNegativeProse } from './prose.js'; /** After all terminal routing/transforms, before assessment and conversation * capture. No correction, schema parser invocation, answer rewrite or verdict. */ export function withNegativeProse(decide, options) { return async (scope) => { const branch = await decide(scope); if (branch !== 'final' || scope.messageDeniedReason !== undefined || scope.unsupportedValues?.refused === true || scope.answerValidationBlocked === true || options.hasOutstandingConsent()) return branch; const raw = scope.llmLatestContent; let candidate = raw; // Decode only a bounded structured answer. Never invoke the app's parser // again: it may transform data or have effects. Invalid JSON stays text. if (options.structured && raw.length <= 1024 * 1024) { try { candidate = applyOutputSchema(raw, { parse: (value) => value }); } catch { /* The schema's own path retains its verdict; observe the text. */ } } const record = negativeRecordOf(scope, options.runId()); const rows = observeNegativeProse(candidate, record, undefined, options.phrases); recordFindings(scope, rows.map((row) => ({ ...row, iteration: scope.iteration })), { turn: record.turn }); return branch; }; } //# sourceMappingURL=observe.js.map