The Complete AI Toolkit for PHP
Call 25+ LLM providers through one API. Turn responses into typed PHP objects. Build agents with tools and sessions. Orchestrate coding agents from PHP.
Each package solves a distinct problem. Use one or combine them. They share the same design principles and work together seamlessly.
Unified LLM API
$text = Inference::using('openai')
->withMessages('Say hello.')
->get();
Structured Outputs
$person = StructuredOutput::using('openai')
->with(
messages: 'Jason is 28.',
responseModel: Person::class,
)->get();
Agent SDK
$loop = AgentBuilder::base()
->withCapability(new UseBash())
->withCapability(new UseGuards(maxSteps: 10))
->build();
Coding Agent Control
$response = AgentCtrl::claudeCode()
->inDirectory('/my/project')
->execute('Summarize this repo.');
echo $response->text();
Four packages, clear boundaries. Polyglot handles all LLM communication. Instructor and Agents build on top of it. AgentCtrl talks directly to external coding agent CLIs.
Instructor
Structured Outputs
Polyglot
Unified LLM API
25+ LLM Providers
OpenAI, Anthropic, Gemini, ...
Agents
Agent SDK
Polyglot
Inference + Embeddings
25+ LLM Providers
Groq, Ollama, Mistral, ...
AgentCtrl
Coding Agent Control
CLI Code Agents
Claude Code, Codex, OpenCode, Pi, Gemini
Instructor
Structured Outputs
Polyglot
Unified LLM API
25+ LLM Providers
OpenAI, Anthropic, Gemini, ...
Agents
Agent SDK
Polyglot
Inference + Embeddings
25+ LLM Providers
Groq, Ollama, Mistral, ...
AgentCtrl
Coding Agent Control
CLI Code Agents
Claude Code, Codex, OpenCode, Pi, Gemini
$ composer require cognesy/instructor-php
$ export OPENAI_API_KEY=sk-...
Start with one, add more as your application grows.
Call 25+ providers through one request API.
1use Cognesy\Polyglot\Inference\Inference;2 3$text = Inference::using('openai')4 ->withSystem('You are a senior PHP developer.')5 ->withMessages('Explain the strategy pattern in one paragraph.')6 ->get(); Get typed PHP objects or plain arrays from model responses.
1use Cognesy\Instructor\StructuredOutput; 2 3final class Person { 4 public string $name; 5 public int $age; 6} 7 8$person = StructuredOutput::using('openai') 9 ->withSystem('Extract person data from the text.')10 ->with(11 messages: 'Jason is 28 years old.',12 responseModel: Person::class,13 )14 ->get(); Build agents with context, tools, stop rules, and sessions.
1use Cognesy\Agents\AgentLoop;2use Cognesy\Agents\Data\AgentState;3 4$state = AgentState::empty()5 ->withSystemPrompt('You are a math tutor. Show your work.')6 ->withUserMessage('What is 12 * 15?');7 8$result = AgentLoop::default()->execute($state);9echo $result->finalResponse()->toString(); Control Codex, Claude Code, and OpenCode from PHP.
1use Cognesy\AgentCtrl\AgentCtrl;2 3$response = AgentCtrl::claudeCode()4 ->withSystemPrompt('Focus on architecture, skip implementation details.')5 ->inDirectory(__DIR__)6 ->execute('Summarize this repository.');7 8echo $response->text(); Built for PHP developers who want AI capabilities without leaving their ecosystem.
Works with plain PHP, Laravel, Symfony, or your own structure. No framework lock-in.
Leverages PHP's type system. Get typed objects from LLMs, not unstructured strings you have to parse.
Each package works independently. Use only what you need. Add more when your application grows.
FakeAgentDriver for deterministic testing. No API calls needed. Script scenarios and verify behavior.
Retry policies, validation, error handling, and observability built in. Not a prototype toolkit.
Not a port from Python or JavaScript. Designed for PHP idioms, patterns, and developer expectations.
Write your code once. Switch providers by changing a single string. No rewrites needed.
via Polyglot
via Polyglot
via AgentCtrl
From simple data extraction to multi-agent workflows. Here's what developers are building with InstructorPHP.
Extract structured data from documents, emails, invoices, and reports. Turn unstructured text into typed PHP objects ready for your database.
Build customer support bots, FAQ assistants, and interactive agents that reason, use tools, and maintain conversation state across sessions.
Orchestrate coding agents for automated refactoring, migrations, test generation, and CI/CD workflows. Control multiple agent backends from one script.
Build retrieval-augmented generation with Polyglot embeddings and inference. Index documents, search semantically, and generate contextual answers.
Generate validated, structured content for CMS, e-commerce catalogs, and marketing. Get typed objects with SEO metadata, not raw strings.
Convert natural language to validated API parameters. Classify requests, extract entities, and route them through your existing PHP service layer.
Each package has a clear responsibility. Here's what each one gives you.
| Capability | Polyglot | Instructor | Agents | AgentCtrl |
|---|---|---|---|---|
| LLM Inference | — | — | — | |
| Embeddings | — | — | — | |
| Structured Output | — | — | — | |
| Validation + Retry | — | — | — | |
| Agent Loop | — | — | — | |
| Tool Execution | — | — | — | |
| Lifecycle Hooks | — | — | — | |
| Subagents | — | — | — | |
| Session Persistence | — | — | ||
| CLI Agent Control | — | — | — | |
| Sandbox Modes | — | — | — | |
| Streaming | * | |||
| * via event listeners | ||||
Structured outputs for typed PHP data or plain arrays.
cognesy/instructor-struct
Unified LLM calls and embeddings across 25+ providers.
cognesy/instructor-polyglot
Agent loops, tools, subagents, capabilities, and sessions.
cognesy/agents
Control Claude Code, Codex, OpenCode, Pi, and Gemini from PHP.
cognesy/agent-ctrl
"Start with plain PHP code. Add the AI capability you need. Keep the rest of your application structure the same."
cognesy/instructor-php installs everything, but you can also install individual packages like cognesy/instructor-polyglot or cognesy/agents separately.