UNPKG

agentfootprint

Version:

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

38 lines • 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withNegativeProse = void 0; const outputSchema_js_1 = require("../../../answer-validation/outputSchema.js"); const ledger_js_1 = require("../findings/ledger.js"); const capture_js_1 = require("./capture.js"); const prose_js_1 = require("./prose.js"); /** After all terminal routing/transforms, before assessment and conversation * capture. No correction, schema parser invocation, answer rewrite or verdict. */ 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 = (0, outputSchema_js_1.applyOutputSchema)(raw, { parse: (value) => value }); } catch { /* The schema's own path retains its verdict; observe the text. */ } } const record = (0, capture_js_1.negativeRecordOf)(scope, options.runId()); const rows = (0, prose_js_1.observeNegativeProse)(candidate, record, undefined, options.phrases); (0, ledger_js_1.recordFindings)(scope, rows.map((row) => ({ ...row, iteration: scope.iteration })), { turn: record.turn }); return branch; }; } exports.withNegativeProse = withNegativeProse; //# sourceMappingURL=observe.js.map