System design answer
A refund agent for an online store
A tool-using agent with task-shaped tools, rules for what it may do alone, human approval above a limit, and full audit.
The question“Design an agent that handles refund requests end to end: checks the order, decides, and issues the refund.”
1Clarify0-5 min
Ask before you draw. These answers change the design.
- What refund policy applies, and which cases are judgement calls?
- Up to what amount may it refund without a person?
- Which systems: orders, payments, courier tracking?
- How many requests a day?
2Requirements and numbers5-8 min
It must
- Read the order and delivery status
- Apply the refund policy and explain the decision
- Issue refunds within limits; ask a person above them
- Tell the customer the outcome
And it must be
- No refund issued twice for the same order
- Every step logged with its reason
- A person can stop the agent at once
Numbers to say out loud
- Volume
- 8,000 refund requests a day
- Steps per run
- 4-8 tool calls, under 30 s
- Approval share
- About 10% need a person
3High-level design8-12 min
- Customer request → Agent loop
- Agent loop → get_order (read)
- Agent loop → get_delivery_status (read)
- Agent loop → refund_quote (read)
- refund_quote (read) → Within the auto limit?
- Within the auto limit? → yes → issue_refund (idempotency key = order id)
- Within the auto limit? → no → Human approval card
- Human approval card → approved → issue_refund (idempotency key = order id)
- issue_refund (idempotency key = order id) → Tell the customer
- Tell the customer → Audit log
4Deep dives12-26 min
Tools
Three read tools and one action tool, each with a strict schema. issue_refund takes a quote id, not an amount, so the model cannot invent a figure, and uses the order id as an idempotency key.
Approval
Rules decide what is automatic: under ₹2,000, delivered and within policy. Everything else pauses with a checkpoint and an approval card showing the evidence; no reply in 4 hours escalates.
5Failures26-30 min
| What can go wrong | What stops it |
|---|---|
| Double refund | Idempotency key on the order; the payment API rejects repeats |
| Agent loops | Step cap of 10 and repeated-call detection |
| Injected instructions in the message | The refund amount comes from the quote tool, never from text |
| Runaway cost | Token budget per task and a kill switch |
6Evals and monitoring30-33 min
- Sandbox runs with seeded orders: right refund state, approval before large refunds, zero safety violations
- Success on all of 3 runs per task
- Human review of a weekly sample of decisions
7Trade-offs33-35 min
- An agent over a fixed workflow only because cases vary; simple cases could be a workflow
- A lower auto limit means more approvals but less risk
Follow-ups to expect
- How do you stop it from being talked into a refund?
- How would you test it before launch?