@sema-agent/core
Version:
Stateless, task-oriented AI agent core
108 lines (107 loc) • 9.67 kB
TypeScript
import type { AgentDefinition, McpServerSpec, ToolSpec } from "../core/types.js";
import type { ToolSelector, ToolSelectorLayer } from "../core/tool-face.js";
import { type MountedMcp } from "../core/mounted-mcp.js";
import type { McpHostSeat } from "../core/mcp-host-seat.js";
import type { InheritedGate, RunInternals, RunnerSelfSeat } from "../core/runner/contracts.js";
/**
* What a delegated child inherits when its delegation tool has no explicit pool (`SubagentToolOptions.inheritedTools`):
* the parent surface, narrowed at spawn by two laws, and the parent's MCP declarations. The mint of the parent bound
* ({@link callerToolMembership}) and the reads live here, so the law has one home. Which of these tools the child may USE is
* not decided here: its own prepare runs its selector over everything it is handed and mounts.
*/
/** The team task-list family (pool-borne; the catalog marks it a teammate's protocol UNDER the ceiling — a named child holds the ones its
* spawner may use). */
export declare const TEAM_TASK_LIST_TOOL_NAMES: readonly string[];
/** The run's `mountsCallerTool` seat: membership BY IDENTITY in `spec.tools` as the caller handed it (the roster snapshot's
* copy of the array — the one read of the slot; nothing is read off the entries, so no entry can make the mint throw). */
export declare function callerToolMembership(tools: readonly unknown[] | undefined): (tool: ToolSpec) => boolean;
/**
* The inherited pool for one spawn.
* · ⊆ parent: an entry survives only when the spawning run mounts THAT instance — a same-named replacement (a host's
* own tool, a per-spawn injection) never re-admits the surface's original. No seat (the tool is driven outside a
* Runner) = no parent bound is known = nothing is inherited; a host driving the tool directly passes the seat itself.
* · tier (upstream `filterToolsForAgent`): an anonymous background child gets the async allowlist there — WebFetch /
* WebSearch / TodoWrite, not the task-list family. A synchronous child, a named teammate and a fork keep it.
*/
export declare function inheritedChildPool(surface: readonly ToolSpec[], mountsCallerTool: ((tool: ToolSpec) => boolean) | undefined, anonymousBackground: boolean): ToolSpec[];
/** Does this tool start agent runs? As its producer says: `ToolSpec.startsAgents: true` on its face, or the delegation factory's
* binding on its `execute` ({@link declaredDelegationNameOf} — a copy that drops the face member keeps it). Never by name. A member
* that cannot be read is not read as one: the leg the tool reaches refuses an unreadable or non-`true` value at its prepare. */
export declare function isAgentStarter(tool: ToolSpec): boolean;
/** The tools a worker of a run that keeps a member ledger is handed: `tools` without the ones that start agents ({@link isAgentStarter}).
* The one law for every way the engine hands a worker its tools — a spawn's pool (the nested delegation copy included) and a woken
* snapshot's. A worker's own workers would be members no ledger lists. */
export declare function withoutAgentStarters<T extends ToolSpec>(tools: readonly T[]): T[];
/**
* The MCP servers a delegated child is declared: each server its spawning run declares, exactly as declared, when the child's
* selector can admit a tool of it ({@link ToolSelector.admitsPeer} — read off the lists, never off what the server lists now).
* A server the selector can never reach is not declared, so it is never dialled or leased for this child. The child connects
* from these (through the run tree's pool) and its own selector decides, at intake and on every refresh and re-dial, which of
* the server's tools mount.
*/
export declare function inheritedMcpDeclarations(mounted: MountedMcp, selector: ToolSelector): McpServerSpec[];
/** The host seats a child is handed: of `held` (the seats of the run that spawns or wakes it — `MountedMcp.hostSeats`), those of the
* host-transport servers among `servers`, as the child's internals carry them — none ⇒ no member, so such a server of the child fails its
* dial like any declaration without a seat. A seat follows the declaration it was handed for: `servers` is what the child inherits from the
* run that spawns it, or, at a wake, the woken leg's own list — whose host-transport entries are inherited ones too, since the definition
* door refuses a definition that declares one ({@link import("./agent-definition.js").definitionMcpServers}). */
export declare function inheritedHostSeats(held: ReadonlyMap<string, McpHostSeat> | undefined, servers: ReadonlyArray<McpServerSpec>): Pick<RunInternals, "mcpHostSeats">;
/** The host-transport servers among `servers` that `held` (a waker's mount seats) has no seat for — each fails its dial on the woken leg
* (`config.mcp_host_seat_missing`), and the wake's receipt says so. */
export declare function seatlessHostServers(held: ReadonlyMap<string, McpHostSeat> | undefined, servers: ReadonlyArray<McpServerSpec>): string[];
/** A child's internals as a retained snapshot keeps them: without the seats that belong to whoever wakes it — the host seats (live objects of
* the run that held them), the placement fence (the target of the leg that spawned it), the objective's author (who wrote the spawn's
* prompt), the activity seat and the approval-hold seat (the spawner's, closures over its row). Each wake hands the waker's own: its seats
* ({@link inheritedHostSeats} over the waker's mount), its target, so a woken agent is minted where its waker is — the same answer a
* tier-3 revival of that agent gets — its author, since every resume states who wrote it, and the activity seat of the row it wakes.
* The manager seat goes too: a woken worker's cards go to its own seat (a wake is not the spawn the manager's seat was handed for). */
export declare function withoutWakerSeats(internals: RunInternals): RunInternals;
/** The chain a WAKE hands the leg it wakes — a retained snapshot's ({@link withoutWakerSeats}) and a tier-3 revival's (the waker's own
* chain): without any reading of the `sharedArtifactReads` setting. One rule: every wake is a run of its own and reads the seat
* again — neither the spawner's old `allow` nor the waker's outlives a setting changed since. Every other member stays as it is. */
export declare function wakeGate(gate: InheritedGate): InheritedGate;
/** Merge an agent definition's MCP servers with the lane's servers, returning both the mounted list and any shadowed entries. */
export declare function mergeDefinitionServers<S extends {
readonly name: string;
}>(handed: readonly S[] | undefined, own: readonly S[] | undefined): {
servers: S[];
dropped: S[];
};
/**
* The MCP servers a leg spawned as an agent definition is declared ({@link AgentDefinition.mcp}): the servers its lane hands it (the
* spawning run's it inherits, a workflow child's governed spec's) first, then each of the definition's own whose tool namespace none of
* those holds — a run holds one server per namespace, and a name the lane already declares for the leg names the lane's server. Every
* entry as declared; two of the definition's own under one namespace both stay, so the leg's mount refuses them as it refuses a task's
* own pair (`config.mcp_server_name_collision`). Which of their tools mount is the leg's own selector's question at its prepare.
*/
export declare function withDefinitionServers<S extends {
readonly name: string;
}>(handed: readonly S[] | undefined, own: readonly S[] | undefined): S[];
/**
* Announce shadowed agent-definition MCP entries through `mcpInjectionDroppedNotice`, once per (runner, root session address, agent,
* server) while that tuple is among the last `MAX_SHADOWED_ANNOUNCEMENTS_PER_RUNNER` announced (one pushed out is said again). The announcement is said on behalf of the spawning tree's leg `leg` and goes where that leg's children's notices go
* (`noticeAddressOf` over the root anchor `root` the children are handed): to the tree's root, under the runner's admission for that
* route — an announcement for a root occupant the root no longer holds is discarded and said, never delivered to its later occupant.
*/
export declare function announceShadowedDefinitionServers(args: {
readonly runner: Pick<RunnerSelfSeat, "emitNotice">;
readonly leg: string | undefined;
readonly root: {
readonly rootSessionId?: string;
readonly rootSessionIncarnation?: string;
};
readonly agent: string | undefined;
readonly dropped: ReadonlyArray<{
readonly name: string;
}>;
}): void;
/**
* A definition's own allowed-tools list as its leg's selector reads it: the list it wrote, extended by every tool of each MCP server it
* declares (`mcp__<server>__*`) — the servers an agent brings are its own whatever its list names, and its denied list still wins over them.
* No list (absent or `null`) stays no list.
*/
export declare function definitionAllowTools(def: Pick<AgentDefinition, "allowTools" | "mcp">): string[] | undefined;
/** THE selector layer a pair of governing lists makes, as frozen copies (`null` reads as absent); both are lists the spawn's check already read. */
export declare function selectorLayerOf(allow: readonly string[] | null | undefined, deny: readonly string[] | null | undefined): ToolSelectorLayer;
/** THE layer a definition's lists make for the leg launched as it (a delegated child's own, a workflow agent's definition layer). */
export declare function definitionSelectorLayer(def: Pick<AgentDefinition, "allowTools" | "denyTools" | "mcp">): ToolSelectorLayer;