@sema-agent/core
Version:
Stateless, task-oriented AI agent core
61 lines (60 loc) • 5.27 kB
TypeScript
/**
* The run's record of a REFUSED VERDICT (`TaskResult.verdictRefused`, the `task.verdict_refused` notice) — what tells "the model did
* not submit" from "it submitted and the gate refused it" when a leg ends without its outcome.
*
* ONE rule: on this run, at least one call of the leg's verdict tool (the catalog's `verdict` rows for the leg's kinds,
* `legVerdicts`) was refused at the gate, and no call of it was delivered ⇒ the run carries the record and announces it once;
* otherwise neither (a delivery anywhere on the run — before or after a refusal — means the leg has its outcome). The words are read
* off each verdict call's END, never composed again: REFUSED = its gate record (`tool_end.gate`, a refusal recorded after the gate
* included) is a deny — `deniedBy` / `settlement` are that record's words; DELIVERED = the gate let it go and its body ran (no
* `notExecuted`) — every verdict body records its outcome when it runs, so a run body is a landed outcome, whatever an extension then
* showed the model; an extension's result in the body's place (`notExecuted`) and arguments refused before the gate (no gate record)
* are neither. A deny on an end minted while the turn it ran in is being cut is no refusal — the harness's one reading of that,
* `turnSeatState() === "ending"`: the run's own stop (a host cancel, the walltime, a stop the run made) and a cut of the turn alone (a
* person's halt, an immediate steer, an extension's `$.turn.abort`) both answer it — so the gate's deny such a cut leaves on the call is
* read as what it is, a cut, and the terminal (or the turn's notice) already says why. A delivery is read whenever it lands, a cut
* turn's included (its body ran: the leg has its outcome). The record rides only a FINAL result: a paused
* result carries none (`recordsOf`), and the resumed leg keeps a ledger of its own run (`attempts` counts this run).
*/
import type { EngineNotice } from "../engine-notice.js";
import type { GateOutcome } from "../gate-outcome.js";
import type { RefusedAsk, RefusedToolCalls, VerdictRefusal } from "../task-result.js";
import { type LegVerdicts } from "../../agents/tool-filter.js";
import type { ToolLegKind } from "../tool-face.js";
export interface VerdictLedger {
/** The leg's verdict tools (`legVerdicts` of its kinds; this ledger reads only which tools they are) — also what the leg's tool view never hides. */
readonly verdicts: LegVerdicts;
/** One call's end, fed by the one mint of `tool_end` (`emitSettled`: the live loop's, the resumed leg's, a reconcile's) — the roster's
* wire name, the end's gate record and its never-executed fact. A call of no verdict tool of this leg is not read; a deny on an end
* minted while its turn is being cut is no refusal (a delivery is read whenever it lands). */
noteEnd(end: {
readonly toolName: string;
readonly toolCallId: string;
readonly gate: GateOutcome | undefined;
readonly notExecuted: boolean;
}): void;
/** Was the leg's LAST verdict-call end a refusal (rather than a delivery, or arguments refused before the gate)? */
lastEndRefused(): boolean;
/**
* The run's two refusal records as its result carries them, read off the same ends under the same cut rule. `final`: the result
* is the run's last word (not a paused one).
* - `verdictRefused` — present ⇔ the result is final, a verdict call was refused on this run, and none was delivered on it. A
* paused result carries none (the run is not over: its resumed leg keeps a record of its own).
* - `refusedToolCalls` — every call the gate refused on this run outside a cut, bounded; absent when none was. Each call is
* sorted once, when its end is read: an ask nobody could answer (`asks` holds it), a call of a verdict tool of this leg, a
* person's refusal, anything else. A verdict tool's call is counted by the verdict record exactly when that record rides this
* result; otherwise (the verdict landed, or the result is paused) it is the ordinary refusal it is. So every refused call is
* counted once, by one record, on every result: the asks, the person's and the other calls, the verdict's attempts.
*/
recordsOf(final: boolean): {
readonly verdictRefused?: VerdictRefusal;
readonly refusedToolCalls?: RefusedToolCalls;
};
}
/** The ledger of a leg of these kinds (no verdict tool ⇒ its verdict record never records; its refused calls are any tool's).
* `cut` answers, at the moment an end is minted, whether the turn it ran in is being cut (the leg's harness
* `turnSeatState() === "ending"`). `asks` is the run's list of asks nobody could answer (`TaskResult.refusedAsks`, borrowed: the
* ask lane adds a call to it when the ask settles, before the call's end is minted). */
export declare function createVerdictLedger(legs: readonly ToolLegKind[], cut: () => boolean, asks: readonly RefusedAsk[]): VerdictLedger;
/** The run's one announcement of its record — sent exactly when the result carries it. `ids` are the run's attribution keys. */
export declare function verdictRefusedNotice(refused: VerdictRefusal, ids: Record<string, string>): EngineNotice;