agentleFS
kwhornekwhorne/elyra-skills/skills/laravel-ai-features/SKILL.md

laravel-ai-features

Skill1 starsChanged 7 months agoMITView on GitHub

Build AI features in Laravel with the laravel/ai SDK - agent and tool design, structured output, conversation storage, queued AI work, testing with fakes, and cost control. Use when adding AI functionality to a Laravel app, designing agents or tools with laravel/ai, reviewing AI integration code, or wiring LLM calls into jobs and Livewire components.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the SDK's conversation storage for chat history.

    line 65
  2. Very specific:

    Keep a small real-call eval suite (@group ai-evals), run on prompt/model changes, not in CI's hot path

    line 72
  3. Distinctive:

    Never let CI depend on a live LLM API for correctness

    line 73

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Laravel AI Features

Wire LLM calls into Laravel the Laravel way: agents as small focused classes, side effects through tools, slow work on queues, and everything testable with fakes.

For model-agnostic design (evals, fallbacks, prompt contracts) see llm-feature-design — this skill is the Laravel-specific layer on top.

When to use

  • Adding AI features to a Laravel app (chat, summarization, extraction, agents)
  • Designing agents/tools with the laravel/ai SDK
  • Reviewing AI integration: error handling, cost, queueing, testing
  • "Where does the LLM call go?" in a Laravel architecture

Principles

  • Agents are classes, not config. One agent = one job-to-be-done with a tight instruction set. Five vague agents lose to one sharp one per task.
  • Side effects go through tools. The model proposes; your tool code validates and executes — with the same authorization you'd demand from a controller.
  • LLM calls are slow I/O. Anything non-interactive belongs in a queued job; anything interactive should stream.
  • Untrusted in, validated out. User input can steer the model (prompt injection); model output is parsed and schema-checked before anything acts on it.

Process

1. Place the call correctly

Use casePlacement
Chat / interactiveController or Livewire action, streamed to the UI
Enrichment (summarize, classify, tag)Queued job (see laravel-queue-design)
Bulk processingBatched queued jobs, rate-limited queue
Inline in a web request, blockingAlmost never — only sub-second, cached, or trivial calls

2. Design the agent

  • One agent class per task, instructions versioned in code (review like any other code)
  • Inject runtime context (user, tenant, locale) explicitly — never let the model guess
  • Pick the smallest model that passes your eval set; make the model a constructor/config concern so it's swappable

3. Design the tools

  • Tool = capability boundary. Validate parameters like a FormRequest; authorize against the acting user, not "the agent"
  • Destructive operations: tool creates a pending action requiring confirmation, or is simply not exposed
  • Return small, structured results — the tool result is prompt context and costs tokens
  • Log every tool invocation with arguments (audit trail for "why did the AI do that?")

4. Demand structured output

  • Schema-constrained responses for anything programmatic; map to DTOs/enums at the boundary
  • Validate before use; one retry with the validation error fed back, then fallback (default value, human queue, degraded UX)
  • Give the model an explicit out (null / "unknown") — or it will invent one

5. Handle conversation state

  • Use the SDK's conversation storage for chat history; cap context (last N messages or a rolling summary) — unbounded history is unbounded cost
  • Multi-tenant: conversations scoped by tenant/user like any other model, in queries and policies

6. Test it

  • Fake at the SDK boundary in feature tests: assert your code's behavior given a canned AI response — including a malformed one
  • Tools: plain unit tests (they're just classes)
  • Keep a small real-call eval suite (@group ai-evals), run on prompt/model changes, not in CI's hot path
  • Never let CI depend on a live LLM API for correctness

7. Control cost and failure

  • Token/request budgets per user or tenant (rate limiter); track cost per feature in logs/metrics
  • Timeouts + retry-with-backoff on provider errors; circuit-break to fallback behavior on provider outage (see resilience-patterns)
  • Cache deterministic calls (same input → same enrichment) keyed on a content hash + prompt version

Output format

## AI feature: <name>

**Agent:** <class> — task, model, instruction version.
**Placement:** streamed controller / queued job / batch.

### Tools
| Tool | Validates | Authorizes | Destructive? |
|------|-----------|------------|--------------|
| …    | …         | policy X   | no / confirm-gated |

### Output contract
Schema: … → on invalid: retry ×1 → fallback: …

### Tests
Faked: … | Evals: N cases (manual trigger)

### Cost guards
Budget: …/user/day, cache: …, circuit breaker: …

Anti-patterns

  • ❌ Synchronous LLM call in a web request with no timeout, spinner, or fallback
  • ❌ Tools that execute without authorization because "the agent decided"
  • ❌ Parsing free-text model output with regex instead of structured output
  • ❌ CI that calls a real LLM API — slow, flaky, expensive, nondeterministic
  • ❌ Unbounded conversation history shipped to the model on every message
  • ❌ Prompt instructions edited ad hoc with no version trail
  • ❌ One mega-agent with twenty tools instead of focused agents per task

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.