StreamCallbacks
struct StreamCallbacks: Sendable
The callbacks you pass to send(_:conversationId:configure:) and retry(conversationId:messageId:configure:).
(@Sendable (String) async -> Void)?
Runs for each chunk of text. Add it to the current bubble.
(@Sendable (ToolCallInfo) async -> Void)?
Runs when the agent asks for a tool, before your handler runs.
(@Sendable (ToolResultInfo) async -> Void)?
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.
String
required
An ID for this tool call. Use it to match this call with its
ToolResultInfo.String
required
The tool’s name, which matches the Custom Action on your agent.
ToolResultInfo
struct ToolResultInfo: Sendable
Passed to onToolResult.
String
required
Matches the
toolCallId on the ToolCallInfo it belongs to.String
required
The tool’s name.
JSONValue
required
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.String?
The conversation this reply belongs to. On a new conversation, this is where the ID first arrives.
String?
The agent’s final message ID.
String?
The server’s ID for the user’s message.
String?
Who the reply belongs to. This fills in
client.currentUserId.FinishReason?
See FinishReason. Treated as
.stop when missing.Usage?
Credits used. Treated as
0 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 agent can run
ChatResponse
What a finished reply contains
JSONValue
Reading tool data
