Laravel AI SDK
Comprehensive guide for building AI-powered features with the Laravel AI SDK (laravel/ai). Contains 17 rules across 7 categories covering agents, tools, media generation, embeddings, vector stores, and testing.
When to Apply
Reference these guidelines when:
- Creating AI agents with instructions, tools, and structured output
- Prompting agents with conversation context
- Streaming or queueing agent responses
- Generating images, audio, or transcriptions
- Creating and querying vector embeddings
- Building RAG (retrieval-augmented generation) features
- Testing AI features with fakes and assertions
Rule Categories by Priority
| Priority |
Category |
Impact |
Prefix |
| 1 |
Agents |
CRITICAL |
agent- |
| 2 |
Tools |
HIGH |
tool- |
| 3 |
Embeddings & Search |
HIGH |
embed- |
| 4 |
Media Generation |
MEDIUM |
media- |
| 5 |
Files & Storage |
MEDIUM |
files- |
| 6 |
Infrastructure |
MEDIUM |
infra- |
| 7 |
Testing |
HIGH |
test- |
Quick Reference
1. Agents (CRITICAL)
agent-create-configure - Create agents with artisan, PHP attribute configuration
agent-prompting - Prompt agents, conversation context, RemembersConversations
agent-structured-output - Structured output with JSON schema
agent-streaming-async - Streaming, broadcasting, and queueing responses
agent-middleware - Agent middleware pipeline
agent-anonymous - Anonymous agents for quick interactions
2. Tools (HIGH)
tool-create - Create custom tools with schema and handle method
tool-provider - Provider tools: WebSearch, WebFetch, FileSearch, SimilaritySearch
3. Embeddings & Search (HIGH)
embed-generate-cache - Generate, store, and cache vector embeddings
embed-rerank - Rerank documents and collections by relevance
4. Media Generation (MEDIUM)
media-images - Generate, store, and queue images
media-audio-transcription - Text-to-speech and speech-to-text
5. Files & Storage (MEDIUM)
files-vector-stores - File storage and vector stores for RAG
6. Infrastructure (MEDIUM)
infra-failover - Automatic provider failover for resilience
7. Testing (HIGH)
test-agents - Fake agents, assert prompts, prevent stray prompts
test-media - Fake images, audio, and transcriptions
test-data - Fake embeddings, reranking, files, and vector stores
Essential Patterns
Creating an Agent
<?php
namespace App\Ai\Agents;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;
class SalesCoach implements Agent
{
use Promptable;
public function instructions(): string
{
return 'You are a sales coach, analyzing transcripts and providing feedback.';
}
}
Prompting
use App\Ai\Agents\SalesCoach;
$response = SalesCoach::make()->prompt('Analyze this sales transcript...');
return (string) $response;
Generating Images
use Laravel\Ai\Image;
$image = Image::of('A donut sitting on the kitchen counter')
->landscape()
->generate();
$path = $image->store();
Generating Embeddings
use Illuminate\Support\Str;
$embeddings = Str::of('Napa Valley has great wine.')->toEmbeddings();
Testing
use App\Ai\Agents\SalesCoach;
SalesCoach::fake(['First response', 'Second response']);
SalesCoach::make()->prompt('Analyze this...');
SalesCoach::assertPrompted('Analyze this...');
How to Use
Read individual rule files for detailed explanations and code examples.
Each rule file contains:
- YAML frontmatter with metadata (title, impact, tags)
- Brief explanation of why it matters
- Bad Example with explanation
- Good Example with explanation
- Laravel 13 and PHP 8.3 specific context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
1---2name: laravel-ai-sdk3description: Laravel AI SDK for building AI-powered features. Use when creating agents, generating images or audio, working with embeddings, vector search, or testing AI features. Triggers on tasks involving laravel/ai, AI agents, tool-calling, structured output, streaming, embeddings, reranking, or AI faking in tests.4license: MIT5metadata:6 source: https://skillmd.com/skills/asyrafhussin/laravel-ai-sdk7 author: Laravel Community8 version: "1.0.0"9 laravelVersion: "13.x"10 phpVersion: "8.3+"11---1213# Laravel AI SDK1415Comprehensive guide for building AI-powered features with the Laravel AI SDK (`laravel/ai`). Contains 17 rules across 7 categories covering agents, tools, media generation, embeddings, vector stores, and testing.1617## When to Apply1819Reference these guidelines when:20- Creating AI agents with instructions, tools, and structured output21- Prompting agents with conversation context22- Streaming or queueing agent responses23- Generating images, audio, or transcriptions24- Creating and querying vector embeddings25- Building RAG (retrieval-augmented generation) features26- Testing AI features with fakes and assertions2728## Rule Categories by Priority2930| Priority | Category | Impact | Prefix |31|----------|----------|--------|--------|32| 1 | Agents | CRITICAL | `agent-` |33| 2 | Tools | HIGH | `tool-` |34| 3 | Embeddings & Search | HIGH | `embed-` |35| 4 | Media Generation | MEDIUM | `media-` |36| 5 | Files & Storage | MEDIUM | `files-` |37| 6 | Infrastructure | MEDIUM | `infra-` |38| 7 | Testing | HIGH | `test-` |3940## Quick Reference4142### 1. Agents (CRITICAL)4344- `agent-create-configure` - Create agents with artisan, PHP attribute configuration45- `agent-prompting` - Prompt agents, conversation context, RemembersConversations46- `agent-structured-output` - Structured output with JSON schema47- `agent-streaming-async` - Streaming, broadcasting, and queueing responses48- `agent-middleware` - Agent middleware pipeline49- `agent-anonymous` - Anonymous agents for quick interactions5051### 2. Tools (HIGH)5253- `tool-create` - Create custom tools with schema and handle method54- `tool-provider` - Provider tools: WebSearch, WebFetch, FileSearch, SimilaritySearch5556### 3. Embeddings & Search (HIGH)5758- `embed-generate-cache` - Generate, store, and cache vector embeddings59- `embed-rerank` - Rerank documents and collections by relevance6061### 4. Media Generation (MEDIUM)6263- `media-images` - Generate, store, and queue images64- `media-audio-transcription` - Text-to-speech and speech-to-text6566### 5. Files & Storage (MEDIUM)6768- `files-vector-stores` - File storage and vector stores for RAG6970### 6. Infrastructure (MEDIUM)7172- `infra-failover` - Automatic provider failover for resilience7374### 7. Testing (HIGH)7576- `test-agents` - Fake agents, assert prompts, prevent stray prompts77- `test-media` - Fake images, audio, and transcriptions78- `test-data` - Fake embeddings, reranking, files, and vector stores7980## Essential Patterns8182### Creating an Agent8384```php85<?php8687namespace App\Ai\Agents;8889use Laravel\Ai\Contracts\Agent;90use Laravel\Ai\Promptable;9192class SalesCoach implements Agent93{94 use Promptable;9596 public function instructions(): string97 {98 return 'You are a sales coach, analyzing transcripts and providing feedback.';99 }100}101```102103### Prompting104105```php106use App\Ai\Agents\SalesCoach;107108$response = SalesCoach::make()->prompt('Analyze this sales transcript...');109110return (string) $response;111```112113### Generating Images114115```php116use Laravel\Ai\Image;117118$image = Image::of('A donut sitting on the kitchen counter')119 ->landscape()120 ->generate();121122$path = $image->store();123```124125### Generating Embeddings126127```php128use Illuminate\Support\Str;129130$embeddings = Str::of('Napa Valley has great wine.')->toEmbeddings();131```132133### Testing134135```php136use App\Ai\Agents\SalesCoach;137138SalesCoach::fake(['First response', 'Second response']);139140SalesCoach::make()->prompt('Analyze this...');141142SalesCoach::assertPrompted('Analyze this...');143```144145## How to Use146147Read individual rule files for detailed explanations and code examples.148149Each rule file contains:150- YAML frontmatter with metadata (title, impact, tags)151- Brief explanation of why it matters152- Bad Example with explanation153- Good Example with explanation154- Laravel 13 and PHP 8.3 specific context and references155156## Full Compiled Document157158For the complete guide with all rules expanded: `AGENTS.md`