Skip to content
QwryAI
Documentation
Pages

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:).

Swift
public struct SendHandlers: Sendable {
    public var onTextDelta: (@Sendable (String) -> Void)?
    public var onToolCall: (@Sendable (ToolCall) -> Void)?
    public var onToolResult: (@Sendable (ToolResult) -> Void)?
    public init()
}
HandlerTypeDescription
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:

Swift
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.

Swift
public struct ToolCall: Sendable, Equatable {
    public let id: String
    public let name: String
    public let input: JSONValue
}
PropertyTypeDescription
idStringAn ID for this call. Use it to match the call with its ToolResult.
nameStringThe tool's name, which is the action's Action name.
inputJSONValueEverything the agent passed to the tool. See JSONValue.
Swift
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.

Swift
public struct ToolResult: Sendable, Equatable {
    public let id: String
    public let name: String
    public let output: JSONValue
}
PropertyTypeDescription
idStringThe id of the ToolCall this result answers.
nameStringThe tool's name.
outputJSONValueWhat the tool returned. An object with an error key means it failed. See JSONValue.
Swift
handlers.onToolResult = { result in
    let failed = result.output["error"] != nil
    Task { @MainActor in model.completeToolCard(id: result.id, failed: failed) }
}

Tool handlers

Swift
@Sendable (JSONValue) async throws -> JSONValue

The 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.

Explore the documentation