Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

An agent can issue refunds up to 500 dollars. Design the human approval flow so the agent proposes refunds, a person approves, and nothing is paid twice or without approval.

The agent's tool only creates a pending refund proposal with amount, reason and evidence; it has no access to the payment API. A person approves the proposal in a UI, where the approval is checked against their permissions and limits and recorded with identity and time, and execution then calls the payment provider with an idempotency key taken from the proposal so retries cannot pay twice. Stale proposals expire, account state is validated again at execution time, every step is audited, and the rejection rate tells us how to tune the agent.

Why this question is asked

Letting an agent touch money is where AI design meets classic payment engineering. The model may propose the wrong amount, propose twice, or be manipulated, and networks may time out at the worst moment. The design must guarantee two things regardless: no refund without approval, and no refund paid twice. Interviewers ask this because it tests state machines, idempotency, authorization and audit, all around an LLM. In this answer, we will design the proposal record, the approval step, idempotent execution, expiry and re-validation, and the audit and feedback loop.

1A Quick Recap of the Two Guarantees

The first guarantee, nothing paid without approval, is about who can reach the payment API. If the agent has any tool that can pay, a confused or manipulated model can pay. So the agent must have no such tool. The second guarantee, nothing paid twice, is about retries. Payment calls can time out after the provider has actually processed them; if we simply retry, we may refund twice. Idempotency, the property that doing an operation twice has the same effect as doing it once, solves that, usually through an idempotency key the provider uses to recognise a repeated request.

2The Agent Creates Proposals, Nothing More

The agent's only refund tool is proposeRefund. It writes a row in a refund_proposal table with status PENDING, the order, the amount, the reason and the evidence, for example the delivery record showing the parcel was lost. The tool checks basic rules in code: the amount is positive, at most 500 dollars and no more than the amount paid on the order, and there is no other open proposal for the same order. It returns the proposal id, and the agent tells the customer that a colleague will review the request.

Java
record RefundProposal(UUID id, String orderId, BigDecimal amount, String reason,
String evidence, Status status, Instant createdAt, Instant expiresAt) {}
enum Status { PENDING, APPROVED, REJECTED, EXPIRED, EXECUTING, PAID, FAILED }
@Tool(description = "Propose a refund for review by a staff member. Does not pay anything.")
String proposeRefund(String orderId, BigDecimal amount, String reason, String evidence) {
Order order = orders.forCurrentCustomer(orderId); // ownership checked
if (amount.signum() <= 0 || amount.compareTo(new BigDecimal("500")) > 0
|| amount.compareTo(order.paidAmount()) > 0) return "Amount not allowed";
if (proposals.hasOpenProposal(orderId)) return "A refund is already under review";
RefundProposal p = proposals.create(orderId, amount, reason, evidence, Duration.ofHours(48));
return "Proposal " + p.id() + " created for review"; // status PENDING
}

3A Person Approves, Within Their Limits

Staff see pending proposals in a review screen with the evidence and order history. When someone clicks approve, the server checks their permissions: they have the refund-approver role, and their personal limit covers the amount, for example 200 dollars for junior staff and 500 for team leads. The server also refuses approval by the same person who requested the refund, if the agent was acting for a staff member. The approval is recorded with the approver's identity and timestamp, and the status changes from PENDING to APPROVED with a conditional update, so two people clicking at once cannot both approve.

SQL
-- succeeds for exactly one approver; the other sees 0 rows updated
UPDATE refund_proposal
SET status = 'APPROVED', approved_by = :staffId, approved_at = now()
WHERE id = :id AND status = 'PENDING' AND expires_at > now();
Refund proposal states
StateEntered whenCan move to
PENDINGagent creates the proposalAPPROVED, REJECTED, EXPIRED
APPROVEDauthorised person approvesEXECUTING
EXECUTINGworker starts the payment callPAID, FAILED
PAIDprovider confirms the refundfinal
REJECTED, EXPIRED, FAILEDrejected, too old, or account no longer validfinal (FAILED may be retried by staff)

4Executing Once, With an Idempotency Key

A worker picks up approved proposals and calls the payment provider. The idempotency key is the proposal id itself. If the call times out, the worker retries with the same key, and the provider returns the result of the first request instead of refunding again. Most payment providers support idempotency keys on refund requests; if ours does not, we must first query the provider for an existing refund tied to the proposal before retrying.

Step throughApproval and execution
StaffRefund serviceDatabasePayment provider
approve proposal P-31
UPDATE status APPROVED WHERE PENDING
re-check order and account, set EXECUTING
refund 40.00, idempotency key P-31
timeout
retry refund 40.00, idempotency key P-31
refund R-77 (same as first request)
status PAID, provider ref R-77

8 messages in order. Play them, or step through them one at a time.

The retry reuses the key, so the provider returns the original refund instead of paying again.

Notice that the status moves to EXECUTING before the call and to PAID only after confirmation, and the provider's refund reference is stored. If the worker crashes, a recovery job finds proposals stuck in EXECUTING and retries them with the same key, which is safe for the same reason.

5Expiry and Re-validation at Execution Time

A proposal that sits for a week may no longer make sense. So proposals expire, for example after 48 hours, and a scheduled job marks old PENDING ones as EXPIRED. And at execution time the service checks the account and order again: the order has not already been refunded through another channel, the customer has not charged back the payment with their bank, the account is not closed or flagged for fraud, and the total refunded stays within the amount paid. If anything changed, the proposal fails with a clear reason instead of paying.

6Audit and Learning From Rejections

Every step is written to an audit log: the conversation and tool call that created the proposal, the evidence, who approved or rejected it and when, the payment request and the provider's response. This answers any later question from finance or the customer. We also measure how often staff reject proposals and why, using a reason picked at rejection time. A high rejection rate for one reason, such as 'evidence does not support a lost parcel', points to prompt or tool changes, and those changes are tested on an evaluation set built from past proposals before release.

7Follow-up questions

Why not let the agent pay refunds under 20 dollars automatically?

It can be a later step, once the rejection rate for small refunds is very low over months, but it should still go through the same proposal and idempotent execution path, just with an automatic approver rule that is logged and limited per customer and per day.

What stops the agent from splitting a 900 dollar refund into two proposals of 450?

The rule of one open proposal per order, plus the rule that the 500 dollar limit applies to the total the agent has refunded on an order, not to each proposal, so a second proposal of 450 is refused. A check that total refunds never exceed the amount paid and a daily limit per customer add further protection. These are enforced in code and the database, not in the prompt.

What happens if the provider call succeeds but our database update fails?

The key is the proposal id, which already exists before the call. On recovery, the job retries with the same key, gets the existing refund back from the provider, and then records PAID, so the state converges without a second payment.

8Conclusion

In this answer, we designed a refund approval flow in which the agent only creates pending proposals with amount, reason and evidence, a person approves within their permissions and limits with identity and time recorded, execution uses the proposal id as an idempotency key so retries never pay twice, stale proposals expire and account state is re-validated at execution time, and every step is audited while rejection rates guide tuning of the agent.

What to say in the interviewAbout 80 seconds aloud

Open with

The core rule is that the agent cannot pay anything. Its only tool, proposeRefund, writes a proposal row with status pending, the order, amount, reason and evidence, after checking in code that the order belongs to the customer, the amount is at most 500 dollars and not more than was paid, and there is no other open proposal for that order.

Then, if they want more

A staff member reviews it in a UI. On approval the server checks their role and personal limit, records who approved and when, and moves the status from pending to approved with a conditional update, so two clicks cannot both approve.

A worker then executes it: it re-validates the account and order, because things may have changed, sets the status to executing, and calls the payment provider using the proposal id as the idempotency key.

If the call times out, it retries with the same key and the provider returns the original refund instead of paying twice; a recovery job does the same for anything stuck in executing. Proposals expire after, say, 48 hours.

Every step goes to an audit log, and we track rejection rates and reasons, which tell us how to improve the agent's prompts and tools.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring AI reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "An agent can issue refunds up to 500 dollars. Design the human approval flow so the...": https://scrivio-interview-library.netlify.app/spring-boot/ai-agents-and-mcp/f323875c8a/