class StructuredAnonymousAgent extends AnonymousAgent implements HasStructuredOutput

Traits

Properties

protected null|Message> $adHocMessages

The ad-hoc message history to send ahead of the next prompt.

from  Promptable
protected SerializableClosure|null $runtimeTools

The runtime tool override, replacing the tools the agent declares.

from  Promptable
protected array<int, object|string> $runtimeMiddleware

The runtime middleware wrapping the agent's declared middleware.

from  Promptable
SerializableClosure|null $schema

Methods

mixed
getSerializedPropertyValue(mixed $value, bool $withRelations = true)

Get the property value prepared for serialization.

mixed
getRestoredPropertyValue(mixed $value)

Get the restored property value after deserialization.

restoreCollection(ModelIdentifier $value)

Restore a queueable collection instance.

restoreModel(ModelIdentifier $value)

Restore the model from the model identifier instance.

getQueryForModelRestoration(Model $model, array|int|string $ids)

Get the query for model restoration.

array
__serialize()

Prepare the instance values for serialization.

void
__unserialize(array $values)

Restore the model after serialization.

mixed
getPropertyValue(ReflectionProperty $property)

Get the property value for the given property.

static Promptable
make(mixed ...$arguments)

Create a new instance of the agent.

prompt(AgentInput|UserMessage|Decisions|string $prompt, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null, int|null $timeout = null)

Invoke the agent with a given prompt, or resume a paused run with tool approval decisions.

stream(AgentInput|UserMessage|Decisions|string $prompt, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null, int|null $timeout = null)

Invoke the agent with a given prompt and return a streamable response.

queue(AgentInput|UserMessage|Decisions|string $prompt, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent in a queued job.

broadcast(AgentInput|UserMessage|Decisions|string $prompt, Channel|array $channels, array $attachments = [], bool $now = true, Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent with a given prompt and broadcast the streamed events.

broadcastNow(AgentInput|UserMessage|Decisions|string $prompt, Channel|array $channels, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent with a given prompt and broadcast the streamed events immediately.

broadcastOnQueue(AgentInput|UserMessage|Decisions|string $prompt, Channel|array $channels, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent with a given prompt and broadcast the streamed events.

withMessages(iterable $messages)

Set the ad-hoc message history to send ahead of the next prompt.

withTools(Closure|iterable $tools)

Replace the agent's declared tools for this instance.

withMiddleware(array $middleware)

Append middleware that wraps the agent's declared middleware for this instance.

array|null
resolveAgentTools()

Resolve the runtime tools for the next invocation, or null when the agent's declared tools apply.

array
getProvidersAndModels(Provider|Lab|array|string|null $provider, string|null $model)

Get the providers and models array for the given initial provider and model values.

string
getDefaultModelFor(TextProvider $provider)

Get the default model to use for the given provider.

int
getTimeout(int|null $timeout)

Get the timeout to use for the agent prompt.

static FakeTextGateway
fake(Closure|array $responses = [])

Fake the responses returned by the agent.

static void
assertPrompted(Closure|string $callback)

Assert that a prompt was received matching a given truth test.

static void
assertPromptedTimes(int $times = 1)

Assert that a certain number of prompts were received.

static void
assertNotPrompted(Closure|string $callback)

Assert that a prompt was not received matching a given truth test.

static void
assertNeverPrompted()

Assert that no prompts were received.

static void
assertQueued(Closure|string $callback)

Assert that a queued prompt was received matching a given truth test.

static void
assertNotQueued(Closure|string $callback)

Assert that a queued prompt was not received matching a given truth test.

static void
assertNeverQueued()

Assert that no queued prompts were received.

static bool
isFaked()

Determine if the agent is currently faked.

__construct(string $instructions, iterable $messages, iterable $tools, Closure|null $schema = null)

Create an ad-hoc agent with a structured output schema.

Stringable|string
instructions()

Get the agent instructions.

iterable
messages()

Get the conversation messages.

iterable
tools()

Get the available tools.

array
schema(JsonSchema $schema)

Get the structured output schema.

Details

protected mixed getSerializedPropertyValue(mixed $value, bool $withRelations = true)

Get the property value prepared for serialization.

Parameters

mixed $value
bool $withRelations

Return Value

mixed

protected mixed getRestoredPropertyValue(mixed $value)

Get the restored property value after deserialization.

Parameters

mixed $value

Return Value

mixed

protected Collection restoreCollection(ModelIdentifier $value)

Restore a queueable collection instance.

Parameters

ModelIdentifier $value

Return Value

Collection

Model restoreModel(ModelIdentifier $value)

Restore the model from the model identifier instance.

Parameters

ModelIdentifier $value

Return Value

Model

protected Builder getQueryForModelRestoration(Model $model, array|int|string $ids)

Get the query for model restoration.

Parameters

Model $model
array|int|string $ids

Return Value

Builder

in SerializesModels at line 18
array __serialize()

Prepare the instance values for serialization.

Return Value

array

in SerializesModels at line 69
void __unserialize(array $values)

Restore the model after serialization.

Parameters

array $values

Return Value

void

in SerializesModels at line 105
protected mixed getPropertyValue(ReflectionProperty $property)

Get the property value for the given property.

Unlike Laravel, this reads the stored value without running a get hook, as native serialization does.

Parameters

ReflectionProperty $property

Return Value

mixed

in Promptable at line 85
static Promptable make(mixed ...$arguments)

Create a new instance of the agent.

Parameters

mixed ...$arguments

Return Value

Promptable

in Promptable at line 99
AgentResponse prompt(AgentInput|UserMessage|Decisions|string $prompt, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null, int|null $timeout = null)

Invoke the agent with a given prompt, or resume a paused run with tool approval decisions.

Parameters

AgentInput|UserMessage|Decisions|string $prompt
array $attachments
Provider|Lab|array|string|null $provider
string|null $model
int|null $timeout

Return Value

AgentResponse

in Promptable at line 171
StreamableAgentResponse stream(AgentInput|UserMessage|Decisions|string $prompt, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null, int|null $timeout = null)

Invoke the agent with a given prompt and return a streamable response.

Parameters

AgentInput|UserMessage|Decisions|string $prompt
array $attachments
Provider|Lab|array|string|null $provider
string|null $model
int|null $timeout

Return Value

StreamableAgentResponse

in Promptable at line 320
QueuedAgentResponse queue(AgentInput|UserMessage|Decisions|string $prompt, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent in a queued job.

Parameters

AgentInput|UserMessage|Decisions|string $prompt
array $attachments
Provider|Lab|array|string|null $provider
string|null $model

Return Value

QueuedAgentResponse

in Promptable at line 370
StreamableAgentResponse broadcast(AgentInput|UserMessage|Decisions|string $prompt, Channel|array $channels, array $attachments = [], bool $now = true, Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent with a given prompt and broadcast the streamed events.

Parameters

AgentInput|UserMessage|Decisions|string $prompt
Channel|array $channels
array $attachments
bool $now
Provider|Lab|array|string|null $provider
string|null $model

Return Value

StreamableAgentResponse

in Promptable at line 381
StreamableAgentResponse broadcastNow(AgentInput|UserMessage|Decisions|string $prompt, Channel|array $channels, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent with a given prompt and broadcast the streamed events immediately.

Parameters

AgentInput|UserMessage|Decisions|string $prompt
Channel|array $channels
array $attachments
Provider|Lab|array|string|null $provider
string|null $model

Return Value

StreamableAgentResponse

in Promptable at line 389
QueuedAgentResponse broadcastOnQueue(AgentInput|UserMessage|Decisions|string $prompt, Channel|array $channels, array $attachments = [], Provider|Lab|array|string|null $provider = null, string|null $model = null)

Invoke the agent with a given prompt and broadcast the streamed events.

Parameters

AgentInput|UserMessage|Decisions|string $prompt
Channel|array $channels
array $attachments
Provider|Lab|array|string|null $provider
string|null $model

Return Value

QueuedAgentResponse

in Promptable at line 409
Promptable withMessages(iterable $messages)

Set the ad-hoc message history to send ahead of the next prompt.

Parameters

iterable $messages

Return Value

Promptable

in Promptable at line 429
Promptable withTools(Closure|iterable $tools)

Replace the agent's declared tools for this instance.

Parameters

Closure|iterable $tools

Return Value

Promptable

in Promptable at line 447
Promptable withMiddleware(array $middleware)

Append middleware that wraps the agent's declared middleware for this instance.

Parameters

array $middleware

Return Value

Promptable

in Promptable at line 461
protected array|null resolveAgentTools()

Resolve the runtime tools for the next invocation, or null when the agent's declared tools apply.

Return Value

array|null

in Promptable at line 573
protected array getProvidersAndModels(Provider|Lab|array|string|null $provider, string|null $model)

Get the providers and models array for the given initial provider and model values.

Parameters

Provider|Lab|array|string|null $provider
string|null $model

Return Value

array

in Promptable at line 609
protected string getDefaultModelFor(TextProvider $provider)

Get the default model to use for the given provider.

Parameters

TextProvider $provider

Return Value

string

in Promptable at line 627
protected int getTimeout(int|null $timeout)

Get the timeout to use for the agent prompt.

Parameters

int|null $timeout

Return Value

int

in Promptable at line 651
static FakeTextGateway fake(Closure|array $responses = [])

Fake the responses returned by the agent.

The fake affects subsequent calls for this agent in the worker.

Parameters

Closure|array $responses

Return Value

FakeTextGateway

in Promptable at line 660
static void assertPrompted(Closure|string $callback)

Assert that a prompt was received matching a given truth test.

Parameters

Closure|string $callback

Return Value

void

in Promptable at line 668
static void assertPromptedTimes(int $times = 1)

Assert that a certain number of prompts were received.

Parameters

int $times

Return Value

void

in Promptable at line 676
static void assertNotPrompted(Closure|string $callback)

Assert that a prompt was not received matching a given truth test.

Parameters

Closure|string $callback

Return Value

void

in Promptable at line 684
static void assertNeverPrompted()

Assert that no prompts were received.

Return Value

void

in Promptable at line 692
static void assertQueued(Closure|string $callback)

Assert that a queued prompt was received matching a given truth test.

Parameters

Closure|string $callback

Return Value

void

in Promptable at line 700
static void assertNotQueued(Closure|string $callback)

Assert that a queued prompt was not received matching a given truth test.

Parameters

Closure|string $callback

Return Value

void

in Promptable at line 708
static void assertNeverQueued()

Assert that no queued prompts were received.

Return Value

void

in Promptable at line 716
static bool isFaked()

Determine if the agent is currently faked.

Return Value

bool

at line 19
__construct(string $instructions, iterable $messages, iterable $tools, Closure|null $schema = null)

Create an ad-hoc agent with a structured output schema.

Parameters

string $instructions
iterable $messages
iterable $tools
Closure|null $schema

in AnonymousAgent at line 30
Stringable|string instructions()

Get the agent instructions.

Return Value

Stringable|string

in AnonymousAgent at line 38
iterable messages()

Get the conversation messages.

Return Value

iterable

in AnonymousAgent at line 46
iterable tools()

Get the available tools.

Return Value

iterable

at line 33
array schema(JsonSchema $schema)

Get the structured output schema.

Parameters

JsonSchema $schema

Return Value

array