@sema-agent/core
Version:
Stateless, task-oriented AI agent core
70 lines (69 loc) • 6.25 kB
TypeScript
/**
* A leg's receipt of its spec: every member of it that names something a peer can be dialled with, and the tool roster, taken ONCE at
* the moment the engine takes the spec (`Runner.runTaskStream`, for every fresh, resumed, child, cascade-rung and repair-attempt leg) —
* inside the call its giver (the host, or the parent leg's tool call) is alive for. What it takes:
*
* - the lock set, `mcp` and `a2a` — the door's own receipt (locked-config.ts {@link receivePeerDeclarations});
* - the tool roster's one snapshot (caller-roster.ts {@link snapshotCallerRoster}): prepare mounts and scans this copy, so the
* definitions a delegation or workflow tool of the roster was made with are read off the very entries the leg mounts;
* - `agents` — the list read once, each per-task definition copied whole ({@link snapshotDefinitionLists}) or refused on its own.
*
* And first, before anything of the spec, the declarations the Runner itself holds ({@link receiveHeldDeclarations}): before a leg
* starts, every declaration its Runner holds has passed its receipt — whether or not the leg mounts the tool that would use it. The
* MCP servers and A2A peers whose credential references the receipt takes in are the leg's own: the person told why its shell lacks a
* variable is given the names of the entries this receipt took in for that very variable, never another leg's ({@link LegReceipt.peerEntries}).
*
* The leg holds every reference this receipt names ({@link legDeclarations}, the one keeper reading `heldDeclarationsOf`) from the call
* until its stream settles, and every door of its prepare judges this same receipt: what a leg holds, what it mounts and what it dials
* are one read. A refusal is kept and raised by the door that judges it, where it would have been raised. A prepare entered without
* a receipt (outside a Runner) takes one at its start, through this same function.
*/
import type { AgentDefinition, RunnerDeps, TaskSpec } from "../types.js";
import type { PeerDeclarations } from "../peer-seat.js";
import { type Received, type ReceivedPeerDeclarations } from "../locked-config.js";
import { type PeerEntriesTaken } from "../secret-env.js";
import { snapshotCallerRoster } from "./caller-roster.js";
/**
* Declarations held before a leg receives them as part of its spec, each through the receipt that reads it where it is used, so what
* their MCP servers' and A2A peers' credential references name is taken in (locked-config.ts `snapshotDeclaredEntry`) before a child is
* spawned: agent definitions (`agents`) through the definition receipt ({@link snapshotDefinitionLists} — the delegation tool's and the
* workflow tool's), and a workflow governance baseline (`workflowGovernanceBaseline`) through the baseline's
* ({@link receiveGovernanceBaseline} — the workflow tool's). Called first by every leg's receipt ({@link receiveLeg}) with what the Runner
* holds of its own (`RunnerDeps.agents`, `RunnerDeps.workflowGovernanceBaseline`), and by `runSpec` with its task's definitions before
* its preflight.
*
* Nothing is refused here and this never throws: a declaration its receipt refuses is refused where it is received to be used (the
* delegation tool's assembly, the workflow tool's mount, the leg's door), exactly as before; here what the receipt read before its
* refusal stands, and every other one is received on its own. Every leg receives them again, as they stand at its receipt: there is no
* memo, so a declaration the host edits or adds after an earlier leg is taken in by the next leg's receipt.
*/
export declare function receiveHeldDeclarations(held: {
readonly agents?: unknown;
readonly workflowGovernanceBaseline?: unknown;
}): void;
/** What a leg received of its spec at the call (see the module note). */
export interface LegReceipt extends ReceivedPeerDeclarations {
/** The tool roster's one snapshot, or the refusal it met (raised as prepare's first refusal). */
readonly roster: Received<ReturnType<typeof snapshotCallerRoster>>;
/** `TaskSpec.agents`: absent when the task carries none; else the list read once, each definition copied whole or refused on its own. */
readonly agents?: Received<readonly Received<AgentDefinition>[]>;
/** The entries whose credential references this receipt took in, per variable they name, as a sentence names each entry (`MCP server "acme"`):
* the (variable, entry) pairs the leg's person is told an entry of by name (secret-env.ts {@link peerEntriesTakenIn}). */
readonly peerEntries: PeerEntriesTaken;
}
/** Take a leg's receipt of `spec` (see the module note). Never throws for a spec that is an object. */
export declare function receiveLeg(spec: TaskSpec, deps: Pick<RunnerDeps, "lockedConfig" | "agents" | "workflowGovernanceBaseline">): LegReceipt;
/** The receipt of the same call for a spec the engine made from it at the run's entry (a saved team's run, team-run.ts): the same
* roster, lists and definitions — nothing is read again — and the roster's spec copy with `members` laid over it, which is the spec
* every door of the leg's prepare reads. A roster refused at the call stays refused. */
export declare function receiptWith(receipt: LegReceipt, members: Partial<TaskSpec>): LegReceipt;
/** Prepare's receipt — the one the Runner took at the call, or (prepare outside a Runner) one taken now by {@link receiveLeg} — and its
* roster snapshot, the snapshot's refusal raised here, as prepare's first. */
export declare function receiptAtPrepare(taken: LegReceipt | undefined, spec: TaskSpec, deps: Pick<RunnerDeps, "lockedConfig" | "agents" | "workflowGovernanceBaseline">): {
readonly receipt: LegReceipt;
readonly callerRoster: ReturnType<typeof snapshotCallerRoster>;
};
/** What a leg holds (the keepers are peer-seat.ts's module note): its receipt's copies — its own lists, its per-task definitions and its
* roster's tools (each entry as handed, and its face: the rebuild seam prepare calls is the face's) — read by the one keeper reading. A
* refused entry names nothing (the door refuses the leg before anything is dialled). */
export declare function legDeclarations(receipt: LegReceipt): PeerDeclarations;