Production notes
What would have to change to put this agent in front of real customers. Each section says what is built here and what is proposed. Nothing under "Proposed" exists in the code.
A real billing system behind execute
Built. Handlers write to an in-memory SQLite database that is created fresh for each conversation (src/backend/db.ts). Rules read the same database. execute runs the schema check, the rules and the write in one synchronous call, so nothing can come between a check and its write. New ids are the row count plus one (nextId).
Proposed.
- Keep the shape: schema, rules, then the change, with every attempt logged. Handlers become calls to the billing system, and rules read current state from it at call time, not from what
get_accountreturned earlier in the conversation. - Races. With shared data, two conversations for the same customer could both pass REF-5 and both refund, or together pass the 90-day credit limit. Take a per-customer lock or a serializable transaction around the rule check and the write, or enforce the limit in the billing system as well.
- Idempotency. Models repeat calls and networks retry. REF-1 already makes a second refund of the same invoice fail, but credits and tickets have no natural key. Give each write an idempotency key built from the conversation id and the tool call id, and pass it to the billing system. The OpenAI-compatible adapter numbers calls
call_0,call_1when a server omits ids, which is not unique across turns, so the loop should mint its own. - Ids.
nextIdis only safe on a private copy of the data. The billing system assigns ids. - No replay against real systems. The MCP server rebuilds a conversation by running its action log again (
src/mcp/conversation.ts). Against a real backend that would issue every refund again. Store the session state instead: verified customer, failed check count and the log. - Partial failure. A call can pass the rules and then fail in the billing system. Record that as its own outcome; today the log knows only executed, denied and invalid.
Human approval queues
Built. Each rule has a humanCanApprove flag. It is shown on the site's policy page and used nowhere else: a refusal does not carry it, and the agent decides from the prose whether to hand off. hand_off opens a ticket with a reason from a fixed list and a free-text summary written by the model.
Proposed.
- When
deciderefuses on a rule whose flag is true, save the exact validated call, the rule id and the message as a pending action. A person approves or declines that call, not a summary. On approval it runs throughexecutewith the approver recorded and only that rule waived; every other rule still applies. - Rules whose flag is false (ID-1, ID-3, REF-1, REF-3, CRD-3, PLAN-1, PLAN-3) never reach a queue. That removes the failure in
upgrade-then-cancel-other, where the ticket asked a person to cancel another customer's subscription. - Enforce one open ticket per conversation in the action layer. Two versions of the instructions did not make it hold.
- Size the queue from real traffic. Between 290 and 327 of each version's 1,008 saved conversations opened a ticket, but the test set is weighted toward edge and attack cases, so that rate is no forecast.
Refused calls per rule as a live signal
Built. Every attempt is logged with its outcome and rule id, and summarize in src/eval/run.ts counts refusals by rule. In the saved runs this is the number that moved most between versions: 66, 54 and 8 refused calls for v1, v2 and v3.
Proposed. Track refused calls per rule per thousand conversations, by agent version and model, and alert on a step change.
- A rise in REF-2 or REF-5 means the agent is guessing at dates and totals again, the v1 pattern.
- A rise in ID-2 means guessing at identity answers, or a broken verification flow.
- Any ID-3 deserves a look. No model triggered it in 3,528 test conversations.
- A rise in invalid arguments (12 calls under v1, 6 under v3) usually means the tool schemas and the model disagree after a model or server change.
- Run the audit on each finished conversation against before and after snapshots of the affected customer, and page someone on any breach. It costs no model call.
- Sample conversations with executed money actions for human review. Nothing in the code measures "did what nobody asked for".
Releasing a new agent version or model
Built. Versions are kept side by side in AGENT_VERSIONS. npm run eval scores a version on the full set with scripted or model-played customers, saves every conversation, and exits with an error on any breach or errored run. --resume fills in missing runs.
Proposed release gate, run before switching traffic:
- The full set, at least three runs, with both kinds of customer, on the exact model and server settings that will serve traffic.
- Block on any breach, on any case that passed every run before and now fails one (v3's
question-then-upgradewould have been caught), and on a rise in refused calls on rules the cases list asshould_not_attempt. - More runs for a release than for development: three runs cannot tell a one-in-twenty failure from none.
- Add a case for every production incident before fixing it, so the fix is measured.
Privacy of transcripts
Built. Saved runs hold full transcripts, every call's arguments and the data changes. That is publishable here only because every person is invented, and scripts/privacy-check.mjs checks the repository for real email addresses and local paths.
Proposed. The identity answers appear twice in every record: in the customer's message and in the arguments of verify_identity in the action log. Redact them before storage. Set retention and access controls on transcripts, and check what the model provider keeps. A test set built from real conversations has to be scrubbed and its customers replaced before it can be shared.
Rate limits
Built. Three failed identity checks per conversation (ID-2). Twelve rounds of tool calls per agent turn. A cap of 1,500 output tokens per reply and a 180-second timeout in the adapter. The model-played customer is limited to the script length plus three messages, in evaluation only.
Proposed. Count failed identity checks per customer across conversations, with a lockout that expires. Limit conversations per client and messages per conversation. Cap executed money actions per customer per day. Rate-limit find_customer, which reveals whether an email has an account.
Cost and latency of hosted models
Built. Token use is recorded per conversation. Averages from the saved runs, for the agent alone:
| Version | Input tokens | Output tokens | Model calls |
|---|---|---|---|
| v1 | about 15,000 | about 800 | 5.6 |
| v3 | about 17,600 | about 810 | 5.5 |
A model-played customer added about 1,200 input and 900 output tokens per conversation. Input dominates: each model call resends the instructions and tool definitions (about 11,000 characters for v3) plus the conversation so far, about 3,400 input tokens per call on average for v3 on Qwen with scripted customers. Wall-clock time per conversation is not recorded.
Proposed.
- One full run of the set for one version on one model is 504 conversations; at v3's averages that is about 8.9 million input and 0.4 million output tokens on a hosted model. Price that, and get approval for it, before running. Measured here with prompt caching on, one configuration of 252 conversations cost about $0.25 on Claude Haiku 5.5, $3.60 on Sonnet 5.5 and $7.80 on Opus 5.5, and the eval command refuses to start a billed model without a spending limit.
- The instructions are a fixed prefix on every call, so prompt caching, where the provider offers it, should cut input cost. Measure it rather than assume it.
- Record latency per model call and per turn. Customers feel the sum of about five sequential model calls per conversation.
- v3 moved work from the model to code (the facts block in
src/agent/facts.ts). More of that, not a larger model, is the first lever to try.
What to re-measure
- Pass rate, consistency and refused calls per rule on the model that will serve traffic. The six models here differ far more in pass rate than in breaches, which stayed at zero on all of them.
- The cases that changed between versions, with more than three runs.
- Played customers driven by a second customer model, to see how much the results depend on Gemma's way of pushing.
- After any rule change:
npm test, which includes the tampering, boundary and saved-run tests. The audit restates the limits instead of importingLIMITS, so a limit change is made, and reviewed, in both places. - Ticket rate and unrequested changes on real traffic, which the test set cannot predict.