Skip to Content
Motoko

Definitions

  • defineTool({ name, description, label?, tier, replay?, executionMode?, parameters, execute }): zod parameters; execute(args, context) gets the arguments parsed with them and a ToolContext (ports, signal, scope, sessionId, toolCallId, output(), update()), and returns { text, details? }: the text the model reads and JSON for clients. replay and executionMode are pi-durable's, passed through: replay: "safe" lets a call a crash cut off run again on reopen; the default unsafe tells 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 a null it sends is dropped before validation, as chia's pi/tools.ts does.
  • defineDelegate({ name, description, label?, tier, executionMode?, agent }): a tool whose call runs the sub-agent agent in a child session and returns its answer (see Delegates). It takes { task: string } and is replay: "safe".
  • defineDeferredTool({ name, description, label?, tier, executionMode?, parameters, timeoutMs?, start, cancel? }): a tool whose call starts work elsewhere with start, then parks until a reply reaches it or timeoutMs (default 24 hours) passes, and returns the reply (see Deferred tools). It is replay: "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.requiresApproval is a list of tiers or a function of (tier, toolName). model is a pi-durable ModelRef ({ provider, modelId }), never a key. The kind is held to the scope rule below.