UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

85 lines (84 loc) • 6.78 kB
import type { Model } from "../../internal/llm.js"; import type { AgentHarnessEvent } from "../../internal/harness.js"; import type { PromptTraitName } from "../../prompt-assembly/catalog/schema.js"; import { type ToolCardFacts } from "../../prompt-assembly/tool-catalog.js"; import type { MaterializedA2a } from "../a2a.js"; import type { MaterializedMcp } from "../mcp.js"; import type { RunnerDeps, TaskSpec } from "../types.js"; import type { AnnounceOnceSink, ToolFaceSnapshot } from "./contracts.js"; import { RosterBuilder } from "../tool-roster.js"; import type { ToolFaceClass, ToolLegKind } from "../tool-face.js"; export interface PrepareDeferClassifyInput { /** borrowed-readonly — the REBOUND spec (`spec′`); only `tools` is read (names for the full-schema filter, specs for the `defer` declarations). */ spec: Pick<TaskSpec, "tools">; /** borrowed-readonly — deps; `deferMode` (candidate widening) and `toolSearch` (rule ②'s gate) are the only seats read. */ deps: Pick<RunnerDeps, "deferMode" | "toolSearch">; /** borrowed-mutable — the shared mount array (later refs alias it; in-place contract, never * re-created). Mutated here, in order: `splice` of every excluded name; element REPLACEMENT with a * shallow copy for a description variant chosen by the run's traits (the caller's ToolSpec object is never * mutated); `splice` of a retracted memory group. After this phase: the content-origin wrap * (element replacement with the wrapped object), the disclosure mount, the MCP refresh re-splice. Since * Every one of those writes is a builder verb (`unmountWhere` / `replaceAt`). */ roster: RosterBuilder; /** borrowed-readonly — the frozen task-start tool face: the selector (the valve, and whether the search tool deferral needs is admitted), `defer` (operator defers, exact wire names), `alwaysLoad` (the pins). */ toolFaceSnapshot: Pick<ToolFaceSnapshot, "selector" | "defer" | "alwaysLoad">; /** borrowed-readonly — the run's effective prompt traits (each tool's description variants are chosen on them). */ promptTraits: ReadonlySet<PromptTraitName>; /** borrowed-readonly — the run's card facts (each tool's description variants are chosen on them too; `shellFirstSession`). */ cardFacts: ToolCardFacts; /** borrowed-readonly — the resolved model (the deferral gate's threshold reads its context window). */ model: Model; /** borrowed-readonly — the materialized MCP roster; only `tools` is read (protocol names; `mcpAlwaysLoad` self-declarations lose to an operator defer). */ mcp: Pick<MaterializedMcp, "tools">; /** borrowed-readonly — the leg's declared MCP servers (names only): a server the valve can still leave a tool of is the one lane * that can add a tool within the leg, so the tool-face class reads it. */ declaredMcp: readonly { readonly name: string; }[]; /** borrowed-readonly — the kinds of leg this is (the selector was compiled with them): the tool-face class reads its finishing * tools as this leg's own protocol rows, never a wire name alone. */ legs: readonly ToolLegKind[]; /** borrowed-readonly — the materialized A2A roster; only `tools` is read (protocol names). */ a2a: Pick<MaterializedA2a, "tools">; /** borrowed-readonly — whether the shared-memory pair mounted (project-context phase). */ sharedMemoryPairMounted: boolean; /** borrowed-readonly — whether the engine-memory pair mounted (project-context phase). */ memoryEnginePairMounted: boolean; /** borrowed-readonly — the memory block as the project-context phase left it; the engine pair's retraction strips the recall paragraph and returns the * stripped value as {@link PrepareDeferClassifyResult.memoryBlock}. The input is never mutated. */ memoryBlock: string | undefined; /** borrowed-readonly — the exact recall-discipline segment the memory phase composed (the strip removes THIS string, never a re-composition). */ memoryRecallSegment: string | undefined; /** borrowed-readonly — the once-per-session ledger's deduplicated operator sink (a retraction is announced once per session). */ onceLedger: AnnounceOnceSink; /** borrowed-readonly — the acquired session's id (operator-line context). */ sessionId: string; } export interface PrepareDeferClassifyResult { /** owned — the FINAL deferred set over the post-exclusion, post-retraction roster: the disclosure * mount, the deferred registry and `Prepared.deferredToolNames` all read this one set (there is * deliberately no second classification). Empty ⇒ nothing is deferred. */ deferred: Set<string>; /** owned — the memory block after the engine pair's retraction strip (unchanged when no retraction * ran). The driver binds it under the name the prompt assembly reads. */ memoryBlock: string | undefined; /** owned — the gate policy this classification was MEASURED under; the census reports it from here, never a second reading of the seat. */ toolSearch: import("../tool-search-setting.js").ResolvedToolSearch; /** owned — what the valve left the model, in one word ({@link toolFaceClassOf}): read once, after the valve and the memory groups' * late retraction (the roster's last removal), before the assembly that composes on it. */ toolFace: ToolFaceClass; } /** Each roster tool's description variant mounted over `traits` and the run's card facts — at prepare by the run's traits, and * again when the harness switches model by that model's (the facts are the run's, a model switch does not move them) — in place * through the builder (a face whose text does not move is kept). Whether any moved. */ export declare function mountCardVariants(roster: RosterBuilder, traits: ReadonlySet<PromptTraitName>, facts: ToolCardFacts): boolean; /** The cards follow the model the harness requests with, as the read-first waiver does: a switch (`model_select`) mounts each * card's variant again over the new model's traits and hands the harness the new faces; a model whose traits do not read keeps * the cards it had (the waiver then holds it to read-first, the safe side). */ export declare function cardsFollowModel(harness: { subscribe(listener: (event: AgentHarnessEvent) => Promise<void> | void): unknown; }, roster: RosterBuilder, traitsOf: (model: Model) => ReadonlySet<PromptTraitName>, facts: ToolCardFacts, rebuild: { current?: () => Promise<void>; }): void; /** The M11 phase body — prepareTask's tool-face fold + deferred classification, verbatim (module header). */ export declare function prepareDeferClassify(input: PrepareDeferClassifyInput): PrepareDeferClassifyResult;