Skip to content
armanazij.com

Laravel AI SDK 1.0: tool approvals, classification and the upgrade

Laravel AI SDK 1.0 makes AI features production-ready: human-in-the-loop tool approvals, classification as its own capability, per-step middleware, and the breaking changes to plan for when upgrading from 0.x.

Rejaul Alom Khan (Arman Azij), Laravel and WordPress developer in Dhaka, Bangladesh Arman Azij 7 min read
Laravel AI SDK 1.0: tool approvals, classification and the upgrade, by Rejaul Alom Khan (Arman Azij)

Why a 1.0 matters for AI features in Laravel

Laravel AI SDK 1.0 shipped on September 23, 2026. Before that, the laravel/ai package was already usable, but a pre-1.0 package is a promise that things will still move. A 1.0 is the point where a team can put AI features into a production Laravel app and expect the public API to hold still between minor releases.

I have a few merged pull requests in laravel/ai. One preserves raw HTTP responses on stored and retrieved files, another separates text blocks around server tools in Anthropic responses. They are small fixes, but reading the package closely enough to fix it is a good way to learn what it is built for. This post covers the three parts of 1.0 I think matter most for real apps: tool approvals, classification, and the upgrade itself.

A quick map of the SDK

The package installs with Composer, publishes its config, and creates two tables for conversation history:

composer require laravel/ai
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
php artisan migrate

Providers live in config/ai.php. Text generation covers OpenAI, Anthropic, Gemini, Azure, Bedrock, Groq, xAI, DeepSeek, Mistral, Ollama, OpenRouter, Cohere and any OpenAI-compatible endpoint. Images, speech, transcription, embeddings, reranking and files each have their own provider list in the docs.

The core idea is the agent: a class you generate with php artisan make:agent SalesCoach, which implements the Agent contract, uses the Promptable trait, and can opt into Conversational, HasTools and HasStructuredOutput. You call ->prompt(...) and cast the response to a string. Streaming, queueing, broadcasting, failover between providers and usage tracking sit on top of that.

Tool approvals: the feature that makes agents safe to ship

An agent with tools is an agent that can change things: refund an order, send an email, update a record. The question every team asks before shipping one is what happens when the model calls the wrong tool with the wrong arguments.

Laravel's answer is human-in-the-loop approval. It first appeared in v0.10 in July and was reworked for 1.0. A tool opts in by implementing the Approvable contract next to Tool, and by using the InteractsWithApprovals trait. Approvable tools require approval by default. You can make the decision per call by overriding needsApproval(), which returns a boolean or an Approval with a reason:

use Laravel\Ai\Approvals\Approval;

public function needsApproval(Request $request): Approval|bool
{
    return Approval::required('Refunds always need a human.');
}

When the model calls such a tool, the agent stops before running it and returns the pending calls:

if ($response->hasPendingApprovals()) {
    foreach ($response->pendingApprovals as $approval) {
        // $approval->id, $approval->tool, $approval->arguments, $approval->reason
    }
}

Your app shows those to a person. When they decide, you resume the same conversation and pass one decision per tool call ID:

$response = (new SupportAgent)
    ->continue($conversationId, as: $user)
    ->prompt(Decisions::from([
        'call_abc' => Decision::approve(),
        'call_ghi' => Decision::reject('This order is outside the return window.'),
    ]));

A few rules make this work in practice:

  • The agent must be conversational with its history saved. The RemembersConversations trait does that.
  • Every pending call needs a decision. Missing or unknown IDs throw an exception instead of guessing. approveRemaining() and rejectRemaining() set a default for the rest.
  • A rejection with a reason goes back to the model, so it can explain or try something else. A rejection without one stops the loop.
  • It works with prompt, stream, queue and the broadcast methods. When streaming, the pause arrives as a tool_approval_request event. Queued agents fire a ToolApprovalRequested event.
  • Pauses are per call, not per step. Tools in the same step that do not need approval still run, so keep their side effects idempotent.

The design choice I like is that approval lives on the tool, not in the prompt. You do not have to trust the model to ask permission. The framework enforces it.

Classification as its own capability

Plenty of "AI features" are really decisions: is this ticket urgent, which team owns it, is this comment spam. Sending a full chat prompt for that is slow and returns text you then have to parse. 1.0 makes classification a separate capability:

$response = Classification::of($ticket->body)->questions([
    'is_urgent' => new Boolean('Does this message convey urgency?'),
    'department' => new Choice('Which team should handle this?', [
        'billing' => 'Payments, invoicing, refunds',
        'technical' => 'Bugs, outages, integrations',
        'sales' => 'Pricing, plans, upgrades',
    ]),
])->classify();

$response['is_urgent']->isTrue();
$response['department']->choice; // 'technical'

There is also a Score question type for a value between 0 and 1, and a decide macro on Str for one-line yes/no checks such as Str::of($message)->decide('Is this spam?').

Two cautions. Provider support is narrower than for text, and the release post and the docs table list different providers, so check the docs for your provider. And the docs label classification as experimental, with a note that the API may change in minor releases. I would use it for triage and routing today, and pin the package version until that label is gone.

Middleware now runs on every step

Agent middleware used to wrap a whole prompt. In 1.0 it wraps each generation step. Each step arrives as a PendingStep that you can inspect and copy with changes: a different model, fewer tools, a lower token limit. That makes rules like "only allow the search tool on the first step" possible without writing a custom agent loop. If you wrote middleware before 1.0, it needs to be reviewed, not just recompiled.

Raw responses when you need them

Sometimes the SDK's clean response is not enough and you need the provider's actual HTTP response, for example to read rate-limit headers:

$response->raw->header('X-RateLimit-Remaining-Requests');

raw is an Illuminate\Http\Client\Response or null, and each step keeps its own. It is null when streaming, with the Bedrock provider, and on fakes unless you set one with withRawResponse. Handle the null case and this is a cheap way to back off before a provider starts returning errors.

Upgrading from 0.x

1.0 has real breaking changes in four areas: conversation storage, agent middleware, token usage and stream protocols.

  • Usage. promptTokens and completionTokens are now inputTokens and outputTokens. Cached and reasoning tokens are subsets of those totals, so dashboards that added them on top will double count.
  • Storage. Conversation messages now keep one steps JSON column, one entry per round trip, with each tool result stored next to its call. Raw SQL against the old tool_calls or tool_results columns must move to steps, and a backfill migration must run once before you deploy 1.0.
  • Middleware. It is per step now, as above.
  • Streams. Front-end code that parses the stream should be tested against the new protocol.

The package ships an UPGRADE.md on its 1.x branch with before-and-after code and an impact level for each change. If you use Laravel Boost, the release also adds an /upgrade-ai-sdk-v1 command for AI coding tools that walks through the guide.

Takeaways

  • 1.0 is the version to build production AI features on, as long as you plan the upgrade from 0.x.
  • Put approvals on any tool that changes data or money. The framework pauses the run; your app collects the decision.
  • Use classification for triage and routing, and pin the version while it is marked experimental.
  • Review agent middleware: it now runs on every step.
  • Run the storage backfill migration once before deploying 1.0, and rename the token usage fields in your dashboards.
Tags: #Laravel #AI #PHP

More articles

All posts
Abilities and MCP: making your WordPress plugin callable by AI agents, by Rejaul Alom Khan (Arman Azij)

6 min read

Abilities and MCP: making your WordPress plugin callable by AI agents

The Abilities API has been in WordPress Core since 6.9, and the MCP Adapter is now a WordPress.org plugin. How to register typed, permission-checked abilities, expose them over REST and MCP, and keep AI clients safely limited.

  • #WordPress
  • #AI
  • #Security
Rejaul Alom Khan (Arman Azij), Laravel and WordPress developer in Dhaka, Bangladesh

Let’s talk

Arman Azij