The AI Revolution is Here
Gone are the days of messy, manual API calls to OpenAI or Anthropic. In February 2026, the Laravel team released the official Laravel AI SDK—a first-party package that treats AI as a first-class citizen.
The biggest shift? We’ve moved from "Simple Prompts" to "Autonomous Agents." These agents don't just chat; they have memory, they can use "tools" (like your database), and they return structured data that your app can actually use.
Step 1: Installation & Setup
To get started with the new SDK, you simply need to pull in the package:
composer require laravel/ai
After publishing the config (php artisan vendor:publish --tag=ai-config), you can swap between Gemini, OpenAI, or Anthropic in a single line of code in your .env.
Step 2: Creating Your First Agent
In 2026, we no longer put AI logic in Controllers. We use the new Artisan command:
php artisan make:agent SupportAssistant --structured
This creates a dedicated class in app/Ai/Agents. Here, you define the Instructions (System Prompt) and the Tools the agent can use.
Step 3: Giving Your Agent "Tools"
The most powerful feature of the SDK is Function Calling. You can allow your agent to "see" your database or trigger actions. For example:
public function tools(): iterable {
return [
new \App\Ai\Tools\GetOrderDetails,
new \App\Ai\Tools\SimilaritySearch(Document::class),
];
}
Now, when a user asks, "Where is my last order?", the agent recognizes it needs the GetOrderDetails tool, executes it, and provides a real-time answer.
Step 4: Smart Failover (Production Ready)
AI APIs go down. The Laravel AI SDK handles this natively. You can define a "Failover" chain:
$response = (new SupportAssistant)->prompt($message, provider: ['anthropic', 'openai']);
If Claude (Anthropic) is having a slow day or hits a rate limit, Laravel automatically switches the request to GPT-4o without the user ever knowing.