Skip to main content

Configuration

After publishing the configuration file with php artisan vendor:publish --tag=instructor-config, you will find it at config/instructor.php. This file controls every aspect of the package, from LLM provider connections and extraction behavior to HTTP transport, logging, event bridging, code-agent execution, native-agent runtime boundaries, and response caching. This is Laravel-native configuration. The Laravel integration reads config('instructor.*') through Laravel’s config repository and converts those arrays into typed runtime config objects internally. It does not ask the standalone packages/config YAML loader to parse config/instructor.php.

Default Connection

This determines which LLM connection is used when you call a facade without specifying one explicitly. You can override it at runtime with ->connection('name') on any facade, or by passing an LLMConfig object via ->fromConfig(...).

Connections

Configure multiple LLM provider connections. Each connection defines its driver, API credentials, default model, and token limits. You can define as many connections as you need and switch between them at runtime.

Supported Drivers

Adding a Custom Connection

Any OpenAI-compatible API can be used by setting the openai driver and pointing api_url to your endpoint. Extra keys beyond the standard set (driver, api_url, api_key, endpoint, model, max_tokens, options) are automatically merged into the options array and forwarded with each request.

Embeddings Connections

Configure embedding model connections separately from inference connections. The embeddings section has its own default key and connection definitions.

Extraction Settings

Configure defaults for structured output extraction. These values apply to every StructuredOutput call unless overridden at runtime.

Output Modes

The output mode controls how the package instructs the LLM to produce structured output. Different providers have varying levels of support for each mode.

HTTP Client Settings

Configure the underlying HTTP transport. The Laravel package ships with its own LaravelDriver that wraps Laravel’s HTTP client (Illuminate\Http\Client\Factory), which means Http::fake() works transparently in your tests.
The service provider binds Cognesy\Http\Contracts\CanSendHttpRequests to the Laravel-backed HTTP transport. All higher-level services (Inference, Embeddings, StructuredOutput) depend on that contract, ensuring consistent HTTP behavior across the entire package.

Logging Settings

The package includes a logging pipeline that enriches log entries with Laravel request context (request ID, authenticated user, route, URL) automatically.

Logging Presets

Both the default and production presets automatically attach lazy enrichers that add the current HTTP request context (request ID, user ID, session ID, route, method, URL) to every log record.

Events Settings

Configure how Instructor’s internal events are bridged to Laravel’s event dispatcher.
When bridge_events is empty (the default), every Instructor event is forwarded to Laravel. To limit traffic, list only the event classes you care about. See the Events guide for the full list of available events and listener examples.

Cache Settings

Configure response caching to avoid redundant API calls for identical inputs.

Native Agents Settings

The agents namespace is reserved for native Cognesy\Agents runtime integration. This keeps native runtime, persistence, and observability settings separate from AgentCtrl code-agent execution.
The Laravel package resolves tools and capabilities through the container before registration, so constructor dependencies are supported. definitions accepts file or directory paths. schemas accepts class strings or schema-definition arrays. If you prefer explicit service-provider wiring, use the first-party tag constants in Cognesy\Instructor\Laravel\Agents\AgentRegistryTags for definitions, tools, capabilities, and tagged SchemaRegistration objects. For long-lived sessions, switch session_store to database and publish the package migration with php artisan vendor:publish --tag=instructor-migrations. For broadcast envelopes, enable agents.broadcasting.enabled and set the Laravel broadcasting connection you want to use.

Code Agents (AgentCtrl) Settings

AgentCtrl now reads from the dedicated agent_ctrl namespace. The facade still falls back to the legacy agents key so existing published configs continue to work.

Telemetry Settings

The telemetry namespace is the first-class home for Laravel telemetry wiring.
driver accepts null, otel, langfuse, logfire, or composite. The package binds telemetry, projector composition, and the runtime event bridge from this namespace automatically.

Environment Variables Reference

Runtime Configuration

Override any configuration at runtime using the fluent API on the facades:
For full programmatic control, build an LLMConfig object and pass it directly: