trait HandlesToolApprovals

Methods

array
pendingToolCalls(array $messages)

Get the unresolved tool calls in the latest assistant turn, plus the ids already answered.

array
appendApprovalResults(array $messages, array $toolResults)

Append a resume's tool results, merging into the pause turn's partial results so one assistant turn keeps one answering message.

array
settleAbandonedToolCalls(array $messages, bool $exceptLatestAssistantTurn = false)

Settle unresolved historical tool calls so the history remains replayable, optionally leaving the latest assistant turn for a resume to decide.

int
latestAssistantTurnIndex(array $messages)

Find the index of the latest assistant message, or the message count when there is none.

pendingApprovalsFor(Collection $toolCalls, Collection $approvals)

Build pending approval requests for the given tool calls.

Details

at line 24
protected array pendingToolCalls(array $messages)

Get the unresolved tool calls in the latest assistant turn, plus the ids already answered.

Parameters

array $messages

Return Value

array

at line 57
protected array appendApprovalResults(array $messages, array $toolResults)

Append a resume's tool results, merging into the pause turn's partial results so one assistant turn keeps one answering message.

Parameters

array $messages
array $toolResults

Return Value

array

at line 80
protected array settleAbandonedToolCalls(array $messages, bool $exceptLatestAssistantTurn = false)

Settle unresolved historical tool calls so the history remains replayable, optionally leaving the latest assistant turn for a resume to decide.

Parameters

array $messages
bool $exceptLatestAssistantTurn

Return Value

array

at line 140
protected int latestAssistantTurnIndex(array $messages)

Find the index of the latest assistant message, or the message count when there is none.

Parameters

array $messages

Return Value

int

at line 158
protected Collection pendingApprovalsFor(Collection $toolCalls, Collection $approvals)

Build pending approval requests for the given tool calls.

Parameters

Collection $toolCalls
Collection $approvals

Return Value

Collection