Work · Case file 01 · Open-source tool (PyPI package, MIT) · 2026
TraceRazor
4 min readJump to proofJump to limits
At a glance
- Result
- On 12 live runs that all still passed, my first fix raised token use by 5.6 percent on average. I published that, rewrote the fix, and the second round measured 0.7 percent fewer tokens.
- Problem
- Observability does not say which agent work was avoidable, what to change, or whether the changed agent still finishes the task.
- My role
- Solo project: the Rust audit core, Python package and launcher, agent-host integrations, live case-study harness, and release and verification tooling.The README carries my copyright (2025 to 2026) and lists no other authors.
- Stack
- Rust · Python · MCP over stdio · GitHub Actions
Proof
The problem
Observability tells you what an agent run cost and what happened. It does not say which of that work was avoidable, what to change, or whether the changed agent still finishes the task. Coding agents also vary a lot run to run (per-pair token deltas in my study spanned minus 30 to plus 24 percent), so a single before and after pair proves nothing and a projected saving is easy to mistake for a real one.
The idea. Decompose a trace into named waste signals, propose risk-tagged fixes, and then refuse to call anything a saving until the same task is rerun with the same model and still passes.
Fig. 01 · Diagnosis, projection, measurement
A made-up trace, 10 steps
- 01Read task and plan620
- 02read_file("api/routes.py")1,480
- 03search("rate limit")540
- 04read_file("api/routes.py")1,480
- 05run_tests() failed2,100
- 06run_tests() failed2,100
- 07run_tests() failed2,100
- 08Reason about the failure1,900
- 09Patch and run_tests() passed1,300
- 10Summarise the change420
Eight weighted signals
- SRRStep Redundancy Ratenear-duplicate steps0.80
- LDILoop Detection Indexrepeated action cycles0.90
- TCATool Call Accuracyfailed calls and same-tool retries0.90
- RDAReasoning Depthdepth beyond the task’s observed complexity0.50
- ISRInformation Sufficiencysteps that add little novel information0.90
- CCEContext Efficiencyduplicated context across steps0.75
- OBSObservation Token Sharetoken share consumed by tool observations0.75
- CCRCompression Ratiohighly compressible text0.45
- Illustrative score
- 55 / 100 · Poor
- Tokens in trace
- 14,040
- Receipt
Six more signals stay diagnostic by default: TUR Token Utilisation, DBO Decision Optimality, GAR Goal Advancement, CSD Semantic Drift, VDI Verbosity Density, SHL Sycophancy and Hedging.
Step through the sample audit
The bundled support-agent trace and the audit tracerazor 1.1.0 wrote for it, read in your browser: each step with its tokens, the steps the audit flags and why, and the signals behind the score. Nothing is re-scored here.
TAS 83.1 of 100, grade Good, above the 70.0 gate. 11 steps, 14,280 tokens; the audit flags 6 steps.
| Step | Type | Tokens | Audit flag |
|---|---|---|---|
| 1 | reasoning | 820 | none |
| 2 | tool_callget_order_details | 340 | Trim: Compress context: 100% duplicated input context |
| 3 | reasoning | 1,450 | none |
| 4 | tool_callcheck_refund_eligibility | 580 | Delete: Misfired: wrong params for check_refund_eligibility, retried at step 5 |
| 5 | tool_callcheck_refund_eligibility | 620 | Trim: Compress context: correction of step 4 |
| 6 | reasoning | 2,100 | Trim: Compress context: 67% duplicated input context |
| 7 | tool_callprocess_refund | 380 | none |
| 8 | reasoning | 2,840 | Trim: Compress context: 60% duplicated input context |
| 9 | tool_callget_order_details | 920 | none |
| 10 | reasoning | 1,680 | Trim: Compress context: 52% duplicated input context |
| 11 | tool_callsend_confirmation | 2,550 | none |
Loads the trace and the audit JSON from this site.
30 seconds to try it
The same audit on your machine. I ran these commands on 11 Nov 2026 in a fresh virtual environment (Python 3.13, Linux) with the trace above saved beside it; pip installed tracerazor 1.1.0 from PyPI, and the output matched the stored sample-report.txt line for line.
$ python3 -m venv .venv && . .venv/bin/activate
$ pip install -q tracerazor
$ tracerazor --version
tracerazor 1.1.0
$ tracerazor audit support-agent-run-2847.json --hermetic
TRACERAZOR REPORT
------------------------------------------------------
Trace: support-agent-run-2847
Agent: customer-support-v3
Framework: langgraph
Steps: 11 Tokens: 14280
Analysed: 1ms
------------------------------------------------------
TRACERAZOR SCORE: 83 / 100 [GOOD] (raw structural: 86, task value: 0.90)
VAE SCORE: 0.77
MVTG: 33.8% (trace is 33.8% above minimum viable token count)The first lines of the output. The full transcript, with the metric breakdown, per-step flags, fixes and the projected saving: pip-install-transcript.txt; the trace: support-agent-run-2847.json.
See it run
A static copy of the TraceRazor dashboard holding one stored audit of the bundled support-agent trace, produced with tracerazor 1.1.0 from PyPI on 13 October 2026, including one misfired tool call retried with the missing order_id. Audit, Compare, KB and Live need a local install.
Open the sample dashboard How it works
Capture or import a run
tracerazor import --from auto recognises native JSON, LangSmith, Langfuse, Phoenix, OpenTelemetry and Claude Code exports. Agent hooks for Codex, Claude Code and Gemini CLI capture runs into a local-redacted envelope. Provider token counts keep their provenance; missing usage is marked degraded, never replaced with a character-count estimate.
Audit hermetically
The Rust core checks ingest coverage, scores the trace with eight weighted signals plus six detection-only diagnostics, and reports an ordinal Token Alignment Score (TAS). With --hermetic the score is a function of the trace, the configuration and the version, so another reviewer can reproduce it. Every JSON report carries a manifest with the trace hash, tool version, weights, thresholds and ingest quality.
Name the findings and preview fixes
Findings are named patterns: redundancy, loops, failed tool retries, duplicated context, verbosity. Fixes are tagged safe, needs_review or dangerous. tracerazor apply defaults to the safe subset, supports --dry-run and never silently applies a dangerous fix. A clean trace can legitimately produce no fixes.
Rerun the same task and bench
tracerazor bench takes before and after traces from the same task and model and reports measured token and TAS deltas against the audit's estimates. tracerazor compare exits 1 only when a configured regression gate fails.
Sign, bundle and verify
tracerazor export writes a portable bundle with hashes and the exact scoring configuration, and tracerazor verify re-scores it. With TRACERAZOR_SIGNING_KEY set the bundle carries an Ed25519 signature; without one it verifies at rescore-only (unsigned) and is not an authenticated author claim.
Plug into the workflow
The same report is served over the CLI, a stdio MCP server, a loopback-first REST and WebSocket server with an embedded dashboard, and a GitHub Action that posts a sticky pull-request comment and exits 2 on broken input instead of inventing a score.
What was hard
The hardest problem was that my own fix lost. The goal_anchor patch told the agent to restate the task objective before every reasoning step; on 12 runs that were already on track it had nothing to recover and charged a restating ritual on every turn, so the audit's predicted saving measured as a cost. I published that round as a negative result, rewrote the anchor so it cannot add a standing cost, and wrote the honesty contract into the README: TAS is ordinal, savings are estimates until rerun, task success comes first, short traces skip, labs carry no efficacy claims. The trade-off: no saving is shown without a rerun, which is slower to impress and harder to misuse.
Limits. The case study is 6 tasks times 2 replicates on one model, one harness and one domain, and only the goal_anchor fix fired, so it does not license claims across models or fix types. The metric-effectiveness table is a 0.5.0 decision record that does not reproduce on the 1.1.0 scorer (SRR reruns at sd 0.047, under the C1 floor), and passing release automation does not establish that TAS is scientifically validated.
Evidence
- Commits
- 185TraceRazor repository
- Tests and CI
- 111 test files (101 Python, 10 Rust). CI on every push: cargo fmt, cargo test, clippy with warnings denied, cargo deny licence check and pytest.TraceRazor Actions; TraceRazor README, section Develop and verify
- Releases
- 7 releases on PyPI, latest on PyPI 1.1.0. Repository tagged v1.2.0 on 2026-09-23 with five platform wheels, standalone archives, checksums and SBOMs. MIT licence.https://pypi.org/project/tracerazor/; TraceRazor CHANGELOG.md; TraceRazor README, section Evidence before adjectives
- Measured case study, round 1
- The goal_anchor fix used 5.6 percent more tokens on average (95 percent CI minus 11.4 to plus 0.2 percent); mean TAS delta minus 1.5 (CI minus 2.7 to minus 0.4); pass rate 12 of 12 before and after; estimate accuracy minus 102 percent.TraceRazor docs/case_study.md
- Measured case study, round 2
- After the rewrite: 0.7 percent fewer tokens on average (95 percent CI minus 8.9 to plus 9.9 percent, centred on zero), mean TAS delta 0.0, pass rate 12 of 12.TraceRazor docs/case_study.md
- Study scale
- 6 Python engineering tasks times 2 replicates = 12 pairs, model claude-haiku-4-5 under headless Claude Code, seeded 10,000-resample bootstrap CIs, about 1.30 US dollars of API spend for the full study.TraceRazor docs/case_study.md
- Signal selection
- Hermetic audits of 61 real traces (tau-bench, SWE-agent, AgentInstruct ReAct, live Claude Code corpus) kept 8 signals in the composite and demoted 6 to diagnostics on criteria stated before the data was read.TraceRazor docs/metric_effectiveness.md
- Sample audit
- Bundled support-agent trace under 1.2.0: 11 steps, 14,280 tokens, TAS 83.1, projected 4,827 tokens per run (33.8 percent), labelled a projection, not a measured saving.TraceRazor README, section What the sample reports
Stack
- Rust
- Python
- PyPI wheels for Windows, macOS and Linux
- Ed25519 signing and hash manifests
- MCP over stdio
- REST and WebSocket server with embedded dashboard
- OTLP/HTTP receiver
- LangGraph, CrewAI and OpenAI Agents SDK handles
- GitHub Actions