@sema-agent/core
Version:
Stateless, task-oriented AI agent core
101 lines (100 loc) • 7.5 kB
TypeScript
import type { AgentTool } from "../../internal/harness.js";
import type { Model } from "../../internal/llm.js";
import { assemblePrompt, type AssembledPrompt } from "../../prompt-assembly/assemble.js";
import { type CenterAdoption } from "../../prompt-assembly/artifact.js";
import { type RunPromptIdentity } from "../../prompt-assembly/epoch.js";
import type { HostForm, HostRole } from "../../prompt-assembly/catalog/schema.js";
import type { SourcedOverlay } from "../../prompt-assembly/overlay.js";
import { type EnvironmentFacts } from "../../prompts/default.js";
import { type LegModBus } from "../mods/stations.js";
import { type StoredSession } from "../session.js";
import type { RunnerDeps } from "../types.js";
import type { AnnounceOnceSink, Prepared, PrepareResume, PromptFeatureFlags, RunInternals } from "./contracts.js";
export interface PreparePromptAssemblyInput {
/** borrowed-mutable — the acquired session. Read: `getPromptEpoch` (the stored record), `getBranch` (the freshness
* discriminator on the record-less arms). Writer here: `appendPromptEpoch`, the ONE record write of this leg (only
* when the run's identity differs from the stored record's). The acquire phase and the run loop write it elsewhere. */
session: Pick<StoredSession, "getPromptEpoch" | "getBranch" | "appendPromptEpoch">;
/** borrowed-readonly — the deployment seats: `promptSource` (the center artifact source, its candidate and its
* tri-state), `onError` (the assembly's warn channel). Receiver preserved. */
deps: Pick<RunnerDeps, "promptSource" | "onError">;
/** borrowed-readonly — the trusted spawn-side channel: the parent's center layer (`parentCenterArtifactDigest`,
* `parentCenterSourceRevision`), the top-level freshness facts (`parentTaskId`, `parentSessionId`) and the named-child
* fact the teammate flag reads (`explicitAgentName`). */
internals: Pick<RunInternals, "parentCenterArtifactDigest" | "parentCenterSourceRevision" | "parentTaskId" | "parentSessionId" | "explicitAgentName"> | undefined;
/** borrowed-readonly — the resume leg, or undefined; PRESENCE only (a resumed leg is never truly fresh). */
resume: Pick<PrepareResume, "seed"> | undefined;
/** borrowed-readonly — the request-body sugar's overlays (the task class's first contributions). */
sugar: readonly SourcedOverlay[];
/** borrowed-readonly — the host selector values (`promptRole` / `promptForm`). */
host: {
readonly role?: HostRole;
readonly form?: HostForm;
};
/** borrowed-readonly — the run's binding (`TaskSpec.promptBinding`, validated), or undefined: a selector value. */
binding: string | undefined;
/** borrowed-readonly — the leg's mods bus: `prompt.compose` collects the deploy and task seats' overlays. */
modBus: LegModBus;
/** borrowed-readonly — the run's abort signal (the compose raise ends with it). */
signal?: AbortSignal;
/** borrowed-readonly — the harness-context flags; the two orchestration flags are re-derived against the post-exclusion
* roster at assembly. */
featureFlags: PromptFeatureFlags;
/** borrowed-readonly — the MCP instructions block, or undefined. */
mcpInstructionsBlock: string | undefined;
/** borrowed-readonly — the memory block as the assembly reads it (the recall paragraph already stripped when a
* retraction ran), or undefined. */
memoryBlock: string | undefined;
/** borrowed-readonly — the environment facts; `date` is the assembly's date, the block builder re-renders on a date change. */
envFacts: EnvironmentFacts;
/** borrowed-readonly — the resolved prompt profile (a runtime fact of the assembly). */
promptProfile: "simple" | "classic";
/** borrowed-readonly — the fable mitigations switch (a runtime fact of the assembly). */
fableMitigations: boolean;
/** borrowed-readonly — the run's ONE tool roster, read only: the assembly receives DETACHED copies, the audit and the
* manifest read it in place. Never mutated here. */
tools: readonly AgentTool[];
/** borrowed-readonly — the task model: `promptGuidance` (the model-guidance section) and `id` (the compose event's `model`). */
model: Pick<Model, "id" | "promptGuidance">;
/** borrowed-readonly — the acquired session id (every operator line's attribution). */
sessionId: string;
/** borrowed-readonly — the once-per-session ledger's operator sink (the collision audit's two lines). */
onceLedger: Pick<AnnounceOnceSink, "onError">;
}
export interface PreparePromptAssemblyResult {
/** borrowed-mutable — the LIVE system prompt (an accessor cell over this phase's closure variable). Writers: this
* phase's `renderWithDate` (the date re-render, called by the listings phase's date_change seam); the turn-wiring
* phase's center candidate `apply` (the compaction-boundary change). Readers: the harness construction, the cache
* fingerprint, the turn snapshot's stable text, the prompt-overhead term. */
systemPromptSeat: {
current: string;
};
/** owned — the date re-render. Returns the new prompt and writes it into `systemPromptSeat`. */
renderWithDate: ((date: string) => string) | undefined;
/** owned — the physical block face of the assembled prompt (the harness's systemBlocks and the turn snapshot's
* layout groups). */
systemBlocks: AssembledPrompt["systemBlocks"];
/** borrowed-mutable — the composition manifest (`Prepared.promptManifest`). Writers after this phase: the tool-disclosure
* phase writes `toolDisclosure` (when deferred tools exist); the turn-wiring phase backfills `snapshot` and `lowering`
* once the final wire tool list exists. */
promptManifest: Prepared["promptManifest"];
/** owned — the run's identity inputs and the pinned center layer's provenance (`Prepared.promptIdentity`; the
* compaction-boundary candidate replaces it after a committed center change). */
promptIdentity: RunPromptIdentity;
/** owned — the re-invokable assemble-inputs BUILDER: the compaction-boundary candidate re-assembles with a new center
* layer through it (facts, tails and the run-frozen mods overlays identical; only the center class differs). */
buildAssembleInputs: (center: CenterAdoption | undefined) => Parameters<typeof assemblePrompt>[0];
/** owned — the identity inputs under another center layer (the compaction-boundary candidate's record). */
identityFor: (center: CenterAdoption | undefined) => RunPromptIdentity;
/** owned — whether this run adopts center candidates at its boundaries: a top-level run does; a child composes its
* parent's layer and never adopts one of its own. */
adoptsCandidates: boolean;
/** borrowed-mutable — the LIVE center adoption (an accessor cell over this phase's closure variable), or undefined.
* Writers: this phase (the resolution arms); the turn-wiring phase's center candidate `apply` (the boundary change).
* Readers: the two late-bound ctx getters (inherited-gate, caps-and-workflow), the candidate's same-artifact test. */
centerAdoptionRef: {
current: CenterAdoption | undefined;
};
}
/** The M13 phase body — prepareTask's prompt-assembly stretch (see the module header). */
export declare function preparePromptAssembly(input: PreparePromptAssemblyInput): Promise<PreparePromptAssemblyResult>;