trait BuildsTextRequests

Methods

array
buildTextRequestBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options)

Build the request body for the xAI Responses API.

array
buildStepBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options, StepContext $stepContext)

Build the request body for the current text generation step.

array
buildContinuationBody(string $previousResponseId, string $model, array $messages, array $tools, Provider $provider, array|null $schema, TextGenerationOptions|null $options = null)

Build a lightweight continuation body using previous_response_id.

array
mergeSharedResponsesRequestOptions(array $body, array $tools, array|null $schema, TextGenerationOptions|null $options, Provider $provider)

Apply options shared by full requests and previous_response_id continuations.

string|array
mapToolChoice(ToolChoice $choice)

Map a tool choice to the xAI Responses tool_choice shape.

array
extractToolResultsInput(array $messages)

Extract tool result items from the trailing ToolResultMessage for a continuation request.

array
buildSchemaFormat(array $schema, bool $strict)

Build the text format options for structured output.

Details

at line 21
protected array buildTextRequestBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options)

Build the request body for the xAI Responses API.

Parameters

Provider $provider
string $model
string|null $instructions
array $messages
array $tools
array|null $schema
TextGenerationOptions|null $options

Return Value

array

at line 40
protected array buildStepBody(Provider $provider, string $model, string|null $instructions, array $messages, array $tools, array|null $schema, TextGenerationOptions|null $options, StepContext $stepContext)

Build the request body for the current text generation step.

Parameters

Provider $provider
string $model
string|null $instructions
array $messages
array $tools
array|null $schema
TextGenerationOptions|null $options
StepContext $stepContext

Return Value

array

at line 60
protected array buildContinuationBody(string $previousResponseId, string $model, array $messages, array $tools, Provider $provider, array|null $schema, TextGenerationOptions|null $options = null)

Build a lightweight continuation body using previous_response_id.

Only sends tool results as input instead of replaying the full conversation.

Parameters

string $previousResponseId
string $model
array $messages
array $tools
Provider $provider
array|null $schema
TextGenerationOptions|null $options

Return Value

array

at line 81
protected array mergeSharedResponsesRequestOptions(array $body, array $tools, array|null $schema, TextGenerationOptions|null $options, Provider $provider)

Apply options shared by full requests and previous_response_id continuations.

Parameters

array $body
array $tools
array|null $schema
TextGenerationOptions|null $options
Provider $provider

Return Value

array

at line 122
protected string|array mapToolChoice(ToolChoice $choice)

Map a tool choice to the xAI Responses tool_choice shape.

Parameters

ToolChoice $choice

Return Value

string|array

at line 136
protected array extractToolResultsInput(array $messages)

Extract tool result items from the trailing ToolResultMessage for a continuation request.

Parameters

array $messages

Return Value

array

at line 158
protected array buildSchemaFormat(array $schema, bool $strict)

Build the text format options for structured output.

Parameters

array $schema
bool $strict

Return Value

array