UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

34 lines (33 loc) • 2.81 kB
/** * The session's record of the old tool results the engine cleared from its requests (the cleared-projection ledger, * `context-edit.ts`): what makes a clear the session's fact rather than one run's. * * Why it is kept: a clear rewrites the earliest cleared result's position in the request, so the provider re-reads the request * from there once. Held only in a run's memory, the next run rebuilt the full results from the transcript — its first request * carried them again (the size estimate is anchored on the cleared request, so nothing cleared them again) and the provider * re-read the request from that position a second time. Kept with the session, every later request — the next run's, a reloaded * engine's, a durable resume's, a fork's — repaints the same markers and extends the request before it. * * Stored as one engine-owned `custom` entry per change, the whole ledger in each; read as the newest one on the session's * branch (a branch rewound to before a clear holds no record of it, and its full results are the history again). A run reads it * once, at its first request build, and records the ledger again after any build whose landings or replay changed it (a * compaction that summarized a cleared result away prunes its entry). A read or a write that fails is said aloud by the caller * (`onFailure`; a write once while writes of the same ledger keep failing): the run keeps its own ledger and writes it again at its next build; a later run that finds no * record of it (a read that failed, a run that ended before a write landed) sends those results in full until a clear takes them out again. */ import type { SessionTreeEntry } from "../../internal/harness-types.js"; import { type ClearedProjectionLedger } from "../context-edit.js"; export declare const CLEARED_RESULTS_CUSTOM_TYPE = "engine:cleared-results"; export interface ClearedResultsSession { getBranch(): Promise<ReadonlyArray<SessionTreeEntry>>; appendCustomEntry(customType: string, data?: unknown): Promise<string>; } /** The newest record on `branch`: its ledger, `undefined` when the branch holds none, `"malformed"` when the newest does not read. */ export declare function storedClearedResults(branch: ReadonlyArray<SessionTreeEntry>): ClearedProjectionLedger | undefined | "malformed"; /** One run's seat on the record: `seed` fills the run's ledger from the session once; `record` writes it when it differs from the * newest record the run read or wrote. */ export interface ClearedResultsSeat { seed(ledger: ClearedProjectionLedger): Promise<void>; record(ledger: ClearedProjectionLedger): Promise<void>; } export declare function createClearedResultsSeat(session: ClearedResultsSession, onFailure: (error: unknown, step: "read" | "write") => void): ClearedResultsSeat;