All skills
asyrafhussin avatar

/laravel-ai-sdk

@7221662

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.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/laravel-ai-sdk

This session only. Nothing lands on disk.

rulestest-agents.md

≈839 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Testing Agents

Impact: HIGH (Fake agent responses and assert prompts in tests)

Use Agent::fake() to prevent real API calls in tests and control agent responses. Assert that agents were prompted with expected inputs.

Bad Example

// Calling real AI providers in tests — slow, expensive, non-deterministic
test('coach analyzes transcript', function () {
    $response = (new SalesCoach)->prompt('Analyze this...');

    // Flaky: different response every run, costs money, requires API key
    expect((string) $response)->toContain('feedback');
});

Good Example

use App\Ai\Agents\SalesCoach;
use Laravel\Ai\Prompts\AgentPrompt;

// Auto-generate fixed response for every prompt
test('coach analyzes transcript', function () {
    SalesCoach::fake();

    $response = SalesCoach::make()->prompt('Analyze this transcript...');

    // Assert the agent was prompted
    SalesCoach::assertPrompted('Analyze this transcript...');
});
// Provide specific responses
test('coach returns expected feedback', function () {
    SalesCoach::fake([
        'Great job on the opening.',
        'Second response for next prompt.',
    ]);

    $response = SalesCoach::make()->prompt('Analyze this...');

    expect((string) $response)->toBe('Great job on the opening.');
});
// Dynamic responses based on prompt content
test('coach responds contextually', function () {
    SalesCoach::fake(function (AgentPrompt $prompt) {
        return 'Response for: ' . $prompt->prompt;
    });

    $response = SalesCoach::make()->prompt('Analyze this...');

    expect((string) $response)->toBe('Response for: Analyze this...');
});
// Assert with closures for flexible matching
test('coach receives transcript', function () {
    SalesCoach::fake();

    SalesCoach::make()->prompt('Analyze the Q4 sales transcript...');

    SalesCoach::assertPrompted(function (AgentPrompt $prompt) {
        return $prompt->contains('Q4');
    });

    SalesCoach::assertNotPrompted('Missing prompt');
    SalesCoach::assertNeverPrompted(); // fails — was prompted
});
// Assert queued agent invocations
use Laravel\Ai\QueuedAgentPrompt;

test('coach is queued', function () {
    SalesCoach::fake();

    SalesCoach::make()->queue('Analyze this...');

    SalesCoach::assertQueued(function (QueuedAgentPrompt $prompt) {
        return $prompt->contains('Analyze');
    });
});
// Prevent stray prompts — fail if any agent is called without a fake
test('no unexpected agent calls', function () {
    SalesCoach::fake()->preventStrayPrompts();

    // SalesCoach::make()->prompt('...'); // OK — has fake
    // (new OtherAgent)->prompt('...');   // Would throw — no fake
});

Structured output agents auto-generate fake data matching the schema.

Why

  • Fast: No API calls, no network latency
  • Deterministic: Same response every run
  • Free: No API costs in test suites
  • Assertable: Verify exactly what was prompted and how many times
  • Safe: preventStrayPrompts() catches accidental real API calls

Reference: Laravel AI SDK — Testing Agents

Source: SKILL.md on GitHub

1 warning16d4 checks · Risk MEDIUM
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive guide for the Laravel AI SDK but contains deceptive metadata claiming authorship by the 'Laravel Community' despite being associated with the user 'asyrafhussin'. It also presents an indirect prompt injection surface by documenting patterns for ingesting untrusted data (such as transcripts and external URLs) while granting agents capabilities like file system storage and network access.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 7221662. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
Other metadata
metadata
{
  "author": "Laravel Community",
  "version": "1.0.0",
  "laravelVersion": "13.x",
  "phpVersion": "8.3+"
}

README badge

README badge for asyrafhussin/agent-skills/laravel-ai-sdk