iOS SDK
Streaming Types
Reference for SendHandlers, ToolCall and ToolResult, the types you meet while an answer streams
While send or retry runs, the SDK reports progress through SendHandlers. Tool activity arrives as ToolCall and ToolResult values. This page lists each type and its fields.
SendHandlers
struct SendHandlers: Sendable
The handlers you set in the configure closure of send(_:conversationId:configure:) and retry(conversationId:messageId:configure:).
public struct SendHandlers: Sendable {
public var onTextDelta: (@Sendable (String) -> Void)?
public var onToolCall: (@Sendable (ToolCall) -> Void)?
public var onToolResult: (@Sendable (ToolResult) -> Void)?
public init()
}| Handler | Type | Description |
|---|---|---|
onTextDelta | (@Sendable (String) -> Void)? | Called for each piece of the agent's text. Add it to the current bubble. |
onToolCall | (@Sendable (ToolCall) -> Void)? | Called when the agent calls a tool: one you registered, or one the server runs. |
onToolResult | (@Sendable (ToolResult) -> Void)? | Called when a tool finishes, whether your handler or the server ran it. |
Handlers you don't set are ignored:
let response = try await client.send("Hello") { handlers in
handlers.onTextDelta = { piece in print(piece, terminator: "") }
// onToolCall and onToolResult not set
}ToolCall
struct ToolCall: Sendable, Equatable
Passed to onToolCall, and kept in MessagePart.toolCall.
public struct ToolCall: Sendable, Equatable {
public let id: String
public let name: String
public let input: JSONValue
}| Property | Type | Description |
|---|---|---|
id | String | An ID for this call. Use it to match the call with its ToolResult. |
name | String | The tool's name, which is the action's Action name. |
input | JSONValue | Everything the agent passed to the tool. See JSONValue. |
handlers.onToolCall = { call in
let orderNumber = call.input["order_number"]?.stringValue
Task { @MainActor in model.showToolCard(id: call.id, name: call.name, detail: orderNumber) }
}ToolResult
struct ToolResult: Sendable, Equatable
Passed to onToolResult, and kept in MessagePart.toolResult.
public struct ToolResult: Sendable, Equatable {
public let id: String
public let name: String
public let output: JSONValue
}| Property | Type | Description |
|---|---|---|
id | String | The id of the ToolCall this result answers. |
name | String | The tool's name. |
output | JSONValue | What the tool returned. An object with an error key means it failed. See JSONValue. |
handlers.onToolResult = { result in
let failed = result.output["error"] != nil
Task { @MainActor in model.completeToolCard(id: result.id, failed: failed) }
}Tool handlers
@Sendable (JSONValue) async throws -> JSONValueThe shape of a handler you register with client.tool(_:handler:): it receives the call's input and returns the result. See Client-Side Tools.
Lower-level stream
The SDK reads the answer stream itself and turns it into handler calls and the finished ChatResponse. The stream's events are not public types.