class AgentUserInteractionProtocol extends StreamProtocol

The Agent User Interaction (AG-UI) protocol.

See: https://docs.ag-ui.com/concepts/events

Properties

protected bool $started from  StreamProtocol
protected bool $errored from  StreamProtocol
protected Throwable|null $exception from  StreamProtocol
protected int $step
protected bool $finished
protected StreamableAgentResponse|null $response

Methods

parts(StreamableAgentResponse $response)

Get the protocol parts that represent the given response's events.

maskedErrorParts()

Get the protocol parts that terminate a stream interrupted by an exception.

array
headers()

Get the response headers for the protocol.

Response
response(StreamableAgentResponse $response)

Create an HTTP response that represents the given response using the protocol.

string|null
terminator()

Get the raw frame that terminates the stream, if any.

string
encode(array $part)

Encode the given protocol part as a server-sent event line.

string
json(mixed $value)

Encode the given value as JSON, substituting bytes a provider streamed as invalid UTF-8.

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

Create an Agent User Interaction protocol formatter.

yieldPart(array $part)

Get the given protocol part, preceded by the run started events when the run has not begun yet.

beginRunParts()

Get the events that begin the run and its first step.

array
startNextStepPart()

Get the event that starts the next step.

array
stepFinishedPart()

Get the event that finishes the current step.

array
runFinishedPart(array $attributes = [])

Get the event that finishes the run with the given additional attributes.

array
completionAttributes(TextUsage|null $usage, string|null $reason, string|null $provider, string|null $model)

Get the run finished attributes that report how the run completed.

array
interrupts(ToolApprovalRequest $event)

Get the interrupts that represent the given approval request's pending approvals.

array
toolCallParts(ToolCall $call)

Get the protocol parts that represent the given tool call.

array
mapEvent(StreamEvent $event)

Get the protocol parts that represent the given event.

array
preliminaryToolResultPart(ToolResult $event)

Get the protocol part for a tool still producing its output, which AG-UI has no tool result for.

array
toolResultPart(ToolResult $event)

Get the protocol part that represents the given tool result event.

array
citationParts(Citation $event)

Get the protocol parts that represent the given citation event.

string
toolResultContent(ToolResult $event)

Get the tool message content for the given tool result event.

Details

at line 61
protected Generator parts(StreamableAgentResponse $response)

Get the protocol parts that represent the given response's events.

Parameters

StreamableAgentResponse $response

Return Value

Generator

at line 151
protected Generator maskedErrorParts()

Get the protocol parts that terminate a stream interrupted by an exception.

Return Value

Generator

in StreamProtocol at line 38
protected array headers()

Get the response headers for the protocol.

Return Value

array

in StreamProtocol at line 49
Response response(StreamableAgentResponse $response)

Create an HTTP response that represents the given response using the protocol.

Parameters

StreamableAgentResponse $response

Return Value

Response

in StreamProtocol at line 88
protected string|null terminator()

Get the raw frame that terminates the stream, if any.

Return Value

string|null

in StreamProtocol at line 98
protected string encode(array $part)

Encode the given protocol part as a server-sent event line.

Parameters

array $part

Return Value

string

in StreamProtocol at line 106
protected string json(mixed $value)

Encode the given value as JSON, substituting bytes a provider streamed as invalid UTF-8.

Parameters

mixed $value

Return Value

string

at line 52
__construct(string|null $threadId = null, string|null $runId = null)

Create an Agent User Interaction protocol formatter.

Parameters

string|null $threadId
string|null $runId

at line 179
protected Generator yieldPart(array $part)

Get the given protocol part, preceded by the run started events when the run has not begun yet.

Parameters

array $part

Return Value

Generator

at line 193
protected Generator beginRunParts()

Get the events that begin the run and its first step.

Return Value

Generator

at line 214
protected array startNextStepPart()

Get the event that starts the next step.

Return Value

array

at line 224
protected array stepFinishedPart()

Get the event that finishes the current step.

Return Value

array

at line 235
protected array runFinishedPart(array $attributes = [])

Get the event that finishes the run with the given additional attributes.

Parameters

array $attributes

Return Value

array

at line 257
protected array completionAttributes(TextUsage|null $usage, string|null $reason, string|null $provider, string|null $model)

Get the run finished attributes that report how the run completed.

Parameters

TextUsage|null $usage
string|null $reason
string|null $provider
string|null $model

Return Value

array

at line 278
protected array interrupts(ToolApprovalRequest $event)

Get the interrupts that represent the given approval request's pending approvals.

Parameters

ToolApprovalRequest $event

Return Value

array

at line 295
protected array toolCallParts(ToolCall $call)

Get the protocol parts that represent the given tool call.

Parameters

ToolCall $call

Return Value

array

at line 309
protected array mapEvent(StreamEvent $event)

Get the protocol parts that represent the given event.

Parameters

StreamEvent $event

Return Value

array

at line 369
protected array preliminaryToolResultPart(ToolResult $event)

Get the protocol part for a tool still producing its output, which AG-UI has no tool result for.

Parameters

ToolResult $event

Return Value

array

at line 387
protected array toolResultPart(ToolResult $event)

Get the protocol part that represents the given tool result event.

Parameters

ToolResult $event

Return Value

array

at line 410
protected array citationParts(Citation $event)

Get the protocol parts that represent the given citation event.

Parameters

Citation $event

Return Value

array

at line 428
protected string toolResultContent(ToolResult $event)

Get the tool message content for the given tool result event.

Parameters

ToolResult $event

Return Value

string