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.
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.
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.
- One envelope for every tool:
verdict,headline,causes[],evidence,dataSources[],message. "No record" is an explicit verdict, and a failed call is never reported as an empty result. - Completeness instead of confidence. Each data source reports fetched, partly fetched or missing, and the report must print that table. The model is never asked how sure it is.
- One tool per skill. Each skill whitelists exactly one tool, and the scene forbids calling anything not listed.
- Vocabulary rules. Reports use the business's official terms only. Hedge words are banned, and so are raw field names and reason codes.
- A field dictionary across systems, because the same price has a different name in each system it passes through.
- A light response mode. It cut the median payload from 46 KB to 14 KB, which matters because the platform moves large tool results out of the model's context.
Evaluation that was actually run
| Check | Result | What it does not show |
|---|---|---|
| Baseline on 42 real cases of one anomaly, before and after | Correct 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 question | 3 went to the wrong skill; fixed by rewriting two overlapping skill descriptions | Ten phrasings is not a routing benchmark. |
| Production acceptance on the real bot, 10 real cases | 10 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 cases | All 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 prices | 18 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
- A silent fallback. In production the scene had never been bound to my skills, and the production tool service did not have the tools. The bot quietly used a generic tool and still wrote plausible reports. Since then, acceptance happens only on the production entry, with real cases, and checks which tool was called.
- A prompt over the limit. One skill exceeded the character limit and failed to sync for four days with no error anywhere. The deploy path had no length check, and still has none.
- A sign error. The formula in the prompt had the opposite sign to the API field, so a report could show a formula and a value that disagreed.
- The model adding verdicts. Report bodies sometimes stated conclusions the endpoint had not made. This is why the conclusion paragraph must now match the endpoint's headline.
- An argument mix-up. The model passed a summary where the report belonged and the 13,565-character report where a file path belonged. The result was the 90-character shell above.
- Offsetting stages. When one stage widens the gap and another narrows it, "share of the gap" stops meaning anything. That is the over-100% figure in the table.
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
- A golden set with a regression run in CI. The design says 30 cases per skill plus 10 a month, with accuracy targets. None of it exists yet.
- A prompt-length check before deploy, and a daily smoke test of the tools.
- Support for the comparison type behind the 7 unanswerable cases. The change passes 25 of 25 locally and is not released.
- Anything beyond two anomalies. Problems that show up only at one stage still need a person.
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.