@sema-agent/core
Version:
Stateless, task-oriented AI agent core
105 lines (104 loc) • 6.76 kB
TypeScript
/**
* The two run-time reminders of the turn-boundary attachment lane — `silent_turn_reminder` (the model has gone several requests
* without a word to the person) and `elapsed_time_reminder` (how long the person's request has been running) — their switch and
* their judgment. Pure: no I/O, no clock of its own; the boundary hands the rows and the time.
*
* THE SWITCH is read once, at prepare ({@link runTimeReminderLane}): the run's prompt traits say whether the model is one the
* reference reminds (its capabilities `silent_turn_reminder` / `timed_silent_turn_reminder` / `elapsed_time_reminder`), the
* task's attachments config may turn either off (`TaskSpec.attachments.silentTurnReminder` / `.elapsedTimeReminder`, default on —
* the registry rows), and a child leg never gets the silent reminder (the reference serves it on the main thread only). The
* producers read the resolved lane, never a trait.
*
* THE JUDGMENT follows the reference's transcript walk ({@link readSilentStretch}): from the end backwards, an assistant row
* that says something to the person ends the stretch of silence; a person's input that opened its leg (an objective, a resume's
* continuation) ends it and is its start, a steer that landed mid-run does not touch it; a delivered silent
* reminder counts and moves the start; a turn-boundary bundle without one (the reference's other attachments: the elapsed time,
* the token count, …) is skipped; any other engine note moves the start (the reference's meta rows). The count arm fires when fewer than
* {@link SILENT_TURN_REMINDER.MAX_PER_STRETCH} reminders rode this stretch and {@link SILENT_TURN_REMINDER.TURNS} silent requests
* passed since the last one; the timed arm fires when at least one silent request passed since the last one and the silence has
* lasted {@link SILENT_TURN_REMINDER.SECONDS} seconds — with no cap: the reminder itself restarts the silence.
*/
import type { AgentMessage } from "../../internal/harness.js";
import type { PromptTraitName } from "../../prompt-assembly/catalog/schema.js";
/** The reference's thresholds: `wWn` (cli321.js:288269), `TWn` (cli321.js:288269), `F5r` (cli321.js:288269). */
export declare const SILENT_TURN_REMINDER: Readonly<{
/** Silent requests since the last reminder before the count arm fires again. */
TURNS: 5;
/** Reminders one stretch of silence may carry under the count arm. */
MAX_PER_STRETCH: 3;
/** Seconds of silence before the timed arm fires. */
SECONDS: 60;
}>;
/** Which arm of the silent reminder a run is on. */
export type SilentTurnReminderArm = "off" | "turns" | "timed";
/** The run's two reminder lanes, resolved once at prepare. */
export interface RunTimeReminderLane {
readonly silentTurn: SilentTurnReminderArm;
readonly elapsedTime: boolean;
}
/** The run's reminder lanes: the traits' answer, less what the task's attachments config turned off, less the silent reminder on
* a child leg. `switches` are the config's two answers (absent key = on, {@link import("./turn-attachments.js").attachmentSwitchOn}). */
export declare function runTimeReminderLane(input: {
readonly traits: ReadonlySet<PromptTraitName>;
readonly childLeg: boolean;
readonly switches: {
readonly silentTurn: boolean;
readonly elapsedTime: boolean;
};
}): RunTimeReminderLane;
/** What the transcript says about the current stretch of silence. */
export interface SilentStretch {
/** Assistant requests that said nothing to the person since the stretch's latest reminder (since its start when none rode). */
readonly turnsSinceLastReminder: number;
/** Silent reminders delivered in this stretch. */
readonly remindersInStretch: number;
/** When the silence started (ms, the rows' clock): the latest of the person's input, a delivered reminder, an engine note that
* is not a boundary bundle, and the last row of a request that spoke; absent only for an empty transcript. */
readonly silentSince: number | undefined;
}
/** How the running leg opened (set where its opening prompt is sent — run-leg.ts): whether that prompt's row is a person's-input
* row (a fresh leg's objective; a resume's continuation that carries an input frame) and when, on the rows' clock. A leg whose
* opening row is not one — a resume carrying no input frame, a wake — still stamps its first person's-input row as the one that
* opened it (`legFirstInput`, the harness's stamp, which the file-history boundary keys on); for the stretch that row is a steer
* that landed mid-run, the reference's queued-command attachment (`d3r` breaks on a person's prompt only). The stored row of an
* EARLIER such leg cannot be told from its opener: only the running leg's is read this way. */
export interface LegOpening {
readonly byPerson: boolean;
readonly at: number;
}
/**
* The current stretch of silence, read backwards off the rows the next request is built from (the reference's `d3r`). One
* assistant row is one request (the reference groups streamed rows by message id; a row here is already one response).
*/
export declare function readSilentStretch(rows: readonly AgentMessage[], opening?: LegOpening): SilentStretch;
/** Whether the silent reminder is due at a boundary on `arm`, `now` on the rows' clock (the reference's `u3r`). */
export declare function silentTurnReminderDue(stretch: SilentStretch, arm: Exclude<SilentTurnReminderArm, "off">, now: number): boolean;
/**
* A boundary's inputs for the two producers: the silent reminder's stretch, read off the rows the next request is built from (a
* read that fails says nothing this boundary), with `now` on the rows' own clock (the harness stamps a row with `Date.now()`); the
* elapsed reminder's reading of the session's clock. A source whose frame is already on its way is not read again.
*/
export declare function boundaryReminderInputs(input: {
readonly lane: RunTimeReminderLane;
readonly elapsedClock: {
elapsedMs(): number;
};
/** The running leg's opening, once its opening prompt has set it. */
readonly opening: {
readonly current?: LegOpening;
};
readonly carried: (source: "silent_turn_reminder" | "elapsed_time_reminder") => boolean;
readonly rows: () => Promise<readonly AgentMessage[]>;
}): Promise<{
readonly silentTurn?: {
readonly stretch: SilentStretch;
readonly now: number;
};
readonly elapsedMs?: number;
}>;
/** The elapsed-time reminder's two slots for a duration (the reference's `H5r`): whole minutes, and the seconds past them in two
* digits. */
export declare function elapsedTimeSlots(ms: number): {
readonly minutes: string;
readonly seconds: string;
};