Capstone 5 of 8
Order-returns agent with human approval
Business requirement
A shop wants an assistant that can look up orders, check the returns policy and prepare refunds, but a staff member must approve every refund.
Lessons to finish first
Architecture
- Chat front end
- Agent loop (model chooses tools)
- Tools: get_order, check_policy, propose_refund
- Approval step before any refund
- Audit log
- Test scenarios including attacks
Build steps
- Create a fake orders table and a short returns policy.
- Write three tools with strict input schemas; propose_refund only creates a pending request.
- Build the agent loop: the model picks a tool, your code runs it, the result goes back to the model.
- Add the approval step: a person accepts or rejects; only then is the refund recorded.
- Check permissions inside each tool (a customer can only see their own orders).
- Write 20 scenarios: normal returns, out-of-policy requests, missing orders and prompt-injection attempts.
- Log every tool call with inputs, outputs and the approver.
Python route and .NET route
- Python
- LangGraph (state graph, interrupt for approval, checkpointer) or plain Python with a loop. Start from the returns-workflow example.
- .NET (C#)
- Microsoft Agent Framework or Microsoft.Extensions.AI function calling (AIFunctionFactory), with an approval-required function wrapper; ASP.NET Core for the API.
Example input and output
- Input
"I want to return order 1042, it arrived broken."- Output
"Order 1042 qualifies (within 30 days, damaged). A refund of 49.00 is waiting for staff approval."
Data
Fake orders generated by a script.
Starter file structure
agent/
tools.py | Tools.cs
graph.py | Agent/Program.cs
scenarios/*.json
README.mdTests
- No refund is recorded without approval
- Customer A cannot see customer B’s order
- Injection in an order note does not trigger a tool call
- Out-of-policy request is refused with the reason
How it will be judged
- Least-privilege tools
- Approval cannot be skipped by the model
- Full audit trail
- Scenario pass rate reported
Security and privacy
Enforce permissions and approval in code, not in the prompt; never give the agent a tool that moves money directly.
Definition of done
- 20 scenarios with results
- Approval demonstrated in a recording
- Audit log shows every action
Stretch goals
- Use the RAG assistant from capstone 4 for policy questions
- Add a cost cap per conversation
- Add an escalation path to a human agent
What to show an employer
Scenario results table and a demo of an approved and a rejected refund.
Completion
Saved in this browser only.