laravel-ai-sdk
Use when integrating AI agents, tool calling, embeddings, structured output, or streaming in Laravel 13 via the `laravel/ai` package. Covers 14+ providers (OpenAI, Anthropic, Gemini, Azure, Groq, DeepSeek, Ollama, Mistral, xAI, Cohere, ElevenLabs, Jina, VoyageAI, OpenRouter).
What this skill does
# Laravel AI SDK
## Agent Workflow (MANDATORY)
Before ANY implementation, use `TeamCreate` to spawn 3 agents:
1. **fuse-ai-pilot:explore-codebase** - Map existing AI usage (custom HTTP clients, OpenAI PHP, etc.) to migrate
2. **fuse-ai-pilot:research-expert** - Verify provider model IDs and pricing on the official Laravel AI SDK docs
3. **mcp__context7__query-docs** - Pull latest `laravel.com/docs/13.x/ai-sdk` examples
After implementation, run **fuse-ai-pilot:sniper** for validation.
---
## Overview
| Feature | Description |
|---------|-------------|
| **Unified API** | Same code surface for 14+ providers via `Lab` enum |
| **Agents** | Class-based with `Agent` contract + `Promptable` trait |
| **Tool calling** | First-party `FileSearch` + custom tools per agent |
| **Embeddings** | `Embeddings::for([...])->generate()` + `Str::toEmbeddings()` |
| **Streaming** | Native SSE + Vercel AI SDK protocol compatibility |
| **Structured output** | `agent(schema: fn ($s) => ...)` with `JsonSchema` |
---
## Critical Rules
1. **Use the `Lab` enum** - Never hard-code provider strings; use `Lab::Anthropic`, `Lab::OpenAI`, etc.
2. **Configure keys in `.env`** - One env var per provider (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, ...) read by `config/ai.php`
3. **Agents are classes** - Always implement `Laravel\Ai\Contracts\Agent` and use `Promptable` trait
4. **Declare tools explicitly** - Override `tools(): iterable` to expose tool calls; never assume implicit registration
5. **Stream via routes** - Return `$agent->stream(...)` directly from a route; do not buffer in memory
---
## Architecture
```
app/
├── Ai/
│ ├── Agents/
│ │ └── SalesCoach.php # implements Agent, uses Promptable
│ ├── Tools/
│ │ └── SearchProducts.php # custom tool class
│ └── Services/
│ └── EmbeddingService.php # Embeddings::for() wrapper
config/
└── ai.php # providers, default models
.env # *_API_KEY entries
```
→ See [Agent.php.md](references/templates/Agent.php.md) for a full agent
---
## Reference Guide
| Topic | Reference | When to Consult |
|-------|-----------|-----------------|
| **Installation** | [installation.md](references/installation.md) | Setting up `laravel/ai` and providers |
| **Agents** | [agents.md](references/agents.md) | Building agent classes with attributes |
| **Tools** | [tools.md](references/tools.md) | Tool calling, `FileSearch`, custom tools |
| **Embeddings** | [embeddings.md](references/embeddings.md) | Generating vectors for semantic search |
| **Streaming** | [streaming.md](references/streaming.md) | SSE + Vercel AI SDK protocol |
| **Structured output** | [structured-output.md](references/structured-output.md) | `agent()` helper + JSON Schema |
### Templates
| Template | When to Use |
|----------|-------------|
| [Agent.php.md](references/templates/Agent.php.md) | Net new agent class |
| [Tool.php.md](references/templates/Tool.php.md) | Custom tool implementation |
| [EmbeddingService.php.md](references/templates/EmbeddingService.php.md) | Batch embedding generation |
| [StreamingController.php.md](references/templates/StreamingController.php.md) | SSE streaming endpoint |
---
## Quick Reference
### Generate text
```php
use App\Ai\Agents\SalesCoach;
$response = (new SalesCoach)->prompt('Summarize this call');
```
### Generate embeddings
```php
use Illuminate\Support\Str;
$embedding = Str::of('Napa Valley wine')->toEmbeddings();
```
### Stream
```php
Route::get('/coach', fn () => (new SalesCoach)->stream('Analyze this'));
```
→ See [Agent.php.md](references/templates/Agent.php.md) for complete example
---
## Best Practices
### DO
- Use class-level attributes (`#[Provider]`, `#[Model]`, `#[MaxSteps]`) to lock agent configuration
- Cache embeddings in the DB - regenerating is expensive
- Set explicit `#[Timeout]` to avoid runaway long generations
- Use `usingVercelDataProtocol()` for Next.js / SvelteKit frontends
### DON'T
- Don't declare an AI Agent without `#[Tool]` declarations if it needs to call functions - tools must be registered explicitly
- Don't store API keys in `config/ai.php` directly; use `env()` so values aren't committed
- Don't use `Lab::OpenAI` strings - use the enum for type safety
- Don't loop manually over `Embeddings::for()` items; pass the full array - the SDK batches efficiently
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.