Installation
Requirements
- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
- A valid API key from a supported LLM provider (OpenAI, Anthropic, Google, etc.)
Install via Composer
StructuredOutput, Inference, Embeddings, AgentCtrl) are registered automatically. No manual registration is required for typical Laravel applications.
Laravel config now separates native agent runtime settings from AgentCtrl code-agent settings:
config('instructor.agents')is reserved for nativeCognesy\Agentsconfig('instructor.agent_ctrl')configures CLI code agents used byAgentCtrlconfig('instructor.telemetry')owns Laravel telemetry wiring
Publish Configuration
Publish the configuration file to customize connections, extraction defaults, and other settings:config/instructor.php with all available options. The file ships with sensible defaults, so you can start using the package with just an API key and customize later as your needs grow.
Configure API Keys
Add your LLM provider API key to.env. You only need the key for the provider you intend to use:
connection() method on any facade.
Setup by Package
The Laravel package is the Laravel integration layer for four underlying packages. You do not install them separately in a Laravel app. Instead, you configure them through Laravel’s nativeconfig/instructor.php file and use the Laravel facades or container bindings.
The standalone packages/config YAML loader is not responsible for reading config/instructor.php. Under Laravel, the service provider reads Laravel’s config repository directly and maps those values into the typed runtime config objects used by Instructor, Polyglot, and the HTTP client.
| Underlying package | Laravel surface | What to set up | Continue with |
|---|---|---|---|
packages/instructor | StructuredOutput facade and Cognesy\Instructor\StructuredOutput | Configure your default LLM connection, extraction defaults, and response models | Facades, Response Models, Configuration |
packages/polyglot | Inference and Embeddings facades plus Cognesy\Polyglot\Inference\Inference and Cognesy\Polyglot\Embeddings\Embeddings | Configure inference connections in connections and embedding models in embeddings.connections | Facades, Configuration, Events |
packages/agents | Native Cognesy\Agents runtime | Laravel now reserves the agents config namespace for native agent runtime, persistence, and observability wiring. First-class container/runtime bindings are documented separately. | Native Agents, Configuration |
packages/agent-ctrl | AgentCtrl facade | Install the CLI agent you want to use, ensure its binary is available in PATH, then configure timeouts, working directory, and sandbox defaults in agent_ctrl | Code Agents, Testing |
packages/http-client | Internal Laravel-backed transport | No separate install is required; keep http.driver set to laravel to route requests through Laravel’s HTTP client and Http::fake() | Configuration, Testing |
packages/agents Under Laravel
Laravel keeps native agent runtime configuration under config/instructor.php in the agents section so it no longer collides with AgentCtrl.
The Laravel package now ships the native runtime integration end to end:
agents.enabledagents.session_storeagents.definitionsagents.toolsagents.capabilitiesagents.schemasagents.broadcasting
config('instructor.telemetry').
packages/instructor Under Laravel
Structured output uses the default connection from config/instructor.php, then applies Laravel-specific extraction defaults such as output mode and retry behavior. In practice, setup means:
- publish the config file
- set at least one LLM API key
- choose a default connection in
connections - define extraction defaults in
extraction - create response model classes and call
StructuredOutput
packages/polyglot Under Laravel
Laravel exposes Polyglot through two entry points:
Inferencefor raw text, JSON, tool-calling, and streaming responsesEmbeddingsfor vector generation
connections; embeddings read from embeddings.connections. If you already configured providers for StructuredOutput, raw inference usually needs no additional setup.
packages/agent-ctrl Under Laravel
AgentCtrl does not use the LLM HTTP connections from config/instructor.php. It runs external agent CLIs from your Laravel application. Setup means:
- install the agent CLI you want to use
- make sure its executable is available in
PATH - authenticate that CLI using its own provider workflow
- set Laravel defaults for timeout, working directory, model, and sandbox in
agent_ctrl
packages/http-client Under Laravel
Laravel already wires the HTTP client package into the container. All Instructor, Inference, and Embeddings calls use the Laravel-backed driver by default. Setup usually means only:
- keep
http.driverset tolaravel - adjust
http.timeoutandhttp.connect_timeoutif needed - use
Http::fake()when you want transport-level HTTP tests
Verify Installation
Run the installation command to verify everything is configured correctly:- Publish the configuration if not already published
- Check for API key configuration in your
.envfile - Show next steps for getting started
Test Your Connection
Test that your API configuration is working by making a real API call:Optional: Publish Stubs
If you want to customize the response model templates used bymake:response-model:
stubs/instructor/ in your application root. The command will prefer your custom stubs over the package defaults when generating new response models.
Manual Registration (Optional)
If you have disabled Laravel’s package auto-discovery, manually register the service provider. In Laravel 10, add it toconfig/app.php:
bootstrap/providers.php.
Upgrading
When upgrading to a new version, republish the configuration if there are new options:Next Steps
- Configuration — Configure connections and settings
- Facades — Learn how to use the facades
- Response Models — Create your first response model