UNPKG

agentfootprint

Version:

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

43 lines • 2.14 kB
/** * A run's TERMINAL VERDICT: the way an agent's run ended that its caller must * receive as a typed error, held as a plain value a chart's state can carry. * * An agent ends some runs on a record in its state instead of a throw — a * reliability fail-fast, a policy halt, a denied message, a refused answer — * and only its run boundary (`Agent · finalizeResult`) turns that record into * the error. A composition mounts the agent's CHART, so that boundary never * runs: the composition asks the agent what the mount handed back * (`outcomeOf`, duck-typed — `core-flow/` imports no runner): its answer, or * the verdict read off the state its chart ended with. It carries the verdict * and raises the SAME error (`terminalErrorOf`). One translation, used by the * agent's own boundary and by every composition. * * Leaf module: the error classes only, no runner. */ import { AnswerValidationError } from '../answer-validation/types.js'; import { failFastErrorOf } from '../reliability/failFastRecord.js'; import { PolicyHaltError } from '../security/PolicyHaltError.js'; import { UnsupportedValuesError } from './agent/evidence/errors.js'; import { MessageDeniedError } from './agent/middleware/errors.js'; /** The typed error a verdict is raised as — the same one the agent's own run raises. */ export function terminalErrorOf(verdict, snapshot) { switch (verdict.kind) { case 'reliability-fail-fast': return failFastErrorOf(verdict.record, snapshot); case 'policy-halt': return new PolicyHaltError(verdict.halt); case 'message-denied': return new MessageDeniedError(verdict.denial); case 'unsupported-values': return new UnsupportedValuesError(verdict.refusal); case 'answer-validation': return new AnswerValidationError(verdict.report); } } /** Whether a runner reads its own chart's outcome. */ export function readsItsOwnOutcome(runner) { return (typeof runner === 'object' && runner !== null && typeof runner.outcomeOf === 'function'); } //# sourceMappingURL=terminalVerdict.js.map