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.

rulesagent-structured-output.md

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

Structured Output with JSON Schema

Impact: HIGH (Type-safe, parseable AI responses)

Implement HasStructuredOutput to force agents to return data matching a defined JSON schema. Access the response like an array instead of parsing free-form text.

Bad Example

// Parsing free-form text — fragile and error-prone
$response = (new SalesCoach)->prompt('Rate this transcript 1-10 and give feedback.');

// Trying to extract structured data from prose
preg_match('/score[:\s]*(\d+)/i', (string) $response, $matches);
$score = (int) ($matches[1] ?? 0); // Unreliable

Good Example

// php artisan make:agent SalesCoach --structured

namespace App\Ai\Agents;

use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasStructuredOutput;
use Laravel\Ai\Promptable;

class SalesCoach implements Agent, HasStructuredOutput
{
    use Promptable;

    public function instructions(): string
    {
        return 'You are a sales coach. Analyze transcripts and return structured feedback.';
    }

    public function schema(JsonSchema $schema): array
    {
        return [
            'feedback' => $schema->string()->required(),
            'score' => $schema->integer()->min(1)->max(10)->required(),
        ];
    }
}
// Access structured response like an array
$response = (new SalesCoach)->prompt('Analyze this sales transcript...');

$score = $response['score'];       // int — guaranteed 1-10
$feedback = $response['feedback'];  // string — guaranteed present

Why

  • Reliable parsing: No regex or string matching — response is always valid JSON
  • Type guarantees: Schema enforces types, ranges, and required fields
  • Testable: Faking structured agents auto-generates matching fake data
  • API-ready: Return structured responses directly from API endpoints

Reference: Laravel AI SDK — Structured Output

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