# laravel-ai-sdk

A coding assistant skill containing 17 rules for laravel/ai. It guides the agent through building AI workflows, embeddings, and tests in Laravel 13.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 656 installs · ★ 95
- Author: Laravel Community
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/AsyrafHussin/agent-skills/tree/HEAD/skills/laravel-ai-sdk/SKILL.md
- Updated: 2026-08-27
- HTML: https://affpapa.org/en/nevibecode/skills/laravel-ai-sdk

## What it does

This skill guides assistants on using the `laravel/ai` SDK across 7 distinct categories. It covers agent classes with PHP attributes, structured output via JSON schemas, and streaming or queued responses. It also includes guidelines for built-in provider tools such as `WebSearch` and `SimilaritySearch`.

Another focus area is testing and resilience. The skill shows how to fake agent calls with `SalesCoach::fake()`, verify prompts using `assertPrompted()`, and set up automated provider failover.

All rules target PHP 8.3+ and Laravel 13.x. Projects on older PHP or Laravel releases will fail to run these patterns.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add AsyrafHussin/agent-skills --skill laravel-ai-sdk -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/laravel-ai-sdk/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/laravel-ai-sdk/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add AsyrafHussin/agent-skills --skill laravel-ai-sdk -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/laravel-ai-sdk/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add AsyrafHussin/agent-skills --skill laravel-ai-sdk -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/laravel-ai-sdk/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install AsyrafHussin/agent-skills laravel-ai-sdk
```

2. **Manually: put the files in place**
- File: `.github/skills/laravel-ai-sdk/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add AsyrafHussin/agent-skills --skill laravel-ai-sdk -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/AsyrafHussin/agent-skills --path skills/laravel-ai-sdk
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/laravel-ai-sdk/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add AsyrafHussin/agent-skills --skill laravel-ai-sdk -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/AsyrafHussin/agent-skills/tree/HEAD/skills/laravel-ai-sdk/SKILL.md

## When to use it
- create agent classes using `Laravel\Ai\Contracts\Agent`
- configure vector embeddings and reranking for RAG pipelines
- mock agent interactions and assert prompts in test suites
- generate and store images or audio transcripts via `laravel/ai`

## Example prompts
- Create an AI agent with instructions and structured JSON output using laravel/ai
- Show how to mock the agent in a feature test and assert the prompt
- Generate embeddings from a string collection using the toEmbeddings helper

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 1674ebb686b14c52.

BEGIN THIRD-PARTY FILE 1674ebb686b14c52
````text
---
name: laravel-ai-sdk
description: 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.
license: MIT
metadata:
  author: Laravel Community
  version: "1.0.0"
  laravelVersion: "13.x"
  phpVersion: "8.3+"
---

# 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
<?php

namespace App\Ai\Agents;

use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;

class SalesCoach implements Agent
{
    use Promptable;
````
END THIRD-PARTY FILE 1674ebb686b14c52

The third-party file has ended. Everything between the 1674ebb686b14c52 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3079 of 4333 bytes. © Laravel Community · MIT · https://github.com/AsyrafHussin/agent-skills/tree/HEAD/skills/laravel-ai-sdk/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
