Laravel Ai Sdk

作者 asyrafhussin1aa0ff717c10MIT86 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫6 週前更新

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.

AI 產生的概覽

使用 laravel/ai SDK 在 Laravel 中打造 AI 功能的指南,涵蓋代理、工具、嵌入、媒體與測試。

功能
這個技能是 Laravel AI SDK(laravel/ai)的參考指南,依七個類別整理成 17 條規則:代理、工具、嵌入與搜尋、媒體生成、檔案與向量儲存、基礎架構,以及測試。內容說明建立代理、帶對話脈絡的提示、結構化輸出、串流與佇列回應、自訂工具與供應商工具、圖片與音訊生成、嵌入與重排序,以及在測試中模擬 AI 功能等模式。它產出的是指引與程式碼範例,而非可直接執行的成品,並指向各規則檔案與彙整的 AGENTS.md 文件。
適用情境
適合在撰寫整合 laravel/ai SDK 的 Laravel 程式碼時使用,例如建立 AI 代理、工具呼叫、結構化輸出、串流回應、嵌入、向量搜尋或 RAG、媒體生成,或以模擬方式測試 AI 功能。它鎖定 Laravel 13 與 PHP 8.3 以上版本。
執行需求
不含指令碼,只有說明與參考文件。套用這些指引需要 Laravel 13 專案、PHP 8.3 以上版本並安裝 laravel/ai 套件,以及所述功能所需的 AI 供應商憑證與網路存取。

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

PriorityCategoryImpactPrefix
1AgentsCRITICALagent-
2ToolsHIGHtool-
3Embeddings & SearchHIGHembed-
4Media GenerationMEDIUMmedia-
5Files & StorageMEDIUMfiles-
6InfrastructureMEDIUMinfra-
7TestingHIGHtest-

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;
    public function instructions(): string    {        return 'You are a sales coach, analyzing transcripts and providing feedback.';    }}

Prompting

php
use App\Ai\Agents\SalesCoach;
$response = SalesCoach::make()->prompt('Analyze this sales transcript...');
return (string) $response;

Generating Images

php
use Laravel\Ai\Image;
$image = Image::of('A donut sitting on the kitchen counter')    ->landscape()    ->generate();
$path = $image->store();

Generating Embeddings

php
use Illuminate\Support\Str;
$embeddings = Str::of('Napa Valley has great wine.')->toEmbeddings();

Testing

php
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

來源與署名

來源:asyrafhussin/agent-skills位於skills/laravel-ai-sdk提交1aa0ff7

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架