For years, PHP was seen as lagging behind ecosystems like Python when it came to artificial intelligence.
That narrative just changed.
With the release of the Laravel AI SDK (February 2026), AI is no longer an external integration — it’s a native part of the framework. Laravel introduces a powerful concept: Agents, bringing structure, scalability, and developer-friendly AI into PHP.
This is not just another API wrapper.
This is AI built the Laravel way.
For years, PHP was seen as lagging behind ecosystems like Python when it came to artificial intelligence.
That narrative just changed.
With the release of the Laravel AI SDK (February 2026), AI is no longer an external integration — it’s a native part of the framework. Laravel introduces a powerful concept: Agents, bringing structure, scalability, and developer-friendly AI into PHP.
This is not just another API wrapper.
This is AI built the Laravel way.
🚀 What You’ll Learn
- How to build AI logic using Agent Classes
- How Laravel automates conversation history
- How to use native vector search (RAG) with Eloquent
- How to extend AI with Tools (Web, Files, etc.)
⚙️ Installation & Setup
Laravel 12 introduces built-in infrastructure for AI — including database-backed conversations.
1.Install the SDK
composer require laravel/ai
2.Publish & Migrate
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
php artisan migrate
3. Configure .env
AI_PROVIDER=openai
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
🧠 AI Agents: The Core Concept
Forget bloated controllers.
In Laravel 12, AI logic lives inside Agents — clean, reusable PHP classes that define behavior, context, and tools.
Create Your First Agent
php artisan make:agent SupportAssistant
Example Agent
namespace App\Ai\Agents;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\Conversational;
use Laravel\Ai\Concerns\RemembersConversations;
use Laravel\Ai\Promptable;
class SupportAssistant implements Agent, Conversational
{
use Promptable, RemembersConversations;
public function instructions(): string
{
return 'You are a technical support assistant for Laravel applications. Be concise and professional.';
}
}
👉 Think of Agents as:
- Controllers for AI logic
- Services with memory
- Assistants with tools
🔥 Key Features That Change Everything
A. Automated Chat History (Zero Effort)
Laravel handles conversation persistence for you:
$response = SupportAssistant::make()
->forUser(auth()->user())
->prompt('How do I implement rate limiting in Laravel?');
echo $response;
✔ No sessions
✔ No manual storage
✔ Fully user-scoped memory
B. Native Vector Search (RAG)
No external pipelines. No custom SQL.
Laravel lets you query meaning — not keywords:
$documents = Document::query()
->whereVectorSimilarTo('embedding', 'Best practices for PHP 8.4', minSimilarity: 0.7)
->limit(5)
->get();
👉 This is RAG baked into Eloquent.
C. AI Tools (Real Capabilities)
Agents are no longer passive — they can act.
Example: enable web search
use Laravel\Ai\Providers\Tools\WebSearch;
public function tools(): iterable
{
return [
new WebSearch,
];
}
Now your AI can:
- Fetch real-time data
- Interact with external systems
- Extend beyond static knowledge
🛡 Best Practices & Cost Control
1.Smart Model Selection
Use cheaper models when possible:
use Laravel\Ai\Attributes\UseCheapestModel;
#[UseCheapestModel]
class SimpleSummarizer implements Agent {}
👉 Optimize cost without changing logic.
2.Testing Without API Costs
Mock responses in tests:
SupportAssistant::fake(['This is a mocked response.']);
$response = SupportAssistant::make()->prompt('Hello!');
SupportAssistant::assertPrompted('Hello!');
✔ No API calls
✔ Deterministic tests
✔ Faster CI
Legacy vs Laravel AI SDK

💡 Why This Matters
Laravel didn’t just “add AI support”.
It redefined how AI fits into backend architecture:
- AI becomes structured
- AI becomes testable
- AI becomes scalable
- AI becomes Laravel-native
This is the same shift Laravel once brought to routing, queues, and ORM — now applied to AI.
The Laravel AI SDK brings developer happiness to AI development.
Agents transform AI from a feature into a core architectural layer of your application.
