Tool calling
Register tools and handle tool.call / tool.result events so your agent can take real-world actions.
Give your agent the ability to look up information, call APIs, or trigger workflows by registering tools in session.tools. The agent decides when to invoke them and emits a tool.call; you execute the tool and reply with a tool.result. Wait until reply.done before sending it back.
Registering tools
Register tools by passing an array of tool definitions in session.tools on a session.update event. Each tool uses a flat format with type, name, description, and parameters at the top level.
You can update session.tools mid-session by sending another session.update. The new array replaces the previous one.
Handling tool calls
The key pattern: accumulate tool results, then send them all in reply.done, not immediately in tool.call. The agent speaks a transition phrase while waiting; sending results too early can cause timing issues.
If a tool call arrives and the user then interrupts the agent before reply.done completes normally, discard the pending tool results and wait for the next turn. Sending stale results can confuse the agent’s state.
What the agent does while tools run
While waiting for tool.result, the agent generates a short transition phrase based on the system prompt (for example, “Let me check that for you”). This keeps the conversation flowing naturally rather than leaving dead air. The phrasing is influenced by the system prompt, so you can steer it by including instructions like "While looking up information, say 'One moment'".
If the user interrupts during the transition phrase, you’ll receive reply.done with status: "interrupted". Discard any pending tool results. See Handling interruptions for the full pattern.