Diagnostic agents for pricing anomalies: code decides, the model writes

At work I built the single-case diagnostic tools behind a pricing-analysis chat bot. An analyst sends an order or comparison ID and gets back a report naming the stage of the pricing pipeline where the price went wrong, with the evidence. It has been in production since November 2026.

My part: the design, the diagnostic endpoints, three skills, the production fix-up and acceptance, and the evaluation. The agent platform, the tool gateway and the chat bot belong to colleagues. Stack: Java, MCP tools, prompt skills.

Anonymised. This is my employer's system, so the page names no company, product, system or business figure. Every number below is an engineering measurement: sample sizes, pass counts, latencies, limits.
18 / 18verdicts matched the raw data on a stratified sample of live cases
7 / 25sampled cases the tool could not answer yet, and said so
10 / 10production acceptance cases reached the right tool on the first call
0.1–5.3 sendpoint latency; a full answer still takes minutes

The problem

The pricing engine sets our price against a reference price through a long chain of stages: anchoring, commission, subsidy, coupons. Two outcomes cost money. We end up more expensive than the reference, or we undercut it by more than the allowed margin.

An upstream system already labels each such case with a coarse category. It cannot say which stage, rule or coupon caused it. Finding that by hand meant reading four internal pages per case; my estimate was 20 to 40 minutes each, and I never measured it.

The design rule

A skill that carries its reasoning in the prompt runs into the platform's 8,192-character prompt limit, and nobody can unit-test a prompt. So I worked to one rule: anything that can be written as an if/else goes into the endpoint.

The endpoint decides the verdict, computes the price gap after each stage, picks the stage where the gap first appears and the main cause, and returns the evidence it used. The model does three things only: it chooses the skill, reads the JSON, and writes a report in a fixed three-section format. It may not add a verdict of its own.

Model side Chat bot question + an ID Router scene picks one skill by description Skill short prompt, one allowed tool Report three fixed sections Code side Tool gateway (MCP) one tool, one HTTP endpoint Diagnostic endpoint verdict, stage gaps, cause JSON envelope tool call Comparison record Quote snapshot Rule config and change log Coupon config Read-only replay, only when needed
One diagnosis. The shaded box is where every decision is made; it is ordinary code with unit tests. The replay re-runs pricing without writing anything, and only when the reference price the engine anchored on is higher than the one in the comparison.

I built three such pairs of skill and tool: one for each of the two anomalies, and one that explains a single order's pricing stage by stage. The rule logic is about 1,200 lines of Java for one anomaly and 1,700 for the other.

The "router" is just the scene's model choosing one skill from the skill descriptions. A design for eight specialised sub-agents with a thin router exists as a document. It is not built, and this page does not claim it.

Tool contracts

There is no governance platform behind this. There are conventions that every tool I registered follows, and they did most of the work of keeping the model honest.

Evaluation that was actually run

CheckResultWhat it does not show
Baseline on 42 real cases of one anomaly, before and afterCorrect conclusion 81% → 100%; complete report 76% → 95%In-sample. 15 of the 42 lacked part of the raw data.
Routing, 10 phrasings of the same question3 went to the wrong skill; fixed by rewriting two overlapping skill descriptionsTen phrasings is not a routing benchmark.
Production acceptance on the real bot, 10 real cases10 of 10 called the dedicated tool first, with no fallback. A leading question did not produce a false verdict.My review the next day found 7 wording or calculation issues in report bodies. The first write-up had called the numbers consistent, and the routing result could not be re-checked from logs afterwards.
Regression after release, 7 casesAll passed. A made-up ID got an honest "no record".On a re-run, one report came out as a 90-character shell.
Stratified sample: 25 of 500 live cases, each checked against raw prices18 answerable. Verdict right in 18 of 18, main-cause stage right in 18 of 18. In the 3 cases where it disagreed with the upstream label, the tool was right.7 belonged to a comparison type the tool did not support. A "share of the gap" figure exceeded 100% in all 18.

There are 59 unit tests on the rule code. I believe the module's test runner does not execute them in CI, so I count them as local checks.

What broke, and what it changed

Latency

The endpoint answers in 0.1 to 1.4 seconds without a replay and 1.5 to 5.3 seconds with one. A full answer through the bot takes 2 to 9 minutes, and one degraded run took 18. Nearly all of that time is outside my endpoint, in the model's turns and the platform's handling of large results. I have not measured where exactly, so I am not claiming a breakdown.

Not built

How it was built

Most of the implementation, and some of the acceptance runs, were done through coding agents under my direction. The design, the acceptance criteria and the decisions are mine. One habit came out of it: an agent saying "fixed" is not evidence, so I check the production behaviour before I write that something works.