Skip to main content

Overview

Tools in AIChatAgent can be divided into two categories:
  • Server tools: Have an execute function on the server. The AI SDK runs them automatically and the LLM continues responding in the same turn.
  • Client tools: No execute function on the server. The tool call is sent to the client via onToolCall, and the client provides the result. By default, this requires a new request to continue.
With autoContinueAfterToolResult, client tools can behave like server tools — the LLM calls a tool, the client executes it, and the server automatically continues the conversation in the same turn.

Server Setup

Define a tool without an execute function. The AI SDK will pause and send tool-input-available to the client:

Client Setup

Use onToolCall to handle client-side tool execution. Auto-continuation is enabled by default (autoContinueAfterToolResult: true), so the server automatically calls onChatMessage() again after receiving the tool result, letting the LLM continue in the same assistant message.

How It Works

1

User sends message

User: “What’s the weather near me?”Client sends message → Server calls LLM
2

LLM requests client tool

LLM decides to call getUserLocation (no server execute)Stream sends tool-input-available to client
3

Client executes tool

onToolCall fires → client gets geolocation → sends CF_AGENT_TOOL_RESULT
4

Server receives result

Server receives result with autoContinue: trueServer waits for the original stream to complete
5

Automatic continuation

Server calls onChatMessage() again (continuation)LLM sees the location result, calls getWeather (server execute)
6

Final response

LLM responds: “It’s sunny and 72°F near you!”Continuation parts are merged into the same assistant message
The user sees a single seamless response, even though it involved a client-side tool call mid-stream.

Without Auto-Continuation

When autoContinueAfterToolResult is set to false, the client must explicitly send a follow-up message after providing the tool result:
Use this when you want explicit control over when the conversation continues, or when tool results need user review before proceeding.

Combining with needsApproval

You can use client-side tools and approval together. For example, a tool that needs both user approval and browser execution:
The flow becomes: LLM calls tool → user approves → client executes → server auto-continues.

Custom Denial Messages

If the user denies the tool, you can provide a custom error message using addToolOutput with state: "output-error":