UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

64 lines (63 loc) • 4.86 kB
import type { AgentDefinition, McpServerSpec } from "../core/types.js"; import type { PeerDeclarations } from "../core/peer-seat.js"; /** * THE judge of a definition's own MCP servers ({@link AgentDefinition.mcp}), asked wherever a definition is received — the delegation * tool's assembly, the `TaskSpec.agents` door, a workflow's `agentType` fold: the copy the door that judges `TaskSpec.mcp` makes of the * list ({@link snapshotAndValidateMcpEntries}; a declaration that door refuses is refused here, by the same code and sentence), and no * server with a host-supplied transport (`{ kind: "host" }`). A host seat reaches a leg only along the servers the leg inherits from the * run that spawns it, never from a definition, so such an entry would be a declaration no seat can ever answer: the whole definition is * refused (`config.mcp_host_seat_missing`), before any leg is spawned as it. */ export declare function definitionMcpServers(declared: unknown, agentName: unknown): McpServerSpec[]; /** * A definition as the engine receives it — where it is handed to the delegation tool and where a task carries it: its two tool-name * lists replaced by their one copy (the copy every later reader takes instead of the host's container), and its MCP server declarations * by the copy their one judge makes ({@link definitionMcpServers}) — a declaration it refuses refuses the definition here — and its * `thinking` is judged by the one tier judge (`judgeThinkingLevel`). */ export declare function snapshotDefinitionLists(def: AgentDefinition): AgentDefinition; /** What the one question about ONE agent definition answers: its copy as the engine receives it, or the coded refusal. */ export type AgentDefinitionJudgment = { ok: true; definition: AgentDefinition; } | { ok: false; error: Error; }; /** * A definition's own declarations, judged as a task's `TaskSpec.agents` receipt judges them ({@link snapshotDefinitionLists}: its two * tool-name lists, its MCP server declarations by their one judge, its `thinking` tier) — the agent sibling of `judgeMcpEntryDeclarations` / * `judgeA2aEntryDeclarations`, for a caller outside the engine that merges definitions of its own into a task's `TaskSpec.agents` and asks * first, so a definition the receipt would refuse is refused where it was declared — it IS the receipt, so the two cannot answer apart. * Never throws: every refusal of the receipt is the answer `ok: false` (a thrown value that is no error becomes the definition's own coded * refusal); the definition handed in is not changed. Not asked here (the roster's, where the delegation tool is mounted): whether its * name is one, collides with another definition or a reserved name, and whether a model word it names is in the catalog. */ export declare function judgeAgentDefinitionDeclarations(definition: AgentDefinition): AgentDefinitionJudgment; /** What a keeper is handed, as {@link heldDeclarationsOf} reads it: its own `mcp` and `a2a` lists, the definitions it received whole * (`agents`) and the tools it hands on (`tools`) — the engine's own copies, read by data member. */ export interface KeeperDeclarations { readonly mcp?: unknown; readonly a2a?: unknown; readonly agents?: unknown; readonly tools?: unknown; } /** Record what a tool carries — once, where the tool is minted, as the one keeper reading reads what it was minted with — and hand the * tool back. What the record says is what a keeper of the tool holds. */ export declare function recordCarried<T extends object>(tool: T, minted: KeeperDeclarations): T; /** * What a keeper holds (peer-seat.ts `holdPeerDeclarations`; which engine objects keep declarations is that module's note), the one reading * for every keeper and for the record a minted tool carries ({@link recordCarried}): its own `mcp` list, then the MCP servers of each * definition it received whole (`agents`), then the servers each tool it hands on (`tools`) carries; its own `a2a` list, then the peers each * of those tools carries. A tool's record is looked up by identity (the tool's, else its rebuild seam's) — no getter of a host's tool runs. * Data members only. */ export declare function heldDeclarationsOf(keeper: KeeperDeclarations): PeerDeclarations; /** * Validate + freeze a declarative sub-agent definition (design/38 1B). A thin, fail-fast factory: it * checks the only hard requirement (a non-empty `name`) and returns a shallow-frozen copy so a stored * definition can't be mutated out from under the registry. Registry-level checks (name uniqueness, * collision with reserved/tool names, model-ref resolution) happen when the set is handed to * {@link createSubagentTool}, where the tool name + model catalog are available. */ export declare function defineAgent(def: AgentDefinition): AgentDefinition;