UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

96 lines (95 loc) • 7.23 kB
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 PromptEpochArtifact } from "../../prompt-assembly/artifact.js"; import { type EpochDeclaredSections } from "../../prompt-assembly/epoch.js"; import { type EnvironmentFacts, type PromptProvider, type PromptTextDeclaration } from "../../prompts/default.js"; import { type StoredSession } from "../session.js"; import type { RunnerDeps } from "../types.js"; import type { AnnounceOnceSink, Prepared, PrepareResume, PromptFeatureFlags, RunInternals } from "./contracts.js"; /** The center adoption a run composes under: the artifact and, when the source stamped one, its revision. */ export type CenterAdoption = { artifact: PromptEpochArtifact; sourceRevision?: string; }; export interface PreparePromptAssemblyInput { /** borrowed-mutable — the acquired session. Read: `getPromptEpoch` (the pin, twice — the center arm and the epoch * resolution), `getBranch` (the freshness discriminator on the pinless arms). Writer here: `appendPromptEpoch`, the * ONE pin write of this leg (only when the resolution migrated). 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 store and its live candidate), `onError` * (the assembly's warn channel, the prompt-constitution line, the missing-declaration disclosure). Receiver preserved. */ deps: Pick<RunnerDeps, "promptSource" | "onError">; /** borrowed-readonly — the trusted spawn-side channel: the parent's center closure (`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 resolved prompt provider (compared against the default for `isDefaultProvider`). */ provider: PromptProvider; /** borrowed-readonly — the caller's role-layer prompt, or undefined. */ userSystemPrompt: string | undefined; /** borrowed-readonly — the caller's appended prompt, or undefined. */ userAppendSystemPrompt: string | undefined; /** 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; only `promptGuidance` (the model-guidance section). */ model: Pick<Model, "promptGuidance">; /** borrowed-readonly — the acquired session id (every operator line's attribution). */ sessionId: string; /** borrowed-readonly — the session's reminder provenance mark (the declaration the assembled prompt must render). */ reminderMark: 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 swap). 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, or undefined for a provider whose assembly cannot 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, or undefined (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 provider-declared sections in the epoch shape (id, slot, chars, opt-in contentHash; never text). */ epochDeclaredSections: EpochDeclaredSections; /** owned — the resolved epoch's artifact digest, the turn snapshot's identity element. */ epochArtifactDigestForSnapshot: string; /** owned — the re-invokable assemble-inputs BUILDER: the compaction-boundary candidate re-assembles with a new * artifact's declarations through it (facts and tails identical; only the center closure differs). */ buildAssembleInputs: (centerDecls?: PromptTextDeclaration[]) => Parameters<typeof assemblePrompt>[0]; /** borrowed-mutable — the LIVE center adoption (an accessor cell over this phase's closure variable), or undefined. * Writers: this phase (the three arms; the all-shadowed drop on the fresh arm); the turn-wiring phase's center * candidate `apply` (the boundary swap / the explicit-disable rollback). Readers: the two late-bound ctx getters * (inherited-gate, caps-and-workflow), the pin write, the candidate's same-artifact test. */ centerAdoptionRef: { current: CenterAdoption | undefined; }; } /** The M13 phase body — prepareTask's prompt-assembly stretch, verbatim (see the module header). */ export declare function preparePromptAssembly(input: PreparePromptAssemblyInput): Promise<PreparePromptAssemblyResult>;