class AgentUserInteraction

The Agent User Interaction (AG-UI) protocol's input side.

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

Methods

static Chat
chat(Request|array $input)

Create a chat instance from a RunAgentInput request or its array representation.

static array
fromMessages(iterable $messages)

Create messages from a list of AG-UI messages.

static Message
fromMessage(array $message)

Create a message from a single AG-UI message.

static Decisions|null
decisionsFrom(iterable $resume)

Create approval decisions from a RunAgentInput's resume entries.

static array
toClientState(iterable $messages)

Convert messages or conversation message models into state for hydrating an AG-UI client.

static array
uiMessagesFrom(iterable $messages)

Convert conversation history into AG-UI messages.

static array
toInterrupts(iterable $messages)

Get the open interrupts held by stored conversation messages.

static array
interrupt(string $id, string|null $reason = null, string|null $tool = null, array $arguments = [])

Get the interrupt that represents a pending tool approval.

static array
toolMessageFrom(array $toolResult, string|null $messageId = null)

Get the AG-UI tool message that represents a stored tool result.

static string|array
hydratedContent(Message|ConversationMessage $message)

Get the AG-UI content that represents a stored message's text and attachments.

static array
attachmentPartsFrom(Message|ConversationMessage $message)

Get the AG-UI content parts that represent a stored message's attachments.

static array|null
contentPartFrom(File $file)

Get the AG-UI content part that represents the given file.

static array
hydratedToolCalls(Message|ConversationMessage $message)

Get the AG-UI tool calls that represent a stored message's tool calls.

static array
flushToolResults(array $messages, array $toolResults)

Append a tool result message for the given buffered tool results.

static ToolResult|null
toolResultFrom(array $message, array $calls = [])

Create a tool result from an AG-UI tool message, naming it from the tool call it settles.

static Collection
toolCallsFrom(array $message)

Get the tool calls declared on an AG-UI assistant message.

static array
arguments(mixed $arguments)

Decode an AG-UI tool call's JSON encoded arguments.

static string
textFrom(mixed $content)

Get the text held by AG-UI message content.

static Collection
attachmentsFrom(mixed $content)

Get the attachments held by AG-UI message content.

static File|null
fileFrom(array $part)

Create a file instance from an AG-UI multimodal content part.

static string
json(mixed $value)

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

Details

at line 47
static Chat chat(Request|array $input)

Create a chat instance from a RunAgentInput request or its array representation.

Parameters

Request|array $input

Return Value

Chat

at line 58
static array fromMessages(iterable $messages)

Create messages from a list of AG-UI messages.

Parameters

iterable $messages

Return Value

array

at line 105
static Message fromMessage(array $message)

Create a message from a single AG-UI message.

Parameters

array $message

Return Value

Message

at line 122
static Decisions|null decisionsFrom(iterable $resume)

Create approval decisions from a RunAgentInput's resume entries.

Parameters

iterable $resume

Return Value

Decisions|null

at line 154
static array toClientState(iterable $messages)

Convert messages or conversation message models into state for hydrating an AG-UI client.

Parameters

iterable $messages

Return Value

array

at line 170
static protected array uiMessagesFrom(iterable $messages)

Convert conversation history into AG-UI messages.

Parameters

iterable $messages

Return Value

array

at line 223
static array toInterrupts(iterable $messages)

Get the open interrupts held by stored conversation messages.

Parameters

iterable $messages

Return Value

array

at line 255
static array interrupt(string $id, string|null $reason = null, string|null $tool = null, array $arguments = [])

Get the interrupt that represents a pending tool approval.

Parameters

string $id
string|null $reason
string|null $tool
array $arguments

Return Value

array

at line 281
static protected array toolMessageFrom(array $toolResult, string|null $messageId = null)

Get the AG-UI tool message that represents a stored tool result.

Parameters

array $toolResult
string|null $messageId

Return Value

array

at line 307
static protected string|array hydratedContent(Message|ConversationMessage $message)

Get the AG-UI content that represents a stored message's text and attachments.

Parameters

Message|ConversationMessage $message

Return Value

string|array

at line 326
static protected array attachmentPartsFrom(Message|ConversationMessage $message)

Get the AG-UI content parts that represent a stored message's attachments.

Parameters

Message|ConversationMessage $message

Return Value

array

at line 348
static protected array|null contentPartFrom(File $file)

Get the AG-UI content part that represents the given file.

Parameters

File $file

Return Value

array|null

at line 382
static protected array hydratedToolCalls(Message|ConversationMessage $message)

Get the AG-UI tool calls that represent a stored message's tool calls.

Parameters

Message|ConversationMessage $message

Return Value

array

at line 410
static protected array flushToolResults(array $messages, array $toolResults)

Append a tool result message for the given buffered tool results.

Parameters

array $messages
array $toolResults

Return Value

array

at line 423
static protected ToolResult|null toolResultFrom(array $message, array $calls = [])

Create a tool result from an AG-UI tool message, naming it from the tool call it settles.

Parameters

array $message
array $calls

Return Value

ToolResult|null

at line 451
static protected Collection toolCallsFrom(array $message)

Get the tool calls declared on an AG-UI assistant message.

Parameters

array $message

Return Value

Collection

at line 469
static protected array arguments(mixed $arguments)

Decode an AG-UI tool call's JSON encoded arguments.

Parameters

mixed $arguments

Return Value

array

at line 481
static protected string textFrom(mixed $content)

Get the text held by AG-UI message content.

Parameters

mixed $content

Return Value

string

at line 498
static protected Collection attachmentsFrom(mixed $content)

Get the attachments held by AG-UI message content.

Parameters

mixed $content

Return Value

Collection

at line 512
static protected File|null fileFrom(array $part)

Create a file instance from an AG-UI multimodal content part.

Parameters

array $part

Return Value

File|null

at line 547
static 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