Skip to content

Laravel AI Tasks

AI task orchestrator for Laravel. Handles routing, queuing, audit logging, budget tracking, and webhook processing on top of laravel/ai as the transport layer.

Every AI call is a task class: it builds the request, optionally shapes the response, and reacts to the final result. The package takes care of everything around the call:

  • Routing with fallback — a chain of drivers per task; the next one is tried when a provider is down
  • Queues — AI::queue() with idempotency, delayed dispatch, retries of unusable results
  • Audit log — every run is stored in ai_runs: driver, model, tokens, cost, duration, status
  • Budgets — monthly spend limit per tenant
  • Cost tracking — per-driver and per-model rates, prompt-cache tokens, reasoning tokens
  • Dashboard — runs list, driver state, stuck runs, retry from the browser
  • Modalities — text, image, embeddings, text-to-speech, transcription
  • Tools & MCP, structured output, tool approval, streaming
  • Testing — AI::fake() with assertions

Dashboard

use Fomvasss\AiTasks\DTO\AiPayload;
use Fomvasss\AiTasks\Tasks\AiTask;
use Laravel\Ai\Messages\UserMessage;
class SummarizeTask extends AiTask
{
public function __construct(private readonly string $text) {}
public function modality(): string
{
return 'text';
}
public function toPayload(): AiPayload
{
return new AiPayload(
modality: 'text',
messages: [new UserMessage("Summarize: {$this->text}")],
systemPrompt: 'Reply in 3 sentences max.',
);
}
}
use Fomvasss\AiTasks\Facades\AI;
$response = AI::send(new SummarizeTask($article->body));
echo $response->content;

Getting started

  1. Installation
  2. Configuration

Usage

  1. Tasks
  2. Running tasks
  3. Queued tasks
  4. Driver routing
  5. Structured output
  6. Tools & MCP
  7. Tool choice & approval
  8. Modalities
  9. Budgets & tenants
  10. Cost tracking
  11. Per-request provider override
  12. Dashboard
  13. Async providers & webhooks
  14. Testing

Guides — experience from production integrations

  1. Production checklist
  2. Building a chat assistant
  3. Tools in practice
  4. Provider quirks
  5. Testing in practice

Reference

  1. AI facade
  2. AiTask methods
  3. AiPayload & AiResponse
  4. The ai_runs table
  5. Events
  6. Artisan commands
  7. Providers

Upgrading