An AI agent that only reads data is easy to trust. An agent that can refund a payment, delete a record or email a customer is a different story. Two things make that kind of agent safe to ship with the Laravel AI SDK:

  1. Human approval: the agent pauses before a sensitive tool runs and waits for a person to approve or reject it.
  2. Failure recovery: since v1.4.0 (November 13, 2026), a tool that throws no longer crashes the run; the model is told what went wrong and can respond.

In this post we’ll build a support agent that can look up orders freely but needs a manager’s approval before a large refund, handles refusals gracefully, and is covered by tests.

Why approval belongs in code, not the prompt

Why not tell the model “be careful with refunds” in the system prompt? Because a prompt is a suggestion, not a guarantee. Models misread context, get manipulated by text inside user messages, and occasionally hallucinate an order ID. An approval gate is enforced in code, so it holds no matter what the model was talked into.

The model still decides what it wants to do. Your code decides whether it happens. Approval is per tool and opt-in: read-only tools keep running instantly.

Setup

Approval needs persisted conversation history, because a paused agent resumes from stored state:

composer require laravel/ai php artisan migrate 

Configure your provider key in config/ai.php. Upgrading an older install? Human-in-the-loop arrived in v0.10.0 and added a nullable approval_state column to the conversation messages table; custom ConversationStore implementations must provide storeApprovalResults().

Step 1: Make the refund tool approvable

Implement Approvable and use InteractsWithApprovals. Define needsApproval() so small refunds run immediately and large ones pause with a reason the reviewer will see:

use Laravel\Ai\Approvals\Approval; use Laravel\Ai\Concerns\InteractsWithApprovals; use Laravel\Ai\Contracts\Approvable; use Laravel\Ai\Contracts\Tool; class IssueRefund implements Approvable, Tool { use InteractsWithApprovals; public function handle(Request $request): Stringable|string { $order = Order::findOrFail($request['order_id']); if ($order->delivered_at->lt(now()->subDays(30))) { throw new RuntimeException( "Order {$order->id} can no longer be refunded: it's outside the 30-day window." ); } $order->refund($request['amount']); return "Refunded {$request['amount']} on order {$order->id}."; } protected function needsApproval(Request $request): Approval|bool { return $request['amount'] <= 100 ? false : Approval::required('Refunds over $100 need a manager.'); } // description() and schema() as for any tool } 

Step 2: Register tools on the agent

The agent must be Conversational with persisted history, which RemembersConversations handles:

use Laravel\Ai\Concerns\RemembersConversations; use Laravel\Ai\Contracts\Agent; use Laravel\Ai\Contracts\Conversational; use Laravel\Ai\Promptable; class SupportAgent implements Agent, Conversational { use Promptable, RemembersConversations; public function tools(): iterable { return [ (new LookUpOrder)->withoutApproval(), new IssueRefund, ]; } } 

Want every refund reviewed? Use (new IssueRefund)->requireApproval('Every refund gets reviewed.').

Step 3: Catch the pause and queue it

$response = (new SupportAgent) ->forUser($customer) ->prompt('My headphones on order 4192 arrived broken. I want my $249 back.'); if ($response->hasPendingApprovals()) { foreach ($response->pendingApprovals as $approval) { PendingRefund::create([ 'conversation_id' => $response->conversationId, 'tool_call_id' => $approval->id, 'tool' => $approval->tool, 'arguments' => $approval->arguments, 'reason' => $approval->reason, ]); } } 

Each pending approval carries the tool call ID, tool name, the arguments the model chose, and your reason. That table is your approval queue.

Step 4: The approval screen

A manager needs to see what the agent wants to do and why:

@foreach ($pendingRefunds as $refund) <div class="card"> <p>Order #{{ $refund->arguments['order_id'] }}: refund ${{ $refund->arguments['amount'] }}</p> <p class="muted">{{ $refund->reason }}</p> <form method="POST" action="{{ route('refunds.decide', $refund) }}"> @csrf <button name="decision" value="approve">Approve</button> <button name="decision" value="reject">Reject</button> </form> </div> @endforeach 

Protect the route with a policy. The SDK checks that a decision belongs to the right conversation, but who may approve is your job.

Step 5: Resume the agent

use Laravel\Ai\Approvals\Decision; use Laravel\Ai\Approvals\Decisions; public function decide(Request $request, PendingRefund $refund) { $this->authorize('approve', $refund); $decision = $request->input('decision') === 'approve' ? Decision::approve() : Decision::reject('This order is outside the return window.'); (new SupportAgent) ->continue($refund->conversation_id, as: $refund->customer) ->prompt(Decisions::from([$refund->tool_call_id => $decision])); $refund->update(['decided_by' => $request->user()->id]); return back(); } 
  • Approve: the tool runs, its result is recorded, and the model continues.
  • Reject with a message: the message goes back to the model so it can explain.
  • Reject with no message: the rejection is recorded and the loop stops.

Every pending call needs a decision; missing or unknown IDs throw ApprovalMismatchException. For several paused calls, approveRemaining() and rejectRemaining() set a default.

When a tool fails: new in 1.4

Before 1.4, an exception inside a tool ended the run and fired AgentFailed. Now the SDK sends the message back to the model as a failed tool result. If the approved refund hits the 30-day rule in Step 1, the model receives:

The tool call failed: Order 4192 can no longer be refunded: it's outside the 30-day window. 

It can then explain that to the customer, or offer a replacement. You keep full visibility: the exception is still reported, ToolFailed still fires, and in a streamed run the failure arrives as a ToolResult event with successful set to false.

That changes how you write tools, because exception messages are now read by the model, and maybe passed to a user:

  • Write messages a model can act on. “Outside the 30-day window” lets the agent explain. “Error 500” doesn’t.
  • Never put secrets or internals in messages. SQL, stack details or keys in a message would now be sent to your AI provider.
  • Throw on purpose for business rules. A clear exception is a clean way to tell the agent “no, and here’s why”.

To keep the old crash-the-run behaviour, rethrow from a listener (listener exceptions still end the run):

Event::listen(ToolFailed::class, fn (ToolFailed $event) => throw $event->exception); 

Test the whole flow

Also new in 1.4: under Agent::fake(), resuming a paused call now behaves like a real provider. Approved tools run and store their results; rejected ones get a denied result. So you can finally test approvals end to end:

SupportAgent::fake([ new ToolCall('call-1', 'IssueRefund', ['order_id' => 4192, 'amount' => 249]), 'Your refund is on its way.', ]); $paused = (new SupportAgent)->forUser($user)->prompt('Refund order 4192'); expect($paused->hasPendingApprovals())->toBeTrue(); $response = (new SupportAgent) ->continue($paused->conversationId, as: $user) ->prompt(Decisions::from(['call-1' => Decision::approve()])); expect($response->text)->toBe('Your refund is on its way.'); 

A rejection with no reason now ends the turn under the fake too, so pass one if your test expects a reply: Decision::reject('Not now.').

Other 1.4 changes worth knowing

  • OpenAI billing errors (insufficient_quota) now throw InsufficientCreditsException instead of RateLimitedException, and aren’t retried. Alert on it and fall back to a human queue; running out of credits is an ops problem, not a transient error.
  • raw responses on classification, embeddings, transcription, image and reranking responses expose fields the SDK doesn’t map.
  • Stream errors broadcast as error, so frontends know what to listen for.
  • Conversation title generation fires agent events; check parentInvocationId to tell it apart from user turns.

Upgrade with composer update laravel/ai, then update any code that catches RateLimitedException for billing errors.

Production checklist

  • Idempotent side effects. Pauses are per tool call, not per step. Use $request->toolCallId() as an idempotency key so a retry never refunds twice.
  • An approval is spent once recorded. If generation fails after an approved tool ran, resume with a normal text prompt; don’t resubmit the decisions.
  • Notify reviewers. Queued agents dispatch ToolApprovalRequested; listen for it and ping managers.
  • Streaming works. A pause arrives as a tool_approval_request event, so a chat UI can render an inline approval card.
  • Expire stale approvals with a scheduled command that rejects old pending calls politely.
  • Keep an audit trail of who approved what, and when.

FAQ

What is human-in-the-loop in the Laravel AI SDK?

An opt-in, per-tool approval API. Tools implementing Approvable pause the agent until your code passes an approve or reject decision for each pending call.

What happens when a tool throws in Laravel AI SDK 1.4?

The run continues. The exception message is sent to the model as a failed tool result, and the exception is still reported and fires ToolFailed.

Which tools should need approval?

Any tool that moves money, deletes data or contacts a customer. Read-only tools can run freely.

Conclusion

Rule of thumb: anything that touches money, deletes data or contacts a customer should be approvable, and every tool should fail with a message a model can act on. With needsApproval(), clear exceptions and 1.4’s testable fakes, agents with real write access become safe to ship.

Are you running AI agents with write access in production yet? Tell me in the comments how you keep them in check.

Sources