class AiManager extends MultipleInstanceManager

Traits

Constants

HTTP_CONNECTION

ON_DEMAND_PROVIDERS_CONTEXT_KEY

Properties

protected Repository $config

The configuration repository instance.

from  MultipleInstanceManager
protected array $instances

The array of resolved instances.

from  MultipleInstanceManager
protected array $customCreators

The registered custom instance creators.

from  MultipleInstanceManager
protected string $driverKey

The key name of the "driver" equivalent configuration option.

from  MultipleInstanceManager
protected array $fakeAgentGateways

All of the registered fake agent gateways.

from  InteractsWithFakeAgents
protected array $recordedPrompts

All of the recorded agent prompts.

from  InteractsWithFakeAgents
protected array $recordedQueuedPrompts

All of the recorded agent prompts that were queued.

from  InteractsWithFakeAgents
protected FakeAudioGateway|null $fakeAudioGateway

The fake audio gateway instance.

from  InteractsWithFakeAudio
protected array $recordedAudioGenerations

All of the recorded audio generations.

from  InteractsWithFakeAudio
protected array $recordedQueuedAudioGenerations

All of the recorded audio generations that were queued.

from  InteractsWithFakeAudio
protected FakeClassificationGateway|null $fakeClassificationGateway

The fake classification gateway instance.

from  InteractsWithFakeClassification
protected array $recordedClassifications

All of the recorded classifications.

from  InteractsWithFakeClassification
protected FakeEmbeddingGateway|null $fakeEmbeddingGateway

The fake embedding gateway instance.

from  InteractsWithFakeEmbeddings
protected array $recordedEmbeddingsGenerations

All of the recorded embeddings generations.

from  InteractsWithFakeEmbeddings
protected array $recordedQueuedEmbeddingsGenerations

All of the recorded embeddings generations that were queued.

from  InteractsWithFakeEmbeddings
protected FakeFileGateway|null $fakeFileGateway

The fake file gateway instance.

from  InteractsWithFakeFiles
protected array $recordedFileUploads

All of the recorded file uploads.

from  InteractsWithFakeFiles
protected array $recordedFileDeletions

All of the recorded file deletions.

from  InteractsWithFakeFiles
protected FakeImageGateway|null $fakeImageGateway

The fake image gateway instance.

from  InteractsWithFakeImages
protected array $recordedImageGenerations

All of the recorded image generations.

from  InteractsWithFakeImages
protected array $recordedQueuedImageGenerations

All of the recorded image generations that were queued.

from  InteractsWithFakeImages
protected FakeRerankingGateway|null $fakeRerankingGateway

The fake reranking gateway instance.

from  InteractsWithFakeReranking
protected array $recordedRerankings

All of the recorded rerankings.

from  InteractsWithFakeReranking
protected FakeStoreGateway|null $fakeStoreGateway

The fake store gateway instance.

from  InteractsWithFakeStores
protected array $recordedStoreCreations

All of the recorded store creations.

from  InteractsWithFakeStores
protected array $recordedStoreDeletions

All of the recorded store deletions.

from  InteractsWithFakeStores
protected array $recordedFileAdditions

All of the recorded file additions.

from  InteractsWithFakeStores
protected array $recordedFileRemovals

All of the recorded file removals.

from  InteractsWithFakeStores
protected FakeTranscriptionGateway|null $fakeTranscriptionGateway

The fake transcription gateway instance.

from  InteractsWithFakeTranscriptions
protected array $recordedTranscriptionGenerations

All of the recorded transcription generations.

from  InteractsWithFakeTranscriptions
protected array $recordedQueuedTranscriptionGenerations

All of the recorded transcription generations that were queued.

from  InteractsWithFakeTranscriptions
protected null|Closure(string, array): array $providerConfigResolver
protected string|null $conversationPartitionColumn
protected null|Closure(): null|int|string $conversationPartitionResolver
protected null|Closure(): ?string $embeddingsCacheScopeResolver
protected null|Closure $contextCapture

Methods

Closure|null
bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

__construct(Application $app)

Create a new manager instance.

string
getDefaultInstance()

Get the default instance name.

void
setDefaultInstance(string $name)

Set the default instance name.

array
getInstanceConfig(string $name)

Get the instance specific configuration.

mixed
instance(string|null $name = null)

Get a provider without retaining operation-owned credentials in the worker.

mixed
get(string $name)

Attempt to get an instance from the local cache.

mixed
resolve(string $name)

Resolve the given instance.

mixed
callCustomCreator(array $config)

Call a custom instance creator.

forgetInstance(array|string|null $name = null)

Forget resolved providers while retaining their configuration.

void
purge(string|null $name = null)

Remove a resolved provider.

extend(string $name, Closure $callback)

Register a custom instance creator Closure.

setApplication(Application $app)

Set the application instance used by the manager.

mixed
__call(string $method, array $parameters)

Dynamically call the default instance.

fakeAgent(string $agent, Closure|array $responses = [])

Fake the responses returned by the given agent.

bool
hasFakeGatewayFor(Agent|string $agent)

Determine if the given agent has been faked.

fakeGatewayFor(Agent $agent)

Get a fake gateway instance for the given agent.

recordPrompt(AgentPrompt|QueuedAgentPrompt $prompt)

Record the given prompt for the faked agent.

assertAgentWasPrompted(string $agent, Closure|string $callback, array|null $prompts = null, string|null $message = null)

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

assertAgentWasPromptedTimes(string $agent, int $times = 1)

Assert that a certain number of prompts were received.

assertAgentWasQueued(string $agent, Closure|string $callback)

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

assertAgentNotPrompted(string $agent, Closure|string $callback, array|null $prompts = null, string|null $message = null)

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

assertAgentNotQueued(string $agent, Closure|string $callback)

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

assertAgentNeverPrompted(string $agent)

Assert that no prompts were received.

assertAgentNeverQueued(string $agent)

Assert that no queued prompts were received.

fakeAudio(Closure|array $responses = [])

Fake audio generation.

assertAudioGenerated(Closure $callback)

Assert that audio was generated matching a given truth test.

assertAudioNotGenerated(Closure $callback)

Assert that audio was not generated matching a given truth test.

assertNoAudioGenerated()

Assert that no audio was generated.

assertAudioQueued(Closure $callback)

Assert that a queued audio generation was recorded matching a given truth test.

assertAudioNotQueued(Closure $callback)

Assert that a queued audio generation was not recorded matching a given truth test.

assertNoAudioQueued()

Assert that no queued audio generations were recorded.

bool
audioIsFaked()

Determine if audio generation is faked.

fakeAudioGateway()

Get the fake audio gateway.

fakeClassification(Closure|array $responses = [])

Fake classification operations.

assertClassified(Closure $callback)

Assert that a classification was performed matching a given truth test.

assertNotClassified(Closure $callback)

Assert that a classification was not performed matching a given truth test.

assertNothingClassified()

Assert that no classifications were performed.

bool
classificationIsFaked()

Determine if classification is faked.

fakeEmbeddings(Closure|array $responses = [])

Fake embeddings generation.

assertEmbeddingsGenerated(Closure $callback)

Assert that embeddings were generated matching a given truth test.

assertEmbeddingsNotGenerated(Closure $callback)

Assert that embeddings were not generated matching a given truth test.

assertEmbeddingsQueued(Closure $callback)

Assert that a queued embeddings generation was recorded matching a given truth test.

assertEmbeddingsNotQueued(Closure $callback)

Assert that a queued embeddings generation was not recorded matching a given truth test.

assertNoEmbeddingsQueued()

Assert that no queued embeddings generations were recorded.

bool
embeddingsAreFaked()

Determine if embeddings generation is faked.

fakeEmbeddingGateway()

Get the fake embedding gateway.

fakeFiles(Closure|array $responses = [])

Fake file operations.

recordFileDeletion(string $fileId)

Record a file deletion.

assertFileUploaded(Closure $callback)

Assert that a file was uploaded matching a given truth test.

assertFileNotUploaded(Closure $callback)

Assert that a file was not uploaded matching a given truth test.

assertNoFilesUploaded()

Assert that no files were uploaded.

assertFileDeleted(Closure|string $callback)

Assert that a file was deleted matching a given truth test.

assertFileNotDeleted(Closure|string $callback)

Assert that a file was not deleted matching a given truth test.

assertNoFilesDeleted()

Assert that no files were deleted.

bool
filesAreFaked()

Determine if file operations are faked.

fakeFileGateway()

Get the fake file gateway.

fakeImages(Closure|array $responses = [])

Fake image generation.

assertImageGenerated(Closure $callback)

Assert that an image was generated matching a given truth test.

assertImageNotGenerated(Closure $callback)

Assert that an image was not generated matching a given truth test.

assertNoImagesGenerated()

Assert that no images were generated.

assertImageQueued(Closure $callback)

Assert that a queued image generation was recorded matching a given truth test.

assertImageNotQueued(Closure $callback)

Assert that a queued image generation was not recorded matching a given truth test.

assertNoImagesQueued()

Assert that no queued image generations were recorded.

bool
imagesAreFaked()

Determine if image generation is faked.

fakeImageGateway()

Get the fake image gateway.

fakeReranking(Closure|array $responses = [])

Fake reranking operations.

assertReranked(Closure $callback)

Assert that a reranking was performed matching a given truth test.

assertNotReranked(Closure $callback)

Assert that a reranking was not performed matching a given truth test.

assertNothingReranked()

Assert that no rerankings were performed.

bool
rerankingIsFaked()

Determine if reranking is faked.

fakeRerankingGateway()

Get the fake reranking gateway.

fakeStores(Closure|array $responses = [])

Fake store operations.

recordStoreCreation(string $name, string|null $description = null, Collection|null $fileIds = null, DateInterval|null $expiresWhenIdleFor = null)

Record a store creation.

recordStoreDeletion(string $storeId)

Record a store deletion.

recordFileAddition(string $storeId, string $fileId, StorableFile|UploadedFile|HasProviderId|string $file)

Record a file addition to a store.

recordFileRemoval(string $storeId, string $fileId)

Record a file removal from a store.

assertStoreCreated(Closure|string $callback)

Assert that a store was created matching a given truth test.

assertStoreNotCreated(Closure|string $callback)

Assert that a store was not created matching a given truth test.

assertNoStoresCreated()

Assert that no stores were created.

assertStoreDeleted(Closure|string $callback)

Assert that a store was deleted matching a given truth test.

assertStoreNotDeleted(Closure|string $callback)

Assert that a store was not deleted matching a given truth test.

assertNoStoresDeleted()

Assert that no stores were deleted.

assertFileAddedToStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was added to a store matching a given truth test.

assertFileNotAddedToStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was not added to a store matching a given truth test.

assertFileRemovedFromStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was removed from a store matching a given truth test.

assertFileNotRemovedFromStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was not removed from a store matching a given truth test.

fileMatchingCallback(Closure|string $storeId, string|null $fileId)

Get a callback for matching store and file IDs.

bool
fileIdMatches(StorableFile|UploadedFile|HasProviderId|string $file, string|null $expectedFileId)

Determine if the given file matches the expected file ID.

bool
storesAreFaked()

Determine if store operations are faked.

fakeStoreGateway()

Get the fake store gateway.

fakeTranscriptions(Closure|array $responses = [])

Fake transcription generation.

assertTranscriptionGenerated(Closure $callback)

Assert that a transcription was generated matching a given truth test.

assertTranscriptionNotGenerated(Closure $callback)

Assert that a transcription was not generated matching a given truth test.

assertTranscriptionQueued(Closure $callback)

Assert that a queued transcription generation was recorded matching a given truth test.

assertTranscriptionNotQueued(Closure $callback)

Assert that a queued transcription generation was not recorded matching a given truth test.

assertNoTranscriptionsQueued()

Assert that no queued transcription generations were recorded.

bool
transcriptionsAreFaked()

Determine if transcription generation is faked.

build(array $config)

Build an on-demand provider instance from the given configuration.

Provider|null
onDemandProvider(string $name)

Get an on-demand provider from the current operation, if one exists.

array
resolveOnDemandProviders(array $providers)

Capture on-demand providers before an earlier failover attempt can replace them.

audioProvider(Provider|string|null $name = null)

Get an audio provider instance by name.

fakeableAudioProvider(Provider|string|null $name = null)

Get an audio provider instance, using a fake gateway if audio is faked.

classificationProvider(Provider|string|null $name = null)

Get a classification provider instance by name.

fakeableClassificationProvider(Provider|string|null $name = null)

Get a classification provider instance, using a fake gateway if classification is faked.

embeddingProvider(Provider|string|null $name = null)

Get an embedding provider instance by name.

fakeableEmbeddingProvider(Provider|string|null $name = null)

Get an embedding provider instance, using a fake gateway if embeddings are faked.

rerankingProvider(Provider|string|null $name = null)

Get a reranking provider instance by name.

fakeableRerankingProvider(Provider|string|null $name = null)

Get a reranking provider instance, using a fake gateway if reranking is faked.

imageProvider(Provider|string|null $name = null)

Get an image provider instance by name.

fakeableImageProvider(Provider|string|null $name = null)

Get an image provider instance, using a fake gateway if images are faked.

textProvider(Provider|string|null $name = null)

Get a text provider instance by name.

textProviderFor(Agent $agent, Provider|string|null $name = null)

Get a provider instance for an agent by name.

transcriptionProvider(Provider|string|null $name = null)

Get a transcription provider instance by name.

fakeableTranscriptionProvider(Provider|string|null $name = null)

Get a transcription provider instance, using a fake gateway if transcriptions are faked.

fileProvider(Provider|string|null $name = null)

Get a file provider instance by name.

fakeableFileProvider(Provider|string|null $name = null)

Get a file provider instance, using a fake gateway if files are faked.

storeProvider(Provider|string|null $name = null)

Get a store provider instance by name.

fakeableStoreProvider(Provider|string|null $name = null)

Get a store provider instance, using a fake gateway if stores are faked.

createAnthropicDriver(array $config)

Create an Anthropic powered instance.

createAzureDriver(array $config)

Create an Azure OpenAI powered instance.

createBedrockDriver(array $config)

Create an AWS Bedrock powered instance.

createCohereDriver(array $config)

Create a Cohere powered instance.

createDeepseekDriver(array $config)

Create a DeepSeek powered instance.

createElevenDriver(array $config)

Create an ElevenLabs powered instance.

createGeminiDriver(array $config)

Create a Gemini powered instance.

createGroqDriver(array $config)

Create a Groq powered instance.

createJinaDriver(array $config)

Create a Jina powered instance.

createMistralDriver(array $config)

Create a Mistral AI powered instance.

createOllamaDriver(array $config)

Create an Ollama powered instance.

createOpenaiDriver(array $config)

Create an OpenAI powered instance.

createOpenaiCompatibleDriver(array $config)

Create an OpenAI-compatible powered instance.

createOpenrouterDriver(array $config)

Create an OpenRouter powered instance.

createTypesafeDriver(array $config)

Create a TypeSafe powered instance.

createVoyageaiDriver(array $config)

Create a VoyageAI powered instance.

createXaiDriver(array $config)

Create an xAI powered instance.

mixed
ensureProviderSupports(string $contract, string $capability, Provider|string|null $name)

Get a provider instance by name, ensuring it implements the given capability contract.

void
resolveProviderConfigUsing(Closure $resolver)

Configure the provider configuration resolver.

void
resolveConversationPartitionUsing(string $column, Closure $resolver)

Configure the conversation row partition resolver.

string|null
conversationPartitionColumn()

Get the configured conversation partition column.

int|string|null
conversationPartition()

Resolve the current conversation partition.

void
resolveEmbeddingsCacheScopeUsing(Closure $resolver)

Configure the embeddings cache scope resolver.

string|null
embeddingsCacheScope()

Resolve the current embeddings cache scope.

void
captureContextUsing(Closure $capture)

Configure context capture for deferred operations.

Closure|null
captureContext()

Capture a runner for the current operation's context.

void
flushState()

Flush the on-demand providers built during the current operation.

Details

protected Closure|null bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

Parameters

Closure $callback

Return Value

Closure|null

Exceptions

ReflectionException

__construct(Application $app)

Create a new manager instance.

Parameters

Application $app

at line 636
string getDefaultInstance()

Get the default instance name.

Return Value

string

at line 656
void setDefaultInstance(string $name)

Set the default instance name.

This changes the worker's default provider for every request.

Parameters

string $name

Return Value

void

at line 665
array getInstanceConfig(string $name)

Get the instance specific configuration.

Parameters

string $name

Return Value

array

at line 113
mixed instance(string|null $name = null)

Get a provider without retaining operation-owned credentials in the worker.

Parameters

string|null $name

Return Value

mixed

protected mixed get(string $name)

Attempt to get an instance from the local cache.

Parameters

string $name

Return Value

mixed

protected mixed resolve(string $name)

Resolve the given instance.

Parameters

string $name

Return Value

mixed

Exceptions

InvalidArgumentException
RuntimeException

protected mixed callCustomCreator(array $config)

Call a custom instance creator.

Parameters

array $config

Return Value

mixed

at line 181
MultipleInstanceManager forgetInstance(array|string|null $name = null)

Forget resolved providers while retaining their configuration.

Forgetting a configured provider affects every request on the worker; on-demand providers belong to the current operation.

Parameters

array|string|null $name

Return Value

MultipleInstanceManager

at line 201
void purge(string|null $name = null)

Remove a resolved provider.

Forgetting a configured provider affects every request on the worker; on-demand providers belong to the current operation.

Parameters

string|null $name

Return Value

void

MultipleInstanceManager extend(string $name, Closure $callback)

Register a custom instance creator Closure.

Anonymous closures run in this manager's class scope; non-static closures also receive the manager as $this.

The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent instance resolution.

Parameters

string $name
Closure $callback

Return Value

MultipleInstanceManager

MultipleInstanceManager setApplication(Application $app)

Set the application instance used by the manager.

Swaps the singleton's application and configuration references without rebuilding resolved instances; per-request use races across coroutines and breaks every concurrent resolution through this manager.

Parameters

Application $app

Return Value

MultipleInstanceManager

mixed __call(string $method, array $parameters)

Dynamically call the default instance.

Parameters

string $method
array $parameters

Return Value

mixed

FakeTextGateway fakeAgent(string $agent, Closure|array $responses = [])

Fake the responses returned by the given agent.

On the shared manager, the fake gateway affects every request.

Parameters

string $agent
Closure|array $responses

Return Value

FakeTextGateway

bool hasFakeGatewayFor(Agent|string $agent)

Determine if the given agent has been faked.

Parameters

Agent|string $agent

Return Value

bool

FakeTextGateway fakeGatewayFor(Agent $agent)

Get a fake gateway instance for the given agent.

Parameters

Agent $agent

Return Value

FakeTextGateway

InteractsWithFakeAgents recordPrompt(AgentPrompt|QueuedAgentPrompt $prompt)

Record the given prompt for the faked agent.

Recorded prompts remain on the worker-shared manager.

Parameters

AgentPrompt|QueuedAgentPrompt $prompt

Return Value

InteractsWithFakeAgents

InteractsWithFakeAgents assertAgentWasPrompted(string $agent, Closure|string $callback, array|null $prompts = null, string|null $message = null)

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

Parameters

string $agent
Closure|string $callback
array|null $prompts
string|null $message

Return Value

InteractsWithFakeAgents

InteractsWithFakeAgents assertAgentWasPromptedTimes(string $agent, int $times = 1)

Assert that a certain number of prompts were received.

Parameters

string $agent
int $times

Return Value

InteractsWithFakeAgents

InteractsWithFakeAgents assertAgentWasQueued(string $agent, Closure|string $callback)

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

Parameters

string $agent
Closure|string $callback

Return Value

InteractsWithFakeAgents

InteractsWithFakeAgents assertAgentNotPrompted(string $agent, Closure|string $callback, array|null $prompts = null, string|null $message = null)

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

Parameters

string $agent
Closure|string $callback
array|null $prompts
string|null $message

Return Value

InteractsWithFakeAgents

InteractsWithFakeAgents assertAgentNotQueued(string $agent, Closure|string $callback)

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

Parameters

string $agent
Closure|string $callback

Return Value

InteractsWithFakeAgents

InteractsWithFakeAgents assertAgentNeverPrompted(string $agent)

Assert that no prompts were received.

Parameters

string $agent

Return Value

InteractsWithFakeAgents

InteractsWithFakeAgents assertAgentNeverQueued(string $agent)

Assert that no queued prompts were received.

Parameters

string $agent

Return Value

InteractsWithFakeAgents

FakeAudioGateway fakeAudio(Closure|array $responses = [])

Fake audio generation.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeAudioGateway

InteractsWithFakeAudio recordAudioGeneration(AudioPrompt|QueuedAudioPrompt $prompt)

Record an audio generation.

Recorded prompts remain on the worker-shared manager.

Parameters

AudioPrompt|QueuedAudioPrompt $prompt

Return Value

InteractsWithFakeAudio

InteractsWithFakeAudio assertAudioGenerated(Closure $callback)

Assert that audio was generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeAudio

InteractsWithFakeAudio assertAudioNotGenerated(Closure $callback)

Assert that audio was not generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeAudio

InteractsWithFakeAudio assertNoAudioGenerated()

Assert that no audio was generated.

Return Value

InteractsWithFakeAudio

InteractsWithFakeAudio assertAudioQueued(Closure $callback)

Assert that a queued audio generation was recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeAudio

InteractsWithFakeAudio assertAudioNotQueued(Closure $callback)

Assert that a queued audio generation was not recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeAudio

InteractsWithFakeAudio assertNoAudioQueued()

Assert that no queued audio generations were recorded.

Return Value

InteractsWithFakeAudio

bool audioIsFaked()

Determine if audio generation is faked.

Return Value

bool

FakeAudioGateway|null fakeAudioGateway()

Get the fake audio gateway.

Return Value

FakeAudioGateway|null

FakeClassificationGateway fakeClassification(Closure|array $responses = [])

Fake classification operations.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeClassificationGateway

InteractsWithFakeClassification recordClassification(ClassificationPrompt $prompt)

Record a classification.

Recorded prompts remain on the worker-shared manager.

Parameters

ClassificationPrompt $prompt

Return Value

InteractsWithFakeClassification

InteractsWithFakeClassification assertClassified(Closure $callback)

Assert that a classification was performed matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeClassification

InteractsWithFakeClassification assertNotClassified(Closure $callback)

Assert that a classification was not performed matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeClassification

InteractsWithFakeClassification assertNothingClassified()

Assert that no classifications were performed.

bool classificationIsFaked()

Determine if classification is faked.

Return Value

bool

FakeClassificationGateway|null fakeClassificationGateway()

Get the fake classification gateway.

Return Value

FakeClassificationGateway|null

FakeEmbeddingGateway fakeEmbeddings(Closure|array $responses = [])

Fake embeddings generation.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeEmbeddingGateway

InteractsWithFakeEmbeddings recordEmbeddingsGeneration(EmbeddingsPrompt|QueuedEmbeddingsPrompt $prompt)

Record an embeddings generation.

Recorded prompts remain on the worker-shared manager.

InteractsWithFakeEmbeddings assertEmbeddingsGenerated(Closure $callback)

Assert that embeddings were generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeEmbeddings

InteractsWithFakeEmbeddings assertEmbeddingsNotGenerated(Closure $callback)

Assert that embeddings were not generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeEmbeddings

InteractsWithFakeEmbeddings assertNoEmbeddingsGenerated()

Assert that no embeddings were generated.

InteractsWithFakeEmbeddings assertEmbeddingsQueued(Closure $callback)

Assert that a queued embeddings generation was recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeEmbeddings

InteractsWithFakeEmbeddings assertEmbeddingsNotQueued(Closure $callback)

Assert that a queued embeddings generation was not recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeEmbeddings

InteractsWithFakeEmbeddings assertNoEmbeddingsQueued()

Assert that no queued embeddings generations were recorded.

bool embeddingsAreFaked()

Determine if embeddings generation is faked.

Return Value

bool

FakeEmbeddingGateway|null fakeEmbeddingGateway()

Get the fake embedding gateway.

Return Value

FakeEmbeddingGateway|null

FakeFileGateway fakeFiles(Closure|array $responses = [])

Fake file operations.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeFileGateway

InteractsWithFakeFiles recordFileUpload(StorableFile $file)

Record a file upload.

Recorded uploads remain on the worker-shared manager.

Parameters

StorableFile $file

Return Value

InteractsWithFakeFiles

InteractsWithFakeFiles recordFileDeletion(string $fileId)

Record a file deletion.

Recorded deletions remain on the worker-shared manager.

Parameters

string $fileId

Return Value

InteractsWithFakeFiles

InteractsWithFakeFiles assertFileUploaded(Closure $callback)

Assert that a file was uploaded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeFiles

InteractsWithFakeFiles assertFileNotUploaded(Closure $callback)

Assert that a file was not uploaded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeFiles

InteractsWithFakeFiles assertNoFilesUploaded()

Assert that no files were uploaded.

Return Value

InteractsWithFakeFiles

InteractsWithFakeFiles assertFileDeleted(Closure|string $callback)

Assert that a file was deleted matching a given truth test.

Parameters

Closure|string $callback

Return Value

InteractsWithFakeFiles

InteractsWithFakeFiles assertFileNotDeleted(Closure|string $callback)

Assert that a file was not deleted matching a given truth test.

Parameters

Closure|string $callback

Return Value

InteractsWithFakeFiles

InteractsWithFakeFiles assertNoFilesDeleted()

Assert that no files were deleted.

Return Value

InteractsWithFakeFiles

bool filesAreFaked()

Determine if file operations are faked.

Return Value

bool

FakeFileGateway|null fakeFileGateway()

Get the fake file gateway.

Return Value

FakeFileGateway|null

FakeImageGateway fakeImages(Closure|array $responses = [])

Fake image generation.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeImageGateway

InteractsWithFakeImages recordImageGeneration(ImagePrompt|QueuedImagePrompt $prompt)

Record an image generation.

Recorded prompts remain on the worker-shared manager.

Parameters

ImagePrompt|QueuedImagePrompt $prompt

Return Value

InteractsWithFakeImages

InteractsWithFakeImages assertImageGenerated(Closure $callback)

Assert that an image was generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeImages

InteractsWithFakeImages assertImageNotGenerated(Closure $callback)

Assert that an image was not generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeImages

InteractsWithFakeImages assertNoImagesGenerated()

Assert that no images were generated.

InteractsWithFakeImages assertImageQueued(Closure $callback)

Assert that a queued image generation was recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeImages

InteractsWithFakeImages assertImageNotQueued(Closure $callback)

Assert that a queued image generation was not recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeImages

InteractsWithFakeImages assertNoImagesQueued()

Assert that no queued image generations were recorded.

bool imagesAreFaked()

Determine if image generation is faked.

Return Value

bool

FakeImageGateway|null fakeImageGateway()

Get the fake image gateway.

Return Value

FakeImageGateway|null

FakeRerankingGateway fakeReranking(Closure|array $responses = [])

Fake reranking operations.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeRerankingGateway

InteractsWithFakeReranking recordReranking(RerankingPrompt $prompt)

Record a reranking.

Recorded prompts remain on the worker-shared manager.

Parameters

RerankingPrompt $prompt

Return Value

InteractsWithFakeReranking

InteractsWithFakeReranking assertReranked(Closure $callback)

Assert that a reranking was performed matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeReranking

InteractsWithFakeReranking assertNotReranked(Closure $callback)

Assert that a reranking was not performed matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeReranking

InteractsWithFakeReranking assertNothingReranked()

Assert that no rerankings were performed.

bool rerankingIsFaked()

Determine if reranking is faked.

Return Value

bool

FakeRerankingGateway|null fakeRerankingGateway()

Get the fake reranking gateway.

Return Value

FakeRerankingGateway|null

FakeStoreGateway fakeStores(Closure|array $responses = [])

Fake store operations.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeStoreGateway

InteractsWithFakeStores recordStoreCreation(string $name, string|null $description = null, Collection|null $fileIds = null, DateInterval|null $expiresWhenIdleFor = null)

Record a store creation.

Recorded creations remain on the worker-shared manager.

Parameters

string $name
string|null $description
Collection|null $fileIds
DateInterval|null $expiresWhenIdleFor

Return Value

InteractsWithFakeStores

InteractsWithFakeStores recordStoreDeletion(string $storeId)

Record a store deletion.

Recorded deletions remain on the worker-shared manager.

Parameters

string $storeId

Return Value

InteractsWithFakeStores

InteractsWithFakeStores recordFileAddition(string $storeId, string $fileId, StorableFile|UploadedFile|HasProviderId|string $file)

Record a file addition to a store.

Recorded additions remain on the worker-shared manager.

Parameters

string $storeId
string $fileId
StorableFile|UploadedFile|HasProviderId|string $file

Return Value

InteractsWithFakeStores

InteractsWithFakeStores recordFileRemoval(string $storeId, string $fileId)

Record a file removal from a store.

Recorded removals remain on the worker-shared manager.

Parameters

string $storeId
string $fileId

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertStoreCreated(Closure|string $callback)

Assert that a store was created matching a given truth test.

Parameters

Closure|string $callback

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertStoreNotCreated(Closure|string $callback)

Assert that a store was not created matching a given truth test.

Parameters

Closure|string $callback

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertNoStoresCreated()

Assert that no stores were created.

InteractsWithFakeStores assertStoreDeleted(Closure|string $callback)

Assert that a store was deleted matching a given truth test.

Parameters

Closure|string $callback

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertStoreNotDeleted(Closure|string $callback)

Assert that a store was not deleted matching a given truth test.

Parameters

Closure|string $callback

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertNoStoresDeleted()

Assert that no stores were deleted.

InteractsWithFakeStores assertFileAddedToStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was added to a store matching a given truth test.

Parameters

Closure|string $storeId
string|null $fileId

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertFileNotAddedToStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was not added to a store matching a given truth test.

Parameters

Closure|string $storeId
string|null $fileId

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertFileRemovedFromStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was removed from a store matching a given truth test.

Parameters

Closure|string $storeId
string|null $fileId

Return Value

InteractsWithFakeStores

InteractsWithFakeStores assertFileNotRemovedFromStore(Closure|string $storeId, string|null $fileId = null)

Assert that a file was not removed from a store matching a given truth test.

Parameters

Closure|string $storeId
string|null $fileId

Return Value

InteractsWithFakeStores

protected Closure fileMatchingCallback(Closure|string $storeId, string|null $fileId)

Get a callback for matching store and file IDs.

Parameters

Closure|string $storeId
string|null $fileId

Return Value

Closure

protected bool fileIdMatches(StorableFile|UploadedFile|HasProviderId|string $file, string|null $expectedFileId)

Determine if the given file matches the expected file ID.

Parameters

StorableFile|UploadedFile|HasProviderId|string $file
string|null $expectedFileId

Return Value

bool

bool storesAreFaked()

Determine if store operations are faked.

Return Value

bool

FakeStoreGateway|null fakeStoreGateway()

Get the fake store gateway.

Return Value

FakeStoreGateway|null

FakeTranscriptionGateway fakeTranscriptions(Closure|array $responses = [])

Fake transcription generation.

On the shared manager, the fake gateway affects every request.

Parameters

Closure|array $responses

Return Value

FakeTranscriptionGateway

InteractsWithFakeTranscriptions recordTranscriptionGeneration(TranscriptionPrompt|QueuedTranscriptionPrompt $prompt)

Record a transcription generation.

Recorded prompts remain on the worker-shared manager.

InteractsWithFakeTranscriptions assertTranscriptionGenerated(Closure $callback)

Assert that a transcription was generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeTranscriptions

InteractsWithFakeTranscriptions assertTranscriptionNotGenerated(Closure $callback)

Assert that a transcription was not generated matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeTranscriptions

InteractsWithFakeTranscriptions assertNoTranscriptionsGenerated()

Assert that no transcriptions were generated.

InteractsWithFakeTranscriptions assertTranscriptionQueued(Closure $callback)

Assert that a queued transcription generation was recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeTranscriptions

InteractsWithFakeTranscriptions assertTranscriptionNotQueued(Closure $callback)

Assert that a queued transcription generation was not recorded matching a given truth test.

Parameters

Closure $callback

Return Value

InteractsWithFakeTranscriptions

InteractsWithFakeTranscriptions assertNoTranscriptionsQueued()

Assert that no queued transcription generations were recorded.

bool transcriptionsAreFaked()

Determine if transcription generation is faked.

Return Value

bool

FakeTranscriptionGateway|null fakeTranscriptionGateway()

Get the fake transcription gateway.

Return Value

FakeTranscriptionGateway|null

at line 91
Provider build(array $config)

Build an on-demand provider instance from the given configuration.

Parameters

array $config

Return Value

Provider

Exceptions

InvalidArgumentException

at line 145
Provider|null onDemandProvider(string $name)

internal  
 

Get an on-demand provider from the current operation, if one exists.

Parameters

string $name

Return Value

Provider|null

at line 164
array resolveOnDemandProviders(array $providers)

internal  
 

Capture on-demand providers before an earlier failover attempt can replace them.

Parameters

array $providers

Return Value

array

at line 211
AudioProvider audioProvider(Provider|string|null $name = null)

Get an audio provider instance by name.

Parameters

Provider|string|null $name

Return Value

AudioProvider

Exceptions

LogicException

at line 221
AudioProvider fakeableAudioProvider(Provider|string|null $name = null)

Get an audio provider instance, using a fake gateway if audio is faked.

Parameters

Provider|string|null $name

Return Value

AudioProvider

Exceptions

LogicException

at line 235
ClassificationProvider classificationProvider(Provider|string|null $name = null)

Get a classification provider instance by name.

Parameters

Provider|string|null $name

Return Value

ClassificationProvider

Exceptions

LogicException

at line 245
ClassificationProvider fakeableClassificationProvider(Provider|string|null $name = null)

Get a classification provider instance, using a fake gateway if classification is faked.

Parameters

Provider|string|null $name

Return Value

ClassificationProvider

Exceptions

LogicException

at line 259
EmbeddingProvider embeddingProvider(Provider|string|null $name = null)

Get an embedding provider instance by name.

Parameters

Provider|string|null $name

Return Value

EmbeddingProvider

Exceptions

LogicException

at line 269
EmbeddingProvider fakeableEmbeddingProvider(Provider|string|null $name = null)

Get an embedding provider instance, using a fake gateway if embeddings are faked.

Parameters

Provider|string|null $name

Return Value

EmbeddingProvider

Exceptions

LogicException

at line 283
RerankingProvider rerankingProvider(Provider|string|null $name = null)

Get a reranking provider instance by name.

Parameters

Provider|string|null $name

Return Value

RerankingProvider

Exceptions

LogicException

at line 293
RerankingProvider fakeableRerankingProvider(Provider|string|null $name = null)

Get a reranking provider instance, using a fake gateway if reranking is faked.

Parameters

Provider|string|null $name

Return Value

RerankingProvider

Exceptions

LogicException

at line 307
ImageProvider imageProvider(Provider|string|null $name = null)

Get an image provider instance by name.

Parameters

Provider|string|null $name

Return Value

ImageProvider

Exceptions

LogicException

at line 317
ImageProvider fakeableImageProvider(Provider|string|null $name = null)

Get an image provider instance, using a fake gateway if images are faked.

Parameters

Provider|string|null $name

Return Value

ImageProvider

Exceptions

LogicException

at line 331
TextProvider textProvider(Provider|string|null $name = null)

Get a text provider instance by name.

Parameters

Provider|string|null $name

Return Value

TextProvider

Exceptions

LogicException

at line 341
TextProvider textProviderFor(Agent $agent, Provider|string|null $name = null)

Get a provider instance for an agent by name.

Parameters

Agent $agent
Provider|string|null $name

Return Value

TextProvider

Exceptions

LogicException

at line 355
TranscriptionProvider transcriptionProvider(Provider|string|null $name = null)

Get a transcription provider instance by name.

Parameters

Provider|string|null $name

Return Value

TranscriptionProvider

Exceptions

LogicException

at line 365
TranscriptionProvider fakeableTranscriptionProvider(Provider|string|null $name = null)

Get a transcription provider instance, using a fake gateway if transcriptions are faked.

Parameters

Provider|string|null $name

Return Value

TranscriptionProvider

Exceptions

LogicException

at line 379
FileProvider fileProvider(Provider|string|null $name = null)

Get a file provider instance by name.

Parameters

Provider|string|null $name

Return Value

FileProvider

Exceptions

LogicException

at line 389
FileProvider fakeableFileProvider(Provider|string|null $name = null)

Get a file provider instance, using a fake gateway if files are faked.

Parameters

Provider|string|null $name

Return Value

FileProvider

Exceptions

LogicException

at line 403
StoreProvider storeProvider(Provider|string|null $name = null)

Get a store provider instance by name.

Parameters

Provider|string|null $name

Return Value

StoreProvider

Exceptions

LogicException

at line 413
StoreProvider fakeableStoreProvider(Provider|string|null $name = null)

Get a store provider instance, using a fake gateway if stores are faked.

Parameters

Provider|string|null $name

Return Value

StoreProvider

Exceptions

LogicException

at line 425
AnthropicProvider createAnthropicDriver(array $config)

Create an Anthropic powered instance.

Parameters

array $config

Return Value

AnthropicProvider

at line 437
AzureOpenAiProvider createAzureDriver(array $config)

Create an Azure OpenAI powered instance.

Parameters

array $config

Return Value

AzureOpenAiProvider

at line 448
BedrockProvider createBedrockDriver(array $config)

Create an AWS Bedrock powered instance.

Parameters

array $config

Return Value

BedrockProvider

at line 459
CohereProvider createCohereDriver(array $config)

Create a Cohere powered instance.

Parameters

array $config

Return Value

CohereProvider

at line 470
DeepSeekProvider createDeepseekDriver(array $config)

Create a DeepSeek powered instance.

Parameters

array $config

Return Value

DeepSeekProvider

at line 481
ElevenLabsProvider createElevenDriver(array $config)

Create an ElevenLabs powered instance.

Parameters

array $config

Return Value

ElevenLabsProvider

at line 492
GeminiProvider createGeminiDriver(array $config)

Create a Gemini powered instance.

Parameters

array $config

Return Value

GeminiProvider

at line 504
GroqProvider createGroqDriver(array $config)

Create a Groq powered instance.

Parameters

array $config

Return Value

GroqProvider

at line 515
JinaProvider createJinaDriver(array $config)

Create a Jina powered instance.

Parameters

array $config

Return Value

JinaProvider

at line 526
MistralProvider createMistralDriver(array $config)

Create a Mistral AI powered instance.

Parameters

array $config

Return Value

MistralProvider

at line 537
OllamaProvider createOllamaDriver(array $config)

Create an Ollama powered instance.

Parameters

array $config

Return Value

OllamaProvider

at line 548
OpenAiProvider createOpenaiDriver(array $config)

Create an OpenAI powered instance.

Parameters

array $config

Return Value

OpenAiProvider

at line 560
OpenAiCompatibleProvider createOpenaiCompatibleDriver(array $config)

Create an OpenAI-compatible powered instance.

Parameters

array $config

Return Value

OpenAiCompatibleProvider

at line 571
OpenRouterProvider createOpenrouterDriver(array $config)

Create an OpenRouter powered instance.

Parameters

array $config

Return Value

OpenRouterProvider

at line 582
TypeSafeProvider createTypesafeDriver(array $config)

Create a TypeSafe powered instance.

Parameters

array $config

Return Value

TypeSafeProvider

at line 593
VoyageAiProvider createVoyageaiDriver(array $config)

Create a VoyageAI powered instance.

Parameters

array $config

Return Value

VoyageAiProvider

at line 604
XaiProvider createXaiDriver(array $config)

Create an xAI powered instance.

Parameters

array $config

Return Value

XaiProvider

at line 622
protected mixed ensureProviderSupports(string $contract, string $capability, Provider|string|null $name)

Get a provider instance by name, ensuring it implements the given capability contract.

Parameters

string $contract
string $capability
Provider|string|null $name

Return Value

mixed

Exceptions

LogicException

at line 699
void resolveProviderConfigUsing(Closure $resolver)

Configure the provider configuration resolver.

Configured providers are rebuilt on every lookup, including those built by custom creators. Keep custom creators inexpensive and stateless.

On the shared manager, the callback applies to every later AI operation.

Parameters

Closure $resolver

Return Value

void

at line 717
void resolveConversationPartitionUsing(string $column, Closure $resolver)

Configure the conversation row partition resolver.

On the shared manager, the column and callback apply to every subsequent conversation operation.

Parameters

string $column
Closure $resolver

Return Value

void

at line 735
string|null conversationPartitionColumn()

Get the configured conversation partition column.

Return Value

string|null

at line 743
int|string|null conversationPartition()

Resolve the current conversation partition.

Return Value

int|string|null

at line 766
void resolveEmbeddingsCacheScopeUsing(Closure $resolver)

Configure the embeddings cache scope resolver.

On the shared manager, the callback applies to every subsequent embeddings cache operation.

Parameters

Closure $resolver

Return Value

void

at line 779
string|null embeddingsCacheScope()

Resolve the current embeddings cache scope.

Return Value

string|null

at line 802
void captureContextUsing(Closure $capture)

Configure context capture for deferred operations.

The returned runner wraps every stream resumption and AI callback, including nested failover and sub-agent streams. It must be safe to nest and inexpensive to re-enter when its context is already active. Return a runner for a captured empty context too; null means no wrapper.

On the shared manager, the callback applies to every later AI operation.

Parameters

Closure $capture

Return Value

void

at line 817
Closure|null captureContext()

Capture a runner for the current operation's context.

Return Value

Closure|null

at line 825
void flushState()

Flush the on-demand providers built during the current operation.

Return Value

void