@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
57 lines • 2.97 kB
JavaScript
/**
* The two seams that see a turn's traffic to and from the model: an {@link InputProcessor} rewrites
* the prompt on its way out, an {@link OutputProcessor} inspects the answer on its way back and may
* redact, replace or refuse it. Wire them as `AgentLoopDeps.inputProcessors` / `outputProcessors`.
*
* WHAT THESE ARE NOT: a second way to decide what enters the context. {@link
* import('./history-window.js').HistoryWindow} owns SELECTION — which of the thread's messages ride
* into the turn, and what stands in for the rest. Processors run on whatever selection produced and
* own TRANSFORMATION — what those messages say. The distinction is load-bearing rather than
* stylistic: `select` is contractually pure and runs outside any checkpoint, while a processor is
* allowed to call a model, runs in a checkpoint of its own per step, and rewrites a DERIVED prompt
* that never becomes the thread's own memory of what was said.
*/
/**
* Characters an incremental gate keeps holding at the end of the transformed answer, when a
* processor declares {@link IncrementalGating} without naming its own window. Wide enough for the
* patterns a redactor is usually written against — an SSN, an email address, a card number — and
* deliberately not wider: the window IS the answer's minimum latency tail, since those characters
* are only released once the whole-answer pass runs.
*/
export const DEFAULT_INCREMENTAL_LOOKBACK_CHARS = 64;
/**
* The run ended because an output processor refused the answer — NOT because the model failed. The
* two must stay distinguishable: a model failure is worth retrying and worth paging someone about, a
* refusal is the control doing its job.
*/
export class OutputRejectedError extends Error {
/** {@link OutputProcessor.name} of the processor that refused. */
processor;
/** The reason it gave, verbatim. */
reason;
constructor(processor, reason) {
super(`Output rejected by "${processor}": ${reason}`);
this.name = 'OutputRejectedError';
this.processor = processor;
this.reason = reason;
}
}
/**
* A processor threw. Wrapped so it can never be mistaken for the model call failing — the loop's
* only other source of failure at that point in the turn — and so the failure names the processor
* that produced it instead of surfacing a bare `TypeError` from someone else's code.
*/
export class ProcessorFailedError extends Error {
/** Which seam it was on, so a reader knows whether the prompt or the answer was in flight. */
phase;
/** The processor's `name`. */
processor;
constructor(phase, processor, cause) {
super(`${phase} processor "${processor}" failed: ${cause instanceof Error ? cause.message : String(cause)}`);
this.name = 'ProcessorFailedError';
this.phase = phase;
this.processor = processor;
this.cause = cause;
}
}
//# sourceMappingURL=processors.js.map