UNPKG

agentfootprint

Version:

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

89 lines • 3.65 kB
/** * Row "You asked" — the question as the record holds it. * * `turn_start.userPrompt` is the text AFTER the input middleware chain * (`stages/seed.ts` · `buildSeedStage` seeds `verdict.content`). It is the * person's own words only when no input decision changed it; otherwise it is the * app's version (voucher `app`) and the raw words are said to be missing — never * reconstructed. A resumed leg has no `turn_start` (seed does not re-run); the * run's `userMessage` is then quoted, vouched by the library. A question the * record keeps out (a redaction policy's placeholder) is said to be kept out — * never "not recorded", which would deny it was asked. */ import { v } from '../render.js'; import { keptOut, str } from '../view.js'; import { at, stateAt } from './common.js'; export function readAsked(ctx) { const start = ctx.view.first('agent.turn_start'); const prompt = str(start?.payload.userPrompt); if (start !== undefined && prompt !== undefined) { const rewrites = ctx.view .ofType('middleware.decision') .filter((e) => (e.payload.moment === 'input' || e.payload.phase === 'input') && e.payload.changed === true); const from = at(start, 'userPrompt'); if (rewrites.length === 0) { return { question: { value: prompt, source: 'person', status: 'recorded', pointers: [from] }, lines: [ctx.say('asked', { vars: { question: v(prompt, 'person', from) } })], }; } const deciders = rewrites.flatMap((e) => [at(e, 'middleware'), at(e, 'changed')]); return { question: { value: prompt, source: 'app', status: 'recorded', pointers: [from, ...deciders] }, lines: [ ctx.say('asked.rewritten', { vars: { question: v(prompt, 'app', from) }, pointers: deciders, }), ctx.say('asked.raw.notRecorded', { status: 'not-recorded', missing: 'no-event', pointers: [], }), ], }; } const keptOutAt = start !== undefined && keptOut(start, 'userPrompt') ? at(start, 'userPrompt') : start === undefined && ctx.resumedLeg && ctx.view.isStateKeptOut('userMessage') ? stateAt('userMessage') : undefined; if (keptOutAt !== undefined) { return { question: { value: null, source: 'library', status: 'not-recorded', pointers: [keptOutAt], missing: 'redacted', }, lines: [ ctx.say('asked.keptOut', { status: 'not-recorded', missing: 'redacted', pointers: [keptOutAt], }), ], }; } const held = str(ctx.view.state?.userMessage); if (ctx.resumedLeg && held !== undefined && held.length > 0) { const from = stateAt('userMessage'); return { question: { value: held, source: 'library', status: 'recorded', pointers: [from] }, lines: [ctx.say('asked.resumed', { vars: { question: v(held, 'library', from) } })], }; } return { question: { value: null, source: 'library', status: 'not-recorded', pointers: [], missing: 'no-event', }, lines: [ctx.say('asked.none', { status: 'not-recorded', missing: 'no-event' })], }; } //# sourceMappingURL=asked.js.map