class StreamableAgentResponse implements IteratorAggregate, Responsable

Properties

string|null $text
TextUsage|null $usage
StreamEvent> $events
Citation> $citations
string|null $conversationId
object|null $conversationUser
string|null $userMessageId
string|null $assistantMessageId
string $reasoning
protected array $thenCallbacks
protected array $catchCallbacks
protected StreamProtocol|null $protocol
protected StreamedAgentResponse|null $streamedResponse
protected bool $hasYielded
protected Meta $meta
protected null|Closure): mixed $contextRunner
protected null|Throwable): void $iterationFailureHandler

Methods

__construct(string $invocationId, Closure $generator, Meta|null $meta = null)

Create a new streamable agent response instance.

each(callable $callback)

Execute a callback over each event.

broadcast(Channel|array $channels, bool $now = true, array $except = [], string|null $invocationId = null)

Consume the stream and broadcast its events, batching deltas when enabled.

catch(callable $callback)

Provide a callback that should be invoked when the stream fails.

then(callable $callback)

Provide a callback that should be invoked when the stream completes.

withinConversation(string|null $conversationId, object|null $conversationUser = null)

Set the conversation UUID for this response.

adoptStateFrom(StreamedAgentResponse $response)

Adopt state from a completed streamed response.

usingContext(Closure|null $runner)

Use the captured operation context for stream production and callbacks.

wrapProducer(Closure $wrapper)

Wrap each execution of the producer, including its creation and disposal.

onIterationFailure(Closure $handler)

Handle failed or abandoned iterations, including completion callback failures.

mixed
runInContext(Closure $callback)

Run work in the captured operation context, when one was supplied.

usingProtocol(StreamProtocol $protocol)

Stream the response using the given stream protocol.

usingVercelDataProtocol(string|null $messageId = null)

Stream the response using the Vercel AI SDK data stream protocol.

usingAgentUserInteractionProtocol(string|null $threadId = null, string|null $runId = null)

Stream the response using the Agent User Interaction protocol.

Response
toResponse(Request $request)

Create an HTTP response that represents the object.

getIterator()

Get an iterator for the object.

contextualEvents()

Advance and dispose of the producer without leaking its context to consumers.

void
syncConversationFromStreamedResponse()

Synchronize the conversation state from the completed streamed response.

bool
hasYielded()

Determine whether this response has handed at least one event to a consumer.

Details

at line 77
__construct(string $invocationId, Closure $generator, Meta|null $meta = null)

Create a new streamable agent response instance.

Parameters

string $invocationId
Closure $generator
Meta|null $meta

at line 90
StreamableAgentResponse each(callable $callback)

Execute a callback over each event.

Parameters

callable $callback

Return Value

StreamableAgentResponse

at line 108
StreamableAgentResponse broadcast(Channel|array $channels, bool $now = true, array $except = [], string|null $invocationId = null)

internal  
 

Consume the stream and broadcast its events, batching deltas when enabled.

Parameters

Channel|array $channels
bool $now
array $except
string|null $invocationId

Return Value

StreamableAgentResponse

at line 178
StreamableAgentResponse catch(callable $callback)

Provide a callback that should be invoked when the stream fails.

Parameters

callable $callback

Return Value

StreamableAgentResponse

at line 188
StreamableAgentResponse then(callable $callback)

Provide a callback that should be invoked when the stream completes.

Parameters

callable $callback

Return Value

StreamableAgentResponse

at line 209
StreamableAgentResponse withinConversation(string|null $conversationId, object|null $conversationUser = null)

Set the conversation UUID for this response.

Parameters

string|null $conversationId
object|null $conversationUser

Return Value

StreamableAgentResponse

at line 220
StreamableAgentResponse adoptStateFrom(StreamedAgentResponse $response)

Adopt state from a completed streamed response.

Parameters

StreamedAgentResponse $response

Return Value

StreamableAgentResponse

at line 243
StreamableAgentResponse usingContext(Closure|null $runner)

internal  
 

Use the captured operation context for stream production and callbacks.

Parameters

Closure|null $runner

Return Value

StreamableAgentResponse

at line 257
StreamableAgentResponse wrapProducer(Closure $wrapper)

internal  
 

Wrap each execution of the producer, including its creation and disposal.

Parameters

Closure $wrapper

Return Value

StreamableAgentResponse

at line 273
StreamableAgentResponse onIterationFailure(Closure $handler)

internal  
 

Handle failed or abandoned iterations, including completion callback failures.

Parameters

Closure $handler

null indicates abandonment without an exception

Return Value

StreamableAgentResponse

at line 283
protected mixed runInContext(Closure $callback)

Run work in the captured operation context, when one was supplied.

Parameters

Closure $callback

Return Value

mixed

at line 291
StreamableAgentResponse usingProtocol(StreamProtocol $protocol)

Stream the response using the given stream protocol.

Parameters

StreamProtocol $protocol

Return Value

StreamableAgentResponse

at line 303
StreamableAgentResponse usingVercelDataProtocol(string|null $messageId = null)

Stream the response using the Vercel AI SDK data stream protocol.

The message ID is the assistant message being continued, not the "messageId" sent by useChat.

Parameters

string|null $messageId

Return Value

StreamableAgentResponse

at line 311
StreamableAgentResponse usingAgentUserInteractionProtocol(string|null $threadId = null, string|null $runId = null)

Stream the response using the Agent User Interaction protocol.

Parameters

string|null $threadId
string|null $runId

Return Value

StreamableAgentResponse

at line 319
Response toResponse(Request $request)

Create an HTTP response that represents the object.

Parameters

Request $request

Return Value

Response

at line 347
Traversable getIterator()

Get an iterator for the object.

Return Value

Traversable

at line 453
protected Generator contextualEvents()

Advance and dispose of the producer without leaking its context to consumers.

Return Value

Generator

at line 484
protected void syncConversationFromStreamedResponse()

Synchronize the conversation state from the completed streamed response.

Return Value

void

at line 495
bool hasYielded()

Determine whether this response has handed at least one event to a consumer.

Return Value

bool