A restaurant closes October with a profit of £12,556. A figure which is in the range of the previous few months so nothing immediately looks wrong.
The correct profit is £8,632. Underneath that number, last month’s stocktake journal was never reversed, which understated COGS by £11,520. Separately, a new £7,450 oven was expensed rather than capitalised as a fixed asset. These 2 errors push profit in opposite directions and mostly cancel out. Add a handful of less material mistakes and you get a bottom line that’s out by about £3,900 whilst the books are wrong by more than £20,000.
October profit, reported to correct
- Reported profit£12,556
- Stocktake not reversedOverstated profit by £11,520−£11,520
- Oven expensedUnderstated profit by £7,450+£7,450
- Smaller errors (net)Understated profit by £146+£146
- Correct profit£8,632
When an accountant performs a month-end or quarter-end close, they review the P&L looking for errors exactly like these.
This is the problem that Agentic Review solves. A set of agents review the P&L, flag the issues and propose actions to resolve them. The accountant just needs to approve them.
It took us 3 attempts to build something that works. This post covers what we tried, why the first 2 attempts failed, and the learnings that made the 3rd attempt work.
01
What an accountant actually does
When an accountant reviews a P&L, they don’t read every transaction. They perform what’s called a flux analysis:
- Set a materiality threshold, either a percentage or absolute amount or both
- For each account, compare the number vs prior periods
- Where the gap is bigger than the materiality threshold, dig into why until you can explain it, fixing errors along the way
The output is explanations of each deviation.
Flux analysisRestaurant, October
| Account | September | October | Expected | Gap | Review |
|---|---|---|---|---|---|
| Sales | £58,400 | £60,200 | £59,000± £3,000 | +£1,200 | In tolerance |
| Cost of sales | £18,900 | £7,780 | £19,000± £1,500 | −£11,220 | Dig in |
| Wages | £21,300 | £21,650 | £21,500± £1,000 | +£150 | In tolerance |
| Repairs | £420 | £8,010 | £500± £300 | +£7,510 | Dig in |
02
Act 1: an agent per account
Our first attempt gave each P&L account to its own agent to be reviewed. Each agent had tools to fetch the account’s transactions, look up documents and check counterparties.
Looking back, there were 2 key problems with this approach:
- Slow turns: tools paged through the database, returning 100s of rows of data directly into the agent’s context. This caused each turn to take upwards of 50 seconds.
- No way to look sideways: A cost that belongs in one account but was coded to another is invisible to an agent that only looks at its own account. In reality, P&L is all interconnected so siloing each account caused more problems than it solved.
- AgentSales
- Card takings£2,140
- Cash takings£380
- AgentCost of sales
- Produce£920
- Drinks£410
- AgentGeneral expenses
- Cleaning£84
- Train fare£126
- AgentTravel
- Taxi£18
- Train fare £126, coded elsewhere(not visible to the Travel agent)
03
Act 2: a detector per issue type
Our second attempt flipped the script. Instead of an agent per account, we built workflows, each focused on catching one specific type of issue: miscoded transactions, duplicate transactions, missing transactions and so on.
We initially saw some promising results with this approach, the focused detectors were better at catching issues than the first attempt, but this approach still had a big flaw: it only knew how to find issues that we’d defined in advance.
In reality, the errors that come up in real books often don’t fit a specific category and it wasn’t scalable to keep creating specific detectors for an exhaustive list of possible issues.
- Travel coded to general expensesMiscodingCaught
- Stocktake journal not reversedNo detectorMissed
- Bill posted twiceDuplicatesCaught
- Oven expensed, not capitalisedNo detectorMissed
- Supplier bill never postedMissing transactionsCaught
In addition, this approach was inefficient. Each detector crawled the same transactions with no way of sharing information.
The lesson from this attempt was the inverse of what we’d been working on. Don’t enumerate the problems, enumerate the fixes. There are thousands of ways that the books can go wrong, but only a handful of things one can do to put them right. We’ll come back to this below.
04
Act 3: coordinated agents
Our third attempt combined our learnings from the first 2 attempts. We ended up with a workflow relatively similar to how a human accountant might review the P&L.
AgentsDataWorkflows and people
- 1Freeze the booksThe review starts by taking a read-only snapshot of the client’s books. This snapshot includes the current period data plus up to 24 months of historical data.
- 2Set expectationsBefore anything looks at the period itself, one agent forecasts each P&L account using historical data. For each account it returns an expected amount, a tolerance and a short rationale.
- 3The orchestratorOnce the expectations have been set, the orchestrator takes over. Its job is to look at the P&L as a whole, compare the actual balances of each account against their expectations and task subagents to look into deviations.
- 4The investigatorThe investigator’s job is to look into hypotheses assigned to it by the orchestrator and produce a report on its findings. It does this by working in SQL and Python over the snapshot in its own sandboxed kernel.
- 5Signals to itemsAn agent that finds something wrong raises a signal: a short description of the gap along with the evidence. Another agent, called the drafter, picks up the signal and turns it into an issue, a question or a document request.
- 6The writerOnce the orchestrator’s investigations are finished, it spawns writer subagents to explain the period’s movements for each account. An error is what’s left when the explanation doesn’t add up.
- 7The review stays liveThe accountant works through the review, approving issues, answering questions and uploading missing documents. When the ledger changes, we compare fingerprints, and a smaller delta review re-examines the diff.
1. Freeze the books
The review starts by taking a read-only snapshot of the client’s books. This snapshot includes the current period data plus up to 24 months of historical data. That covers journals, invoices, bills, bank transactions, schedules and more.
We chose to use a copy over allowing the agent to query live data for 2 reasons:
- The data is ever-changing
- Using a snapshot allows us to record exactly what data an agent had access to which is useful for debugging
2. Set expectations
Before anything looks at the period itself, one agent forecasts each P&L account using historical data. For each account it returns an expected amount, a tolerance and a short rationale (think of it as a justification for its expectation).
This agent ran in its own special sandbox so that we could block access to current period data to ensure that the agent didn’t “cheat”.
3. The orchestrator
Once the expectations have been set, the orchestrator takes over. Unlike the expectation setter, the orchestrator is given the full context, including the current period’s data. Think of the orchestrator as the manager. Its job is to look at the P&L as a whole, compare the actual balances of each account against their expectations and task subagents to look into deviations.
Deviations do not need to be account-specific, and this is where one of the key learnings from the other attempts comes in. For example, if Sales is up 20% but Cost of Sales is flat, this would be cause to investigate further.
To do this, the orchestrator creates a hypothesis (ie “Sales up 20% but COGS flat”) and spawns an investigator subagent to look into it.
4. The investigator
The investigator’s job is to look into hypotheses assigned to it by the orchestrator and produce a report on its findings.
It does this by working in SQL and Python over the snapshot in its own sandboxed kernel. This fixes attempt 1’s issue where a tool call to fetch 100s of transactions was dumped into its context. Now instead, the agent can query the snapshot with SQL and the results are saved into a pandas dataframe with only a short preview added to its context instead of the entire output.
The goal is to explain the hypothesis. Sometimes large deviations are legitimate, for example perhaps the increase in Sales vs the flat COGS can be explained due to the client raising their prices.
However in other cases, there might be real issues. In this case, the investigator is instructed to raise a signal.
5. Signals to items
An agent that finds something wrong raises a signal: a short description of the gap along with the evidence. Another agent, called the drafter, picks up the signal and turns it into one of 3 things:
- An issue with a concrete fix → transaction is coded to general expenses but should be coded to travel. Fix: recode transaction to travel
- A question → when the evidence is ambiguous or missing
- A document request → when a bank transaction has no invoice matched
The drafter can also decide to decline the signal if there is nothing to raise.
- IssueTransaction is coded to general expenses but should be coded to travelFix: Recode transaction to travel
- QuestionWhen the evidence is ambiguous or missing
- Document requestWhen a bank transaction has no invoice matched
6. The writer
Once accounts are understood, the orchestrator spawns writer subagents to explain the period’s movements for each account.
This is the core of the method. An error is what’s left when the explanation doesn’t add up. We don’t ask the agent to find errors; we ask it to account for every pound, and errors show up as the pounds it can’t account for.
Cost of sales, September to October
- September£18,900
- Higher sales volumeDriver+£580
- Supplier price changesDriver−£180
- UnexplainedResidual: the stocktake journal−£11,520
- October£7,780
7. The review stays live
Once the review is ready, the accountant can start working through it, approving issues, answering questions and uploading missing documents. As this happens, the books start changing.
Every account has a fingerprint: a balance, line count and hash of its lines. When the ledger changes, we compare fingerprints, and a smaller delta review re-examines the diff. It can withdraw items that no longer apply and update account explanations as they go stale.
05
Agents propose, code executes
Act 3 describes how the review finds the right things. This section is about why an accountant can trust it.
Never flag what we can’t fix
Our 2nd attempt taught us to enumerate fixes rather than problems. In accounting, most problems can be solved with the same set of primitives: correcting a posted document, voiding a duplicate, reconciling a bank line, creating a prepayment schedule and so on. We have a range of these primitives, each with its own validation, which we give to the agent as building blocks to resolve an issue.
Before an issue is raised, the resolution gets a dry-run. This is executed against the live books inside a transaction that always rolls back. The dry run reports exactly what would change including which accounts would be affected.
Agents never touch the ledger
No agent can change the books: they analyse a read-only copy in a sandbox with no network access.
The ledger only changes when a user approves an item. The fix then runs through the resolution engine, this time without the dry run. If the books changed since the fix was drafted and it no longer applies, the approval would fail and report the error back to the user.
This follows a principle we use across Briefcase’s data model: Agents produce “inferred data”, which is append-only and comes with a justification. Only deterministic code, acting on a user’s decision, turns this “inferred data” into “facts” in the ledger.
AgentsInferred data
- Agent proposes a fixBuilt from validated primitives
- Dry runAgainst the live books, always rolled back
Deterministic codeFacts
- User approvesThe ledger only changes now
- Resolution engineRuns the fix, this time without the dry run
- LedgerThe books change
06
The sandbox
1Downloaded through short-lived URLs
Virtual machineOne per review
ParquetParquetParquetParquet2Network switched off before any kernel starts
3One kernel per agent
- OrchestratorPython kernelDuckDB in memory
- InvestigatorPython kernelDuckDB in memory
- WriterPython kernelDuckDB in memory
Each review gets its own sandbox: a virtual machine holding the snapshot data as Parquet files, with a separate Python kernel with in-memory DuckDB for each agent.
On instantiation, the sandbox downloads the snapshot data through short-lived URLs and then switches network off before any kernel is started.
We chose one sandbox per review, not one per agent, because agents are idle about 95% of the time waiting on the model. A sandbox per agent would have cost roughly 20 times more for no real gain in isolation, since every agent in a review reads the same client’s data anyway.
We log every SQL and Python action so if an agent loses its sandbox (host fails, a VM times out etc), we can recover it. This only works because the snapshots are frozen and the kernels have no network.
07
The agent loop
Temporal workflowHistory holds references only
- ActivityModel callReference to turn 1
- ActivityTool call
sql - ActivityModel callReference to turn 2
- ActivityTool call
submitCheck failed, returned as a tool error - ActivityModel callReference to turn 3
- ActivityTool call
submitChecks pass, the agent ends
Object storageThe full transcript
- Turn 1
- Turn 2
- Turn 3
We looked at the agent frameworks available at the time and decided to write our own on top of Temporal (which we already use extensively) instead. The available frameworks either ran somewhere Temporal couldn’t see (so crashes could lose the session) or were tied to one model provider.
The loop is simple:
- One Temporal activity per model call and per tool call. If a worker dies mid-review, Temporal replays the workflow so that completed model calls are not repeated.
- References in history, transcripts in object storage. Resending the whole transcript through Temporal on every turn grows history roughly quadratically. The model-call activity loads the transcript, saves the new turn and returns only a small reference.
- Agents end on a successful
submittool call. Schema checks and the arithmetic checks run when an agent submits, and a failure comes back as a tool error. This makes it easy for the agent to handle and correct errors.
08
What we learned
- Give the agent the whole dataset and a real query engine.Tools that page through a database turn analysis into reading through a keyhole.
- Ask it to explain, not to hunt. “Account for every pound” gives the agent a clear definition of done. Errors become what’s left over.
- Enumerate the fixes, not the problems. Thousands of things can go wrong in a set of books; only a handful of actions put them right.
- Code computes the facts, agents make the judgement calls.Keep the arithmetic out of the model and the decisions out of the code.
- Keep a person between the agent and anything permanent.It makes the findings useful and the system safe at the same time.


