Human-in-the-loop tool approval in the Laravel AI SDK pauses an agent before it runs a sensitive tool, such as one that sends an email or issues a refund. Your app shows the pending call to a person, then resumes the conversation with their decision. Until recently, you could not test the second half of that flow with a faked agent.
Laravel AI SDK v1.4.0 fixes that. A faked agent now resumes a paused tool call the same way a real provider does: an approved tool runs, a rejected one gets a denied result, and both are stored in the conversation. The change came from @pascalbaljet in #1190.
Faked Approvals Before 1.4
Agent::fake() could already return a paused response, either from a faked tool call or from AgentResponse::fakeWithPendingApprovals(). Resuming it did not work. When you sent decisions to the fake, it skipped the approval and returned its next response. The approved tool never ran, no tool result was streamed or stored, and a UI built on the stored conversation kept showing the call as waiting for approval.
The Agent and Tool Under Test
These examples use a support agent with one approvable tool. Resuming a paused call needs the conversation history, so the agent uses RemembersConversations:
use Laravel\Ai\Concerns\RemembersConversations; use Laravel\Ai\Contracts\Agent; use Laravel\Ai\Contracts\Conversational; use Laravel\Ai\Contracts\HasTools; use Laravel\Ai\Promptable; class SupportAgent implements Agent, Conversational, HasTools { use Promptable; use RemembersConversations; public function instructions(): string { return 'You help customers with their accounts.'; } public function tools(): iterable { return [new SendReleaseNotes]; } }
The tool implements Approvable and uses the InteractsWithApprovals trait, so every call needs approval:
use Illuminate\Contracts\JsonSchema\JsonSchema; use Illuminate\Support\Facades\Mail; use Laravel\Ai\Concerns\InteractsWithApprovals; use Laravel\Ai\Contracts\Approvable; use Laravel\Ai\Contracts\Tool; use Laravel\Ai\Tools\Request; class SendReleaseNotes implements Approvable, Tool { use InteractsWithApprovals; public function description(): string { return 'Email the latest release notes to an address.'; } public function handle(Request $request): string { Mail::to($request['email'])->send(new ReleaseNotes); return "Release notes sent to {$request['email']}."; } public function schema(JsonSchema $schema): array { return [ 'email' => $schema->string()->required(), ]; } }
Conversations are stored in the database, so the test class needs the RefreshDatabase trait or an equivalent.
Test an Approved Tool Call
To test an approved tool call, you need to fake two responses: a tool call, which pauses the run, and the text the model returns after the tool runs. Then prompt the agent, check the pause, and resume with an approval:
use Illuminate\Support\Facades\Mail; use Laravel\Ai\Approvals\Decision; use Laravel\Ai\Approvals\Decisions; use Laravel\Ai\Responses\Data\ToolCall; test('approved release notes are emailed', function () { Mail::fake(); $user = User::factory()->create(); SupportAgent::fake([ new ToolCall('call-1', 'SendReleaseNotes', ['email' => 'john@example.com']), 'The release notes are on their way.', ]); $paused = (new SupportAgent)->forUser($user)->prompt('Email John the release notes'); expect($paused->hasPendingApprovals())->toBeTrue() ->and($paused->pendingApprovals[0]->tool)->toBe('SendReleaseNotes'); Mail::assertNothingSent(); $resumed = (new SupportAgent) ->continue($paused->conversationId, as: $user) ->prompt(Decisions::from(['call-1' => Decision::approve()])); expect($resumed->toolResults[0]->result)->toBe('Release notes sent to john@example.com.') ->and($resumed->text)->toBe('The release notes are on their way.'); Mail::assertSent(ReleaseNotes::class, fn ($mail) => $mail->hasTo('john@example.com')); });
The tool's handle() method runs, so the test checks the email it sends. The tool result is also stored on the assistant message in the conversation, the same as it would be against a provider. A test that uses stream() instead of prompt() receives a ToolResult stream event for the approved call.
Test Rejections
A rejection with a reason sends that reason to the model as a denied tool result, and the run continues with the fake's next response:
$resumed = (new SupportAgent) ->continue($paused->conversationId, as: $user) ->prompt(Decisions::from([ 'call-1' => Decision::reject('John already received these.'), ])); expect($resumed->toolResults[0]->denied)->toBeTrue() ->and($resumed->toolResults[0]->error())->toBe('John already received these.'); Mail::assertNothingSent();
A rejection without a reason works differently. The SDK records "The user rejected this tool call." as the result and ends the turn without asking the model to continue. Faked agents now follow the same rule. If your test expects a reply after a rejection, pass a reason.
Test Edited Arguments
A person can also change the arguments before approving. Decision::edit() runs the tool with the new arguments in place of the model's:
$resumed = (new SupportAgent) ->continue($paused->conversationId, as: $user) ->prompt(Decisions::from([ 'call-1' => Decision::edit(['email' => 'john@work.example']), ])); Mail::assertSent(ReleaseNotes::class, fn ($mail) => $mail->hasTo('john@work.example'));
When a Fake Resumes the Tool
A faked agent runs the approval only when the conversation paused on a tool that the agent has and that requires approval. A pause faked with AgentResponse::fakeWithPendingApprovals() counts, as long as it names a real tool:
use Laravel\Ai\Approvals\PendingApproval; use Laravel\Ai\Responses\AgentResponse; SupportAgent::fake([ AgentResponse::fakeWithPendingApprovals([ new PendingApproval('call-1', 'SendReleaseNotes', ['email' => 'john@example.com'], 'Sends an email'), ]), 'The release notes are on their way.', ]);
In other cases, the fake behaves as it did before 1.4 and returns its next response. That includes decisions sent when nothing is paused, a pause naming a tool the agent does not have, and a tool registered with withoutApproval().
Decisions for a tool call ID that is not pending throw an ApprovalMismatchException, the same as against a provider. The ToolApprovalResolved event fires on resume with the conversation ID and the tool results, so you can test a listener for it with Event::fake([ToolApprovalResolved::class]).
Updating Existing Tests
Tests written against 1.3 may need two changes. An approved tool now runs, so a test that approves a call to a tool with side effects needs to fake those side effects, as Mail::fake() does above. A test that rejects without a reason and then asserts on the fake's next response needs a reason added, such as Decision::reject('Not now.').