StreamCallbacks
struct StreamCallbacks: Sendable
The callbacks you pass to send(_:conversationId:configure:) and retry(conversationId:messageId:configure:).
Runs when the AI agent asks for a tool, before your handler runs.
Runs when a tool result is ready, whether it came from your handler or from the server.
There is no
onStart, onFinish, or onError callback. The async throws signature covers all three: the call returns a ChatResponse when it works and throws when it does not. See Streaming.ToolCallInfo
struct ToolCallInfo: Sendable
Passed to onToolCall.
Everything the AI agent passed to the tool. See JSONValue.
ToolResultInfo
struct ToolResultInfo: Sendable
Passed to onToolResult.
What the tool returned. An object with an
error key means it failed. See JSONValue.ToolHandler
client.tool(_:handler:). See Client-Side Tools.
Lower-Level Types
The types below are the pieces a reply is made of. The SDK handles them for you and gives you the results throughStreamCallbacks and ChatResponse, so you do not work with them directly. They are public so you can read what a reply contains and name the types in your own code.
StreamEvent
ToolCall
.toolCall. ToolCallInfo is the version you get in callbacks.
StreamFinishInfo
The details that arrive when a reply ends. Everything is optional, since the server may leave any of it out.The conversation this reply belongs to. On a new conversation, this is where the ID first arrives.
See FinishReason. Treated as
.stop when missing.ChatResponse that send returns.
Anything in a reply that the SDK does not recognize is skipped rather than treated as an error, so a shipped app keeps working as Chatbase adds new capabilities. A reply that cannot be read at all ends with
ChatError.decodingFailed.Related
Streaming
Using the callbacks in practice
Client-Side Tools
Registering tools the AI agent can run
ChatResponse
What a finished reply contains
JSONValue
Reading tool data