Architecture

This note explains how the parts fit together and why they are built the way they are. See also: design decisions, threat model, production notes, extending.

The problem

A support agent that only answers questions can be wrong and still do no damage. An agent that issues refunds and cancels subscriptions cannot. Two things have to be true before such an agent can be put in front of customers:

  1. It cannot break company policy, whatever the model decides and whatever the customer says to it.
  2. There is a number for how often it does the right thing, and that number can be checked by someone who does not trust the author.

Backstop is a small, complete example of both, for an invented subscription software company.

One path to the data

customer message
      |
      v
  agent loop  ---- model (any adapter) decides what to call
      |
      v
  execute(session, action, args)            src/actions/execute.ts
      1. arguments checked against a strict schema
      2. policy rules checked in code       src/policy/rules.ts
      3. the change is made
      (every attempt is recorded, whatever its outcome)
      |
      v
  mock company database (SQLite, in memory, new for every conversation)

execute is the only function that writes to the database on the agent's behalf. A model has no other way in. Three consequences follow.

Identity is part of the same layer. verify_identity compares the customer's answers with the customer record, and the session remembers who passed. Every account action is checked against that: no account data is readable before a check passes (ID-1), and only the verified customer's own records are reachable after (ID-3). The refusal for someone else's record is worded the same as for a record that does not exist, so the agent cannot be used to find out which invoice or subscription ids are real. The identity answers themselves are never returned by any action. One thing is visible before the check: find_customer says whether an email address has an account, as most sign-in forms do.

Rules as data and as prose

Each rule is an object with an id, a title, the actions it guards, a flag saying whether a human may approve an exception, and a check function. The same ids and titles are headings in policies/policies.md, which is what the agent reads and what a person reviewing the policy would read. A unit test fails if the two lists differ, so the document cannot drift away from the code without someone noticing.

The limits (30 days, $200.00, $25.00, and so on) live in one constant, and the rule titles that state an amount or a number of days are built from it.

Scoring

A test case is a YAML file: starting data, what the customer says, and every change the final data must show. Scoring compares the database before and after the conversation.

Two kinds of customer

A scripted customer sends the case's fixed messages in order. It is cheap and exactly repeatable, but it does not react: an agent is never argued with about the answer it actually gave.

A model-played customer opens with the same first message and is then played by a model that is given the customer's goal, persona and remaining points, and told to react to the agent's replies and, in attack cases, to keep pushing. It sees the chat only: not the agent's tool calls, not the data. Scoring is unchanged, because it never looked at the words in the first place.

The audit

The policy layer is the thing being relied on, so it is checked by something that does not share its code. src/eval/audit.ts reads the written policies off the finished data: every new refund, credit and subscription change is checked against every rule that applies to it, with the limits written out a second time. It also works out, from the customer table and the call log, who really passed the identity check and whether any account was read without it.

Three kinds of test stand behind it:

The audit looks at the final data, so a change that was made and then undone inside one conversation is invisible to it. None of the actions undo anything, apart from a plan being changed and changed back.

Models

The agent loop talks to a model through one small interface (src/agent/types.ts): a system text, messages, tool definitions in, text and tool calls out.

Agent versions

An agent version is its instructions plus, optionally, a function that changes what the agent is shown for a tool result (src/agent/prompt.ts). Every version is kept, so any two can be scored against each other on the same cases.

The facts block is a view. It is built only from what get_account already returned, it states no verdict, the policy layer never reads it, and the action log records the plain result. A wrong number in it could mislead the agent into a refused call, but could not cause a breach.

Saved runs

Each scored conversation is saved whole: the transcript, every call with its outcome, and the difference between the data before and after. Two commands work from those records without calling a model.

Time

Every conversation has a fixed "now", set by the test case. Nothing reads the system clock. That is what makes date limits testable to the day (a refund on day 30 against the same refund on day 31) and what makes replaying an action log exact.

What is deliberately left out

Next: Design decisions