UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

51 lines (50 loc) • 3.69 kB
/** * The closed set of reasons a request's prefix may lawfully change (design/1393 §5.3). Five open a new * epoch of the head; the last two rewrite history without touching the head. * - `leg_start_inputs` — a leg-start input of the head moved since the session's anchor (environment facts, the memory * band — its configuration, or its store content where the segment's frozen copy is not served: another process, a * withholding or an erasure since —, MCP instructions, the stable body, the tool table). * - `tool_table` — the mounted tool table moved inside the leg (a deferred activation, a roster refresh, the * per-request view). * - `compaction` — a landed compaction: the history is replaced, and a center-prompt adoption moves the system. * - `request_policy` — the request's controls moved (thinking level, output cap, retention word). * - `model_namespace` — the serving model moved (a lane hop, a degrade switch): a different cache namespace. * - `history_rewrite` — a request-time reducer the engine needs to fit the request rewrote earlier messages (a guard * trim, the media trim, the git frame's degrade, a copy pointer, a provider-refused view, a trimmed request's bring-back). * - `tool_result_clear` — old tool results were replaced by cleared markers. It has its own word because clearing is * the one reduction a deployment turns on itself (`microCompact`) and can turn off; the reducers above are what the * engine must do to fit, and share one word. * * @contract prompt_cache.declaration.one_word — every in-leg change to a request's prefix is declared exactly * once, by the seat that makes it, before the request that carries it goes out, with one word of this set; the * session's prefix ledger reads the declarations only to say whether a change it located was declared, and never infers a * reason from the change itself — a located change with no declaration is reported as undeclared (`declared: false`). */ export declare const PREFIX_CHANGE_CAUSES: readonly ["leg_start_inputs", "tool_table", "compaction", "request_policy", "model_namespace", "history_rewrite", "tool_result_clear"]; export type PrefixChangeCause = (typeof PREFIX_CHANGE_CAUSES)[number]; /** One declaration of a prefix change, made by the seat that changes the request. */ export interface PrefixChangeDeclaration { cause: PrefixChangeCause; /** A history word's landing, when its seat knows it: the first message index of the request the rewrite can change, or * `"tail"` — the last message of the main line's previous request, read by the ledger in its own coordinate (a seat that * moves what rode the end of the previous request). The word covers a change in the `messages` region only at or after it; * absent ⇒ 0 (the whole region). */ from?: number | "tail"; } /** One tool as its identity is computed: the name, the description and the schema the wire carries. */ export interface ToolFingerprintInput { name: string; description: string; parameters: unknown; } /** * Project a tool list into the inputs the tool table's identity is computed over. Shared by the initial snapshot in * `prepareTask` AND the per-materialization refresh in tool-disclosure (design/36): both MUST derive the identity the same * way, or a deferred tool going placeholder→full schema would be hashed inconsistently. The schema is the one the wire * carries (`projectToolSchema`), so the identity moves when those bytes do. */ export declare function toolsToFingerprintInputs(tools: ReadonlyArray<{ name: string; description: string; parameters: unknown; }>): ToolFingerprintInput[];