Project at a glance
| Role | Design and engineering, solo |
| Scope | Five processes with separate credentials; 2,600 public claim records and 494 policy clauses; 13 checks before every approval; 268 test files |
| Stack | TypeScript, Next.js, React, PostgreSQL, Docker, Model Context Protocol, Playwright |
| Status | A working demonstration. No real model has run yet: the demo replays a scripted stand-in, and the screens say so. The legacy system is fictional, and every person and claim in it is invented. |
Why I built it
A lot of money still moves through old systems of record that cannot be rebuilt around an AI agent, and a model cannot be trusted with a payment. I wanted to show what it takes to put an agent to work inside such a system anyway: it reads and drafts, code does the arithmetic, and a person approves every change.
What it does
Works a queue of claim disputes
The agent takes disputed flood-insurance claims from FCS/2, a deliberately dated claims system I wrote to stand in for the real thing, green screens and batch files included. For each dispute it either drafts a decision or escalates it, and says why.
The desk's queue after the scripted stand-in has worked twelve invented disputes: nine drafts awaiting approval and three escalations, oldest first.
Drafts a letter where every statement is cited
Each sentence in the draft carries numbered citations that open beside it: a record in the legacy system, a clause of FEMA's public flood policy, or a line of the calculation. Every dollar figure is filled in by code. The model never writes an amount.
A drafted decision letter with one citation open beside its sentence, next to the thirteen checks that must pass before it can be approved. The draft is the scripted stand-in's.
Leaves the decision to a person
Approving lists exactly what will be written to the legacy system, in order, and works the amounts out again from its records before anything is queued. A larger payment asks the adjuster to confirm what they checked.
The approval dialog: the payment, the five changes that would be written to the legacy system in order, and the boxes an adjuster ticks before approving.
How it is built
The rest of this page is for the engineer who wants the detail.
Architecture
Five processes run side by side, each with its own credentials. FCS/2 is the legacy system: green screens and a batch job on a timer. The tool gateway is a Model Context Protocol server with the claim reader and the calculators inside it. The worker runs the agent loop, one claim at a time, and is the only process allowed the model key. The desk is the web app an adjuster uses. The poster turns approved changes into batch files. Only PostgreSQL runs in Docker, pinned by digest and published to the local machine alone, holding two databases: the legacy system's and the desk's.
Architecture: the model and the worker sit inside an untrusted boundary and reach the claim records only through the tool gateway, which can read and draft. An adjuster approves on the desk, the poster queues batch files, and the legacy batch job is the only thing that writes to the legacy database.
One dispute, end to end:
- The desk syncs open requests from FCS/2, and a person queues a run.
- The worker claims it and is issued a capability for that one claim: a random token of which only the hash is stored.
- A pre-screen in code runs before any model call. A litigation flag, an investigation flag or legal language sends the dispute straight to a person.
- The agent works through eight tools: four reads, a policy-clause lookup, a calculator, propose and escalate. None can write to FCS/2.
- The calculator settles the claim in code and stores the result. The propose tool checks the letter and files one pending proposal.
- On approval the desk takes a lock on the claim, re-reads FCS/2 in a single read-only snapshot, works the amounts and the plan of changes out again, and runs 13 checks. Only then does it record the approval, the queued writes and the letter.
- The poster writes the batch file under a temporary name and renames it into the inbound folder. The batch job applies the file whole or not at all, archives it and writes an acknowledgement.
- A write is marked posted only when the payment is on FCS/2's own rows exactly once.
Limits live in the database
The boundary is database logins, not application code.
| Login | What it may do |
|---|---|
| Reader | Select from the legacy database, in sessions that default to read-only |
| Drafting | Add runs, calculations, proposals and escalations; cannot set a proposal's status |
| Approver | The only login that may add approvals, queued writes and letters |
| Poster | May change only the status columns of a queued write |
A queued write cannot exist without an approved decision behind it, and the schema is what refuses it:
decision TEXT NOT NULL DEFAULT 'approved' CHECK (decision = 'approved'),
FOREIGN KEY (proposal_id, decision) REFERENCES approvals (proposal_id, decision)
Each process is started with only the variables on its own allow-list, and takes each secret from its own file.
Money, citations and hostile text
Amounts are whole cents, parsed and rounded by code that refuses an inexact value. A letter never contains a figure; it contains references that code fills in, and a draft with a raw amount in it is refused. Free text from a claim record reaches the model inside an envelope marked as untrusted, and a draft that copies a long run of words from a note is refused.
One gateway, one log
Every tool call passes one gateway, which checks the caller, the run, the rate, the budget, the tool, the policy, the arguments and the claim's scope, in that order, and writes two audit rows per call. The audit log refuses updates and deletes by trigger, and each row carries a hash of the row before it. A separate command recomputes the chain from outside the database.
The legacy interface
FCS/2 takes changes the way such systems do: 120-byte fixed-width records in a file dropped into an inbound folder, answered by an 80-byte acknowledgement file. The batch job runs every 30 seconds, or every 3 in the demo. The desk's code adapts to that; FCS/2 is never changed to suit the agent.
Decisions that mattered
- Stored results cannot be trusted. The drafting login writes the calculation and the plan, so approval never reads them back. It recomputes from FCS/2.
- An acknowledgement is not proof. Acknowledgements can be late, lost or wrong, so a payment counts as posted only when it is on the legacy system's own rows.
- Checking amounts after the fact fails open. Finding every figure in free text cannot be done reliably, so every raw amount is refused and code fills the placeholders.
- A state machine in application code could be stepped around. The allowed moves of a dispute now live in the database, enforced by a trigger.
- Identity claimed by a client can be forged. A tool call is tied to its run by the capability issued to the worker, not by anything the caller says about itself.
Testing and evals
| Layer | Test files | What it covers |
|---|---|---|
| Unit | 182 | Calculators, letter checks, the gateway's rules, batch layouts |
| Integration | 68 | The full flow against real databases, grants, the audit chain |
| Browser | 18 | The desk and the green screens, end to end |
The project keeps 37 written promises, each tied to the tests that prove it. Four eval suites hold 244 scripted cases. A fault gallery runs the stand-in with one mistake planted in it at a time: of 44 mistakes, a guard stopped 36, a grader caught 6 more, and 2 got through (a mislabelled amount and an irrelevant clause cited). Both are recorded as open.
Limits and what is next
No model has run yet, so every eval figure is a script's and says nothing about how well a model would do. The desk has no sign-in; one adjuster is named by a setting. The policy rules are simplified, and the hard cases escalate instead of being decided. The next step is the first real model run, in a recorded mode so its answers can be replayed.
What the project demonstrates
Legacy Claims Desk shows how I would put an agent near money: read-only by construction, arithmetic in code, a person on every write, and an honest account of what has and has not been tested.
