Skip to Content
Motoko

What a session runs with

A session's model, thinking level and turn limit, and which of the agent's tools it may use and which of its calls wait for approval, are chosen per session and stored with it, so they hold after a restart. createSession() sets them, session.configure() changes any of them in one commit (a field left out keeps its value, null puts back the agent's), and session.settings() reads them back:

// A session that may only read, asks before every call of it, and takes at most five tool rounds a run.
const { id } = await instance.createSession({ tools: ["read_note"], requiresApproval: ["read"], maxTurns: 5 });
// Later: a bigger model that thinks harder, every tool but delete_note, and write-tier calls run without asking.
await instance.session(id).configure({
  model: { provider: "anthropic", modelId: "claude-opus-5" },
  thinkingLevel: "high",
  tools: { remove: ["delete_note"] },
  requiresApproval: { remove: ["write"] },
});
  • model is pi's ModelRef; null puts back the model a new session gets, the agent's, else the runtime's defaultModel, and rejects with a TypeError when there is neither. thinkingLevel is pi-ai's ModelThinkingLevel; null puts back pi-durable's default. A change to either applies from the run's next model request.
  • maxTurns bounds the tool rounds of one run: the round that reaches it runs its tools, then the run ends without an answer (run:end with reason: "error", code: "turn_limit" and error: "1 turn" or "N turns"), and continue carries it on. It is an integer, 1 or more; anything else rejects with pi-durable's RangeError and changes nothing, the other fields of the call included. null takes the limit away.
  • tools is a list of the agent's tool names, exactly those, or { remove }: every one but those. The model is offered only the session's tools, and a call of another one ends with an error result without running. It chooses among the agent's own tools: the tools of app extensions stay on whatever it says. It is pi-durable's per-conversation tool selection, which the runtime stores as the agent's tools to remove; a change applies from the run's next model request.
  • requiresApproval is a list of tiers, exactly the calls of those wait, or { add, remove }: the agent's policy with add tiers gated as well and remove tiers not. It applies to every call that reaches the gate after the change. A call already waiting keeps waiting, and its decision decides it whatever the rule says by then: a declined call never runs, and its question stays visible.

tools rejects with a TypeError for a tool the agent does not have, and requiresApproval for a tier no tool of the session carries, the app extensions' included, and neither changes anything. configure on a child session rejects with SessionOwnedError: its delegate chose what it runs with. The wire's createSession call takes none of these: what a session runs with is the app's to choose.