StreamableAgentResponse
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
Create a new streamable agent response instance.
Execute a callback over each event.
Provide a callback that should be invoked when the stream fails.
Provide a callback that should be invoked when the stream completes.
Set the conversation UUID for this response.
Use the captured operation context for stream production and callbacks.
Wrap each execution of the producer, including its creation and disposal.
Handle failed or abandoned iterations, including completion callback failures.
Stream the response using the Vercel AI SDK data stream protocol.
Stream the response using the Agent User Interaction protocol.
Get an iterator for the object.
Advance and dispose of the producer without leaking its context to consumers.
Synchronize the conversation state from the completed streamed response.
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.
at line 90
StreamableAgentResponse
each(callable $callback)
Execute a callback over each event.
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.
at line 178
StreamableAgentResponse
catch(callable $callback)
Provide a callback that should be invoked when the stream fails.
at line 188
StreamableAgentResponse
then(callable $callback)
Provide a callback that should be invoked when the stream completes.
at line 209
StreamableAgentResponse
withinConversation(string|null $conversationId, object|null $conversationUser = null)
Set the conversation UUID for this response.
at line 220
StreamableAgentResponse
adoptStateFrom(StreamedAgentResponse $response)
Adopt state from a completed streamed response.
at line 243
StreamableAgentResponse
usingContext(Closure|null $runner)
| internal |
Use the captured operation context for stream production and callbacks.
at line 257
StreamableAgentResponse
wrapProducer(Closure $wrapper)
| internal |
Wrap each execution of the producer, including its creation and disposal.
at line 273
StreamableAgentResponse
onIterationFailure(Closure $handler)
| internal |
Handle failed or abandoned iterations, including completion callback failures.
at line 283
protected mixed
runInContext(Closure $callback)
Run work in the captured operation context, when one was supplied.
at line 291
StreamableAgentResponse
usingProtocol(StreamProtocol $protocol)
Stream the response using the given stream protocol.
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.
at line 311
StreamableAgentResponse
usingAgentUserInteractionProtocol(string|null $threadId = null, string|null $runId = null)
Stream the response using the Agent User Interaction protocol.
at line 319
Response
toResponse(Request $request)
Create an HTTP response that represents the object.
at line 347
Traversable
getIterator()
Get an iterator for the object.
at line 453
protected Generator
contextualEvents()
Advance and dispose of the producer without leaking its context to consumers.
at line 484
protected void
syncConversationFromStreamedResponse()
Synchronize the conversation state from the completed streamed response.
at line 495
bool
hasYielded()
Determine whether this response has handed at least one event to a consumer.