Support and order-ops agent
A support agent for Cedar & Clay, a made-up homeware shop. Tickets arrive on a webhook. The agent looks up the customer's orders, reads the store policy and answers. It can also ask to issue a refund, change a shipping address or give store credit, and plain Python decides whether each request runs now, waits for a person or is refused.
How it works
- The tool-calling loop is written by hand with the OpenAI Responses API, with no agent framework. Each turn the model asks for a tool or finishes the ticket, and the code runs the tool against a SQLite database and sends the result back.
- The read tools only see orders that belong to the customer who sent the ticket. No tool takes an email address, and another customer's order gets the same answer as an order that doesn't exist.
- The write tools change nothing by themselves. They pass each request to plain Python checks in guardrails.py: the order must belong to the customer, refunds under $50 and store credit up to $25 run now, bigger ones wait for a person, and final-sale items or orders past the 30-day return window are refused.
- A request that waits goes into an approval queue with the rule behind it. When a person approves, decide_approval runs the checks again on the order as it is now, inside a SQLite BEGIN IMMEDIATE lock. A stale approval is blocked, and two people clicking approve at once can't run it twice.
- Each webhook event_id is handled once, and each action has its own key, so a replayed ticket or a repeated tool call does nothing new. A CHECK constraint in the database also refuses any refund total above the order total.
- A FastAPI service takes the webhook and serves the approval queue, orders and audit log. Every model call and tool call goes into a JSON Lines trace.
What I measured
I wrote 15 test tickets by hand: order questions, actions that should run on their own, actions that should wait for approval, requests the policy refuses, 2 prompt injection attempts, a replayed webhook and 2 tickets that must be escalated. Each ticket runs on its own fresh SQLite database, and the score checks what changed in the database, not what the reply says. Any change nobody expected counts as an unauthorized write.
- Tickets passed: 15 of 15, on 3 December 2026 with gpt-5.6-luna.
- Unauthorized writes: 0.
- An email dressed up as a system notice saying the $50 limit was switched off: the $148 refund still waited for a person.
- The replayed webhook: one refund, and the second delivery made no model calls.
15 hand-written tickets is a small, made-up test. Passing shows the rules held on these tickets, not on every ticket. Escalation is still the model's judgment from the policy, so code can't catch a missed one. In the live runs the model turned down the other customer's order before asking for a refund, so the code that blocks writes on someone else's order never fired there. I checked that block separately, outside the live runs.
Limits
The webhook runs the agent before it replies, which takes a few seconds. A real help desk would queue the ticket. The webhook has no signature check and the approval endpoints have no login. If the process is killed outright, its event stays marked as processing until someone clears it. Refunds and credit only change numbers in the database, with no payment provider. It allows one action of each type per order per ticket, and money is stored as floats rounded to the cent.
Python, OpenAI Responses API, SQLite, FastAPI, Pydantic, Typer