Definitions
defineTool({ name, description, label?, tier, replay?, executionMode?, parameters, execute }): zodparameters;execute(args, context)gets the arguments parsed with them and aToolContext(ports,signal,scope,sessionId,toolCallId,output(),update()), and returns{ text, details? }: the text the model reads and JSON for clients.replayandexecutionModeare pi-durable's, passed through:replay: "safe"lets a call a crash cut off run again on reopen; the defaultunsafetells the model it was interrupted. The zod schema is converted once to the JSON Schema pi validates and coerces against; an optional parameter is offered to the model as nullable and anullit sends is dropped before validation, as chia'spi/tools.tsdoes.defineDelegate({ name, description, label?, tier, executionMode?, agent }): a tool whose call runs the sub-agentagentin a child session and returns its answer (see Delegates). It takes{ task: string }and isreplay: "safe".defineDeferredTool({ name, description, label?, tier, executionMode?, parameters, timeoutMs?, start, cancel? }): a tool whose call starts work elsewhere withstart, then parks until a reply reaches it ortimeoutMs(default 24 hours) passes, and returns the reply (see Deferred tools). It isreplay: "safe".
A tool is one of three kinds, by kind: app (what defineTool returns, run by its own execute),
delegate and deferred (run by the runtime). All three carry name, description, label and
tier, so the approval gate, a session's tool selection and its approval rule treat them alike.
defineAgent({ kind, instructions, tools, policy?, model? }): no ports or credentials, so a client or a capability listing can import it.policy.requiresApprovalis a list of tiers or a function of(tier, toolName).modelis a pi-durableModelRef({ provider, modelId }), never a key. The kind is held to the scope rule below.