What did the human approve? Testing an AI refund agent before it can move money

Bind approval to the tenant, order, amount, and currency. Then test changed requests, expired grants, and ambiguous retries against a fake payment provider.
Give approval a specific meaning
AWS announced the Greenlight preview on December 1, 2026. It gives teams a way to check policies for what agents can do through tools and deploy those policies to an enforcement point outside the model.
A refund policy might say an agent cannot issue a refund before someone approves it. The next question is whether approval for USD 25.00 on one order can be spent on a different amount, currency, or order. The approval service needs a record that answers that question before the tool executes.
Treat the refund arguments as a proposal. At the application boundary, read the approved intent by ID and derive the tenant from the authenticated caller. Compare the order ID, integer amount in minor units, and currency with the stored approval. Keep the provider account and charge reference bound to that intent with server-side data.
In Laravel, put refund authorization in a policy using an authenticated principal and the order loaded in that tenant. The refund service can then compare the proposal to the approval. Only the service gets provider credentials. Keep a direct provider tool out of the agent’s tool inventory.
Create the approval through a human-authorized path after displaying the account, order, amount, and currency that will be used. Record the approver and expiry. Treat every approved intent as immutable. A change requires another approval through the trusted path. If multiple approvals can be issued for one purchase, track the remaining refundable amount and reserve it atomically so different intents cannot together exceed it.
Keep the intent stable across transport failures
Give the provider one stable idempotency key per refund intent, scoped to the merchant account in production. Persist the attempt before making the external request. A successful response records the provider’s receipt. A lost response leaves the attempt unresolved because the provider may already have applied the refund.
The function below checks the approval before reading a saved receipt, so supplying a valid intent ID with changed arguments still fails after completion. A matching completed replay can return the existing receipt after the grant expires. At expiry the fixture rejects a new refund call and leaves the unresolved attempt in the database. A production reconciliation path can inspect that record separately.
The fixture injects the clock so equality at the expiry boundary is testable. In an application the executor supplies trusted time. Recheck current policy, ownership, approval revocation, and the refundable balance when admitting work. Claim or serialize execution in the database, and avoid holding an open database transaction across a network request.
<?php
function executeRefund(
PDO $db,
FakeProvider $provider,
string $tenant,
string $intent,
Refund $proposal,
int $now,
): string {
$query = $db->prepare(
'SELECT a.*, x.receipt FROM approvals a
LEFT JOIN refund_attempts x ON x.intent_id = a.intent_id
WHERE a.intent_id = ? AND a.tenant = ?'
);
$query->execute([$intent, $tenant]);
$approved = $query->fetch(PDO::FETCH_ASSOC);
$query->closeCursor();
if (!$approved || $approved['order_id'] !== $proposal->order
|| $approved['amount_minor'] !== $proposal->amountMinor
|| $approved['currency'] !== $proposal->currency) {
throw new Denied('Approval does not match request');
}
if ($approved['receipt'] !== null) {
return $approved['receipt'];
}
if ($now >= $approved['expires_at']) {
throw new Denied('Approval expired');
}
// Persist the attempt before the external call. This fixture uses autocommit.
$db->prepare('INSERT INTO refund_attempts (intent_id) VALUES (?)
ON CONFLICT (intent_id) DO NOTHING')->execute([$intent]);
$receipt = $provider->refund('refund:'.$intent, $proposal);
$db->prepare('UPDATE refund_attempts SET receipt = ? WHERE intent_id = ?')
->execute([$receipt, $intent]);
return $receipt;
}
Assert provider calls and refund effects separately
In the fixture, changing the order, amount, currency, or tenant, or presenting an expired approval, made zero provider calls. An approved request and its completed replay made one call and produced one refund. A lost response followed by a retry made two calls for one additional refund. Retrying an unresolved attempt after expiry made zero additional calls.
The fake provider accepts the refund before simulating a lost response. The application still has an unresolved attempt. Retrying with the original key gets the original receipt. Counting only HTTP responses would miss the first side effect, and counting calls would incorrectly count two refunds.
Provider idempotency has a retention window and scope. Stripe’s API v1, for example, compares parameters when an idempotency key is reused and can treat a reused key as a new request after pruning it. Set the safe retry horizon using the provider’s documented behavior. Escalate unresolved attempts beyond that horizon for reconciliation.
Reconciliation should record the result against the existing intent and use provider evidence, such as a trusted event or a lookup on a stored provider reference. A timeout alone gives the application no evidence that the charge was untouched. Minting a new key after a timeout can turn recovery into another refund.
This is a PHP and SQLite fixture for the application boundary of a hypothetical Laravel support agent. It runs without a model, HTTP authentication, Laravel, AWS, or a real payment account. Its fake provider keeps results in memory and the tests run sequentially. They establish the recorded outcomes for this fixture and give no evidence about durable provider deduplication or concurrent execution.
Check the rules where the tool executes
Use an agent policy to limit which tools can be called and the circumstances under which they are allowed. Keep the stored-approval check and the idempotency boundary in the refund executor. A tool call can be properly authorized and still hit a timeout after the provider has accepted it.
Start with tests against the operation boundary before adding an LLM. Run the same cases through the Laravel tool endpoint with real authentication and test the worker and retry path separately. Keep the status visible to support staff as pending, confirmed, or requiring reconciliation. Log the intent and policy decision without logging provider credentials or customer payment data.
Reproduce the examples
Runnable PHP and SQLite fixture, fake provider, test runner, and expected output.
Download the source and tests (.zip)
