agent-blackbox-cli 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_blackbox_cli-0.3.0/LICENSE +21 -0
- agent_blackbox_cli-0.3.0/PKG-INFO +623 -0
- agent_blackbox_cli-0.3.0/README.md +593 -0
- agent_blackbox_cli-0.3.0/agent_blackbox_cli.egg-info/PKG-INFO +623 -0
- agent_blackbox_cli-0.3.0/agent_blackbox_cli.egg-info/SOURCES.txt +56 -0
- agent_blackbox_cli-0.3.0/agent_blackbox_cli.egg-info/dependency_links.txt +1 -0
- agent_blackbox_cli-0.3.0/agent_blackbox_cli.egg-info/entry_points.txt +2 -0
- agent_blackbox_cli-0.3.0/agent_blackbox_cli.egg-info/requires.txt +4 -0
- agent_blackbox_cli-0.3.0/agent_blackbox_cli.egg-info/top_level.txt +1 -0
- agent_blackbox_cli-0.3.0/blackbox/__init__.py +61 -0
- agent_blackbox_cli-0.3.0/blackbox/__main__.py +6 -0
- agent_blackbox_cli-0.3.0/blackbox/adapters/__init__.py +0 -0
- agent_blackbox_cli-0.3.0/blackbox/adapters/_linking.py +31 -0
- agent_blackbox_cli-0.3.0/blackbox/adapters/base.py +38 -0
- agent_blackbox_cli-0.3.0/blackbox/adapters/claude_code.py +341 -0
- agent_blackbox_cli-0.3.0/blackbox/adapters/codex.py +318 -0
- agent_blackbox_cli-0.3.0/blackbox/adapters/labelled_turns.py +371 -0
- agent_blackbox_cli-0.3.0/blackbox/adapters/registry.py +30 -0
- agent_blackbox_cli-0.3.0/blackbox/aggregate.py +119 -0
- agent_blackbox_cli-0.3.0/blackbox/analysis.py +325 -0
- agent_blackbox_cli-0.3.0/blackbox/bench.py +466 -0
- agent_blackbox_cli-0.3.0/blackbox/cli.py +405 -0
- agent_blackbox_cli-0.3.0/blackbox/cost.py +138 -0
- agent_blackbox_cli-0.3.0/blackbox/describe.py +116 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/__init__.py +32 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/base.py +83 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/context_bloat.py +137 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/contradictions.py +180 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/error_clusters.py +114 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/retry_loops.py +98 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/stalls.py +117 -0
- agent_blackbox_cli-0.3.0/blackbox/detectors/thrash.py +86 -0
- agent_blackbox_cli-0.3.0/blackbox/diff.py +123 -0
- agent_blackbox_cli-0.3.0/blackbox/discover.py +189 -0
- agent_blackbox_cli-0.3.0/blackbox/events.py +163 -0
- agent_blackbox_cli-0.3.0/blackbox/graph.py +150 -0
- agent_blackbox_cli-0.3.0/blackbox/guard.py +528 -0
- agent_blackbox_cli-0.3.0/blackbox/guard_cli.py +349 -0
- agent_blackbox_cli-0.3.0/blackbox/pricing.py +137 -0
- agent_blackbox_cli-0.3.0/blackbox/py.typed +0 -0
- agent_blackbox_cli-0.3.0/blackbox/replay.py +65 -0
- agent_blackbox_cli-0.3.0/blackbox/report/__init__.py +0 -0
- agent_blackbox_cli-0.3.0/blackbox/report/html.py +375 -0
- agent_blackbox_cli-0.3.0/blackbox/report/text.py +287 -0
- agent_blackbox_cli-0.3.0/blackbox/store.py +215 -0
- agent_blackbox_cli-0.3.0/blackbox/toolinfo.py +336 -0
- agent_blackbox_cli-0.3.0/pyproject.toml +58 -0
- agent_blackbox_cli-0.3.0/setup.cfg +4 -0
- agent_blackbox_cli-0.3.0/tests/test_adapter.py +66 -0
- agent_blackbox_cli-0.3.0/tests/test_bench.py +255 -0
- agent_blackbox_cli-0.3.0/tests/test_cli.py +247 -0
- agent_blackbox_cli-0.3.0/tests/test_codex_adapter.py +218 -0
- agent_blackbox_cli-0.3.0/tests/test_cost.py +57 -0
- agent_blackbox_cli-0.3.0/tests/test_detectors.py +363 -0
- agent_blackbox_cli-0.3.0/tests/test_determinism.py +100 -0
- agent_blackbox_cli-0.3.0/tests/test_diff.py +150 -0
- agent_blackbox_cli-0.3.0/tests/test_graph.py +42 -0
- agent_blackbox_cli-0.3.0/tests/test_guard.py +356 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Puja Sridhar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-blackbox-cli
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Structured analytics for a single agent run, from the trace file it already writes. No SDK, no vendor, no model calls.
|
|
5
|
+
Author: Puja Sridhar
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/PujaSridhar/agent-blackbox
|
|
8
|
+
Project-URL: Repository, https://github.com/PujaSridhar/agent-blackbox
|
|
9
|
+
Project-URL: Issues, https://github.com/PujaSridhar/agent-blackbox/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/PujaSridhar/agent-blackbox/releases
|
|
11
|
+
Keywords: agents,llm,observability,tracing,cost-analysis,claude-code,codex,duckdb
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
20
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
21
|
+
Classifier: Topic :: System :: Monitoring
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: duckdb>=1.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# Agent Black Box
|
|
32
|
+
|
|
33
|
+
[](https://github.com/PujaSridhar/agent-blackbox/actions/workflows/ci.yml)
|
|
34
|
+
[](https://github.com/PujaSridhar/agent-blackbox)
|
|
35
|
+
[](https://github.com/PujaSridhar/agent-blackbox/blob/main/LICENSE)
|
|
36
|
+
|
|
37
|
+
**Drop in one agent trace file. Get structured analytics out. No SDK, no vendor, no model calls.**
|
|
38
|
+
|
|
39
|
+
Checked against 5,763 agent runs whose waste a published study had labelled:
|
|
40
|
+
82% of the turns it flags were waste by the study's own judge (89.5% for retry
|
|
41
|
+
loops), from tool calls alone, in under six seconds.
|
|
42
|
+
[How that was measured.](https://github.com/PujaSridhar/agent-blackbox#scored-against-waste-someone-else-labelled)
|
|
43
|
+
|
|
44
|
+
Everyone is shipping agents. Almost nobody can say what their agent actually
|
|
45
|
+
did, what it cost, or where it went wrong — not after the fact, not cheaply,
|
|
46
|
+
and not in a form anyone else can check.
|
|
47
|
+
|
|
48
|
+
The usual answer is an observability vendor: a new SDK in your hot path, a
|
|
49
|
+
contract, and a dashboard you have to trust. But your agent already writes a
|
|
50
|
+
trace file. That file is enough.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
blackbox # the latest run in this directory
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
AGENT BLACK BOX 1919 events from session.jsonl
|
|
58
|
+
adapter claude_code · 384 tool calls · 14 failed · 6.7h active over 31.2h
|
|
59
|
+
46min waiting on you · 2 calls you declined
|
|
60
|
+
|
|
61
|
+
COST $319.28 rates as of 2026-11-10
|
|
62
|
+
model msgs output cache read 1h writes usd
|
|
63
|
+
claude-fable-5 203 651,144 27,159,636 1,428,422 88.96
|
|
64
|
+
claude-opus-4-8 568 748,144 196,595,856 11,385,828 230.33
|
|
65
|
+
44.4% of spend was 1-hour cache writes <- rebuilding a long cached prefix
|
|
66
|
+
is where this run's money went
|
|
67
|
+
at least $24.88 (7.8%) went to work that did not advance the task
|
|
68
|
+
thrash $23.75, retry loop $1.13, error cluster $0.35
|
|
69
|
+
|
|
70
|
+
FINDINGS 50 total (7 high, 18 medium, 25 low)
|
|
71
|
+
[HIGH] thrash backend/physics.py written 9x in 70 tool calls $5.06
|
|
72
|
+
backend/physics.py was written 9 times inside a span of 70 tool
|
|
73
|
+
calls. Edits that tightly packed usually mean each change was
|
|
74
|
+
fixing the last one.
|
|
75
|
+
· step 1204 line 1533 Edit: /repo/backend/physics.py
|
|
76
|
+
· step 1211 line 1540 Edit: /repo/backend/physics.py
|
|
77
|
+
...
|
|
78
|
+
|
|
79
|
+
payload digest 4b2f61f38c729c · detectors ran with no model calls
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Then prove it:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
blackbox --verify
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
verify OK 50 findings replayed byte-identical from the event store,
|
|
90
|
+
with no model calls
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## The part that makes the numbers mean something
|
|
96
|
+
|
|
97
|
+
A trace file is a flat list of rows. Counting tool calls in file order is easy
|
|
98
|
+
and mostly useless, because a flat list cannot answer two questions:
|
|
99
|
+
|
|
100
|
+
**Which result belongs to which call?** When an assistant message issues
|
|
101
|
+
several tool calls at once, file order cannot say which result answers which
|
|
102
|
+
call. Every per-call duration computed from it is wrong, and "the agent
|
|
103
|
+
stalled here" becomes a coin flip. This tool re-parents each result onto its
|
|
104
|
+
own `tool_use` block, so the edge is causal rather than chronological.
|
|
105
|
+
|
|
106
|
+
**Whose cost is this?** A subagent's tokens are billed to the run but are not
|
|
107
|
+
the main thread's work. Smear them together and the expensive step looks cheap
|
|
108
|
+
while the main thread looks bloated. Sidechain events are resolved into their
|
|
109
|
+
own branches and costed separately.
|
|
110
|
+
|
|
111
|
+
Everything downstream — cost, detectors, reports — reads that graph, never the
|
|
112
|
+
raw file. Build the graph wrong and every number is confidently wrong.
|
|
113
|
+
|
|
114
|
+
### The cost detail nobody surfaces
|
|
115
|
+
|
|
116
|
+
Token totals hide where money goes. This splits the cache tiers, because they
|
|
117
|
+
are billed at different multiples of the input rate:
|
|
118
|
+
|
|
119
|
+
| tier | rate | why it matters |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| cache read | 0.1× input (lower where published) | nearly free; a high read share is healthy |
|
|
122
|
+
| cache write, 5 min | 1.25× input | costs *more* than fresh input |
|
|
123
|
+
| cache write, 1 hour | 2.0× input | the most expensive tokens in the run |
|
|
124
|
+
|
|
125
|
+
A run can look cheap per token and still be expensive. In the session above,
|
|
126
|
+
**44.4% of $319.28 went to 1-hour cache writes** — a long cached prefix being
|
|
127
|
+
rebuilt over and over. That is invisible in any flat token count.
|
|
128
|
+
|
|
129
|
+
### Findings cost money, and the report says how much
|
|
130
|
+
|
|
131
|
+
Every finding carries the cost of the model turns behind it, and the run
|
|
132
|
+
carries a total. On that session, **$24.88 — 7.8% of the bill — went to work
|
|
133
|
+
that did not advance the task**, nearly all of it rewriting the same files.
|
|
134
|
+
|
|
135
|
+
That figure is a floor, deliberately. It counts the turns that issued the
|
|
136
|
+
implicated calls; it does not try to price the downstream cost of carrying
|
|
137
|
+
their results in context, which cannot be attributed exactly. A number you can
|
|
138
|
+
defend beats a larger one you cannot.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Findings
|
|
143
|
+
|
|
144
|
+
Six detectors, all pure functions of the graph. No model decides anything.
|
|
145
|
+
|
|
146
|
+
| detector | fires on | deliberately does not fire on |
|
|
147
|
+
|---|---|---|
|
|
148
|
+
| `retry_loop` | the same acting call repeated with identical input inside a sliding window | observation and progress tools — eight identical screenshots is polling, and advancing a task list ten times is bookkeeping |
|
|
149
|
+
| `stall` | wall-clock gap between a call and its result | interrupted calls; tools that exist to wait for a human; pauses long enough to be a person away, reported separately as idle gaps |
|
|
150
|
+
| `error_cluster` | failed calls grouped by normalised error shape, keyed by the program that ran | bare `Exit code 1` headers; calls a human declined |
|
|
151
|
+
| `contradiction` | the same *region* of a file re-read with different bytes and no write between; a file edited in place the agent has never seen | paging through a file with `offset`/`limit`; editing a file the agent created itself; editing a file it read through the shell |
|
|
152
|
+
| `thrash` | several writes to one file inside a sliding window | the same number of writes spread across a long session |
|
|
153
|
+
| `context_bloat` | a large tool result, priced by the turns that carried it afterwards | runs with no model price available — no rate, no claim |
|
|
154
|
+
|
|
155
|
+
**Every exclusion in the right-hand column is a false positive found by running
|
|
156
|
+
against real traces, not a hypothetical.** On the first real corpus the naive
|
|
157
|
+
versions produced 249 findings; the current ones produce 198, and the 51 that
|
|
158
|
+
disappeared were all wrong:
|
|
159
|
+
|
|
160
|
+
* 17 of 17 "blind edits" were files the agent had created itself with `Write`.
|
|
161
|
+
Having authored a file is knowing its contents.
|
|
162
|
+
* The one "stale read" — the finding this README used to lead with — was an
|
|
163
|
+
agent paging through `game.py` at `offset=95` then `offset=164`. Two regions
|
|
164
|
+
of an unchanged file, reported as tampering.
|
|
165
|
+
* Seven unrelated shell failures collapsed into one `Exit code <n>` cluster,
|
|
166
|
+
because the first line of a failed `Bash` result is a header, not an error.
|
|
167
|
+
* Four "stalls" were `AskUserQuestion` waiting for a human to type.
|
|
168
|
+
* Two "tool failures" were a human declining a call.
|
|
169
|
+
* Files were reported as thrashed for three edits across six hours.
|
|
170
|
+
|
|
171
|
+
Adding the second adapter found one more of exactly the same kind:
|
|
172
|
+
|
|
173
|
+
* 84 of 84 "blind edits" on the Codex corpus had a `sed -n '1,200p' <file>`
|
|
174
|
+
before them. That agent inspects files through the shell rather than a file
|
|
175
|
+
tool, and a shell read is a read. Counting it dropped contradictions across
|
|
176
|
+
both corpora from 92 to 14.
|
|
177
|
+
|
|
178
|
+
Each of those has a regression test with the real-world case written into it.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Why replay is the point
|
|
183
|
+
|
|
184
|
+
An analysis of an agent run that cannot itself be re-verified is just another
|
|
185
|
+
opinion. This one reproduces exactly:
|
|
186
|
+
|
|
187
|
+
* the parsed run is written to a **DuckDB** event store;
|
|
188
|
+
* the detectors re-derive every finding from that store — no trace file, no
|
|
189
|
+
network, no model;
|
|
190
|
+
* thresholds are read back out of the store, so a moved default cannot let a
|
|
191
|
+
replay quietly disagree with the original;
|
|
192
|
+
* the payload contains no wall-clock reads, so two runs serialise to identical
|
|
193
|
+
bytes.
|
|
194
|
+
|
|
195
|
+
`tests/test_determinism.py` enforces all of it, including a test that
|
|
196
|
+
monkeypatches `socket` to prove the analysis path cannot open a connection.
|
|
197
|
+
Across 37 real transcripts from two different agents, all 37 replay
|
|
198
|
+
byte-identical.
|
|
199
|
+
|
|
200
|
+
Because the store is just DuckDB, it is also the query interface:
|
|
201
|
+
|
|
202
|
+
```sql
|
|
203
|
+
-- where did the time go?
|
|
204
|
+
select tool_name, count(*) calls, sum(length(tool_output)) output_bytes
|
|
205
|
+
from events where kind = 'tool_call' group by 1 order by 2 desc;
|
|
206
|
+
|
|
207
|
+
-- what did each branch cost?
|
|
208
|
+
select branch, sum(output_tokens) out, sum(cache_write_1h_tokens) writes_1h
|
|
209
|
+
from events group by 1;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Install and use
|
|
215
|
+
|
|
216
|
+
Nothing to clone, nothing to configure:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
uvx --from agent-blackbox-cli blackbox scan
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pipx run --spec agent-blackbox-cli blackbox scan
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
It reads the transcripts already on your machine, offline, and prints what
|
|
227
|
+
your agents have been doing. Or install it properly:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pip install agent-blackbox-cli # installs the `blackbox` command
|
|
231
|
+
pip install git+https://github.com/PujaSridhar/agent-blackbox # or the latest from main
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Nobody remembers a session UUID, so you never have to type one:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
blackbox # latest run for the current directory
|
|
238
|
+
blackbox ls # recent sessions, newest first
|
|
239
|
+
blackbox scan # every local run, aggregated
|
|
240
|
+
blackbox ~/.claude/projects/app/ # every run for one project
|
|
241
|
+
blackbox run.jsonl # one specific trace
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Discovery covers both agents: Claude Code encodes the project into the
|
|
245
|
+
directory name, Codex records it inside the file, and `ls` and `scan` read
|
|
246
|
+
whichever applies. Symlinked paths are resolved both ways, because on macOS
|
|
247
|
+
`/tmp` and `/private/tmp` encode differently.
|
|
248
|
+
|
|
249
|
+
`scan` is the one to try first — it reads every transcript on the machine,
|
|
250
|
+
offline, and tells you what your agent gets wrong *habitually*:
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
AGENT BLACK BOX every run on this machine
|
|
254
|
+
37 run(s) · 3,811 tool calls · 300 findings · 34.7h active
|
|
255
|
+
|
|
256
|
+
SPEND $1,029.85 across 37 run(s)
|
|
257
|
+
at least $88.64 (8.6%) on work that did not advance the task
|
|
258
|
+
cache hit rate 95.2% of billed input · 37,212,551 tokens of 1-hour cache writes
|
|
259
|
+
tool failure rate 5.0% (190 failed)
|
|
260
|
+
|
|
261
|
+
MOST REWRITTEN FILES
|
|
262
|
+
39x /Users/me/reports/summary/main.tex
|
|
263
|
+
16x /Users/me/dataplane/loaders/get_datasets.py
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Did that change help?
|
|
267
|
+
|
|
268
|
+
Tuning a system prompt, swapping a model, adding an MCP server — the honest
|
|
269
|
+
answer has been a feeling. `diff` makes it a measurement, and because
|
|
270
|
+
everything upstream is deterministic, a difference is a difference in the
|
|
271
|
+
agent rather than in the measurement:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
blackbox diff before.jsonl after/
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
AGENT BLACK BOX diff
|
|
279
|
+
before after change
|
|
280
|
+
cost $4.81 $12.40 +$7.58 worse
|
|
281
|
+
wasted $1.93 $4.34 +$2.41 worse
|
|
282
|
+
wasted share 40.1% 35.0% -5.1pp better
|
|
283
|
+
cache hit rate 95.8% 91.4% -4.5pp worse
|
|
284
|
+
tool failure rate 2.0% 2.5% +0.5pp worse
|
|
285
|
+
|
|
286
|
+
FINDINGS BY TYPE
|
|
287
|
+
retry_loop 4 12 +8 worse
|
|
288
|
+
thrash 13 9 -4 better
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Either side can be one trace or a directory of them. When the run counts
|
|
292
|
+
differ — one run before a change, three after — totals are also reported per
|
|
293
|
+
run and the verdict follows those, because three runs costing more than one
|
|
294
|
+
is not a regression.
|
|
295
|
+
|
|
296
|
+
Outputs:
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
blackbox run.jsonl --html out.html # self-contained page, no JS, no network
|
|
300
|
+
blackbox run.jsonl --json out.json # canonical payload
|
|
301
|
+
blackbox run.jsonl --db run.duckdb # queryable event store
|
|
302
|
+
blackbox run.jsonl --verify # store, replay, compare digests
|
|
303
|
+
blackbox --replay run.duckdb # re-derive from a stored run
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Thresholds are flags, not magic numbers: `--stall-seconds`, `--idle-seconds`,
|
|
307
|
+
`--retry-min-repeats`, `--retry-window`, `--thrash-min-edits`,
|
|
308
|
+
`--thrash-window`, `--error-cluster-min`, `--bloat-min-tokens`,
|
|
309
|
+
`--bloat-min-usd`. Whatever you pass is recorded in the store and reused on
|
|
310
|
+
replay.
|
|
311
|
+
|
|
312
|
+
The HTML report is one file with no scripts and no network requests — it
|
|
313
|
+
renders from a USB stick in five years. A rendered example, built from the
|
|
314
|
+
synthetic fixture so every path in it is `/repo/...`, is checked in at
|
|
315
|
+
[`docs/example-report.html`](https://github.com/PujaSridhar/agent-blackbox/blob/main/docs/example-report.html) (and
|
|
316
|
+
[the Codex one](https://github.com/PujaSridhar/agent-blackbox/blob/main/docs/example-report-codex.html)). Reports from real sessions
|
|
317
|
+
stay out of git, because they embed the file paths of whatever produced them.
|
|
318
|
+
|
|
319
|
+
### As a library
|
|
320
|
+
|
|
321
|
+
The CLI is the usual way in, but the interesting questions are the ones
|
|
322
|
+
nobody anticipated:
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
from blackbox import analyze
|
|
326
|
+
|
|
327
|
+
run = analyze("session.jsonl")
|
|
328
|
+
run.cost.total_usd # 319.28
|
|
329
|
+
run.wasted()["share_of_run"] # 0.078
|
|
330
|
+
[f.title for f in run.findings if f.severity == "high"]
|
|
331
|
+
run.payload() # the whole canonical result
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Ships with `py.typed`, so your type checker sees the annotations.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## Stop it while it happens
|
|
339
|
+
|
|
340
|
+
Everything above reads a run after it ends. That finds the waste; it does not
|
|
341
|
+
save any of it. `blackbox guard` runs the same two detectors that find most of
|
|
342
|
+
the waste, `retry_loop` and `thrash`, as a Claude Code hook, on every tool call
|
|
343
|
+
while the agent is working:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
blackbox guard install # .claude/settings.json, for this project
|
|
347
|
+
blackbox guard install --scope local # .claude/settings.local.json, just you
|
|
348
|
+
blackbox guard install --dry-run # show the change, write nothing
|
|
349
|
+
blackbox guard uninstall
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Nothing is written until you run `install`, and it leaves every other setting
|
|
353
|
+
and hook in the file alone. Before a call (`PreToolUse`) the guard can deny it;
|
|
354
|
+
after a call (`PostToolUse`) it can tell the agent what it is repeating. It
|
|
355
|
+
reads the transcript Claude Code already writes, makes no model call, opens no
|
|
356
|
+
socket, and answers in well under a second (about 0.2s on an 8 MB session).
|
|
357
|
+
|
|
358
|
+
Want to know what it would have done before installing it? Replay any finished
|
|
359
|
+
run through it:
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
blackbox guard replay tests/fixtures/guard_demo.jsonl
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
AGENT BLACK BOX guard replay of guard_demo.jsonl
|
|
367
|
+
28 tool calls · $1.57 run cost · warns at medium, blocks at high
|
|
368
|
+
|
|
369
|
+
line 12 warn retry_loop 3rd identical call Bash: pytest tests/test_dates.py -x $0.11 so far
|
|
370
|
+
line 14 warn retry_loop 4th identical call Bash: pytest tests/test_dates.py -x $0.17 so far
|
|
371
|
+
line 16 BLOCK retry_loop 5th identical call Bash: pytest tests/test_dates.py -x $0.22 so far
|
|
372
|
+
line 18 warn retry_loop 5th identical call Bash: pytest tests/test_dates.py -x $0.22 so far
|
|
373
|
+
line 34 warn thrash 5th write in 14 calls Edit: /repo/src/dates.py $0.22 so far
|
|
374
|
+
...
|
|
375
|
+
line 46 BLOCK thrash 8th write in 20 calls Edit: /repo/src/dates.py $0.39 so far
|
|
376
|
+
|
|
377
|
+
what the agent would have read instead of running that call:
|
|
378
|
+
|
|
379
|
+
[agent-blackbox guard] Blocked. This would be the 5th identical call in
|
|
380
|
+
the last 5 tool calls, with nothing written in between: Bash: pytest
|
|
381
|
+
tests/test_dates.py -x. The earlier ones cost about $0.22. Identical input
|
|
382
|
+
will give the same result. Read the last output, change something, or try
|
|
383
|
+
a different approach before running it again. (If you make this call again
|
|
384
|
+
unchanged, it will be allowed.)
|
|
385
|
+
|
|
386
|
+
2 block(s), 8 warning(s)
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
Point it at your own sessions (`blackbox ls` lists them) to see where it would
|
|
390
|
+
have spoken. It does not claim a saving: what the agent would have done
|
|
391
|
+
instead is unknown, so the replay reports what the guard stood in front of.
|
|
392
|
+
|
|
393
|
+
**Defaults, and why.** The guard uses the detectors' own severity scale. It
|
|
394
|
+
warns at medium and blocks at high, so a retry is mentioned on the 3rd
|
|
395
|
+
identical call and stopped on the 5th, and a file is mentioned on its 5th write
|
|
396
|
+
in a burst and stopped on its 8th. Change either with `--warn-at` and
|
|
397
|
+
`--block-at` (`high`, `medium`, `low`, `never`); `--block-at never` makes it
|
|
398
|
+
advisory only. The detector thresholds take the same flags as the report.
|
|
399
|
+
|
|
400
|
+
Three rules keep it out of the way of ordinary work. Each is a case where a
|
|
401
|
+
naive guard would be wrong, and a guard that is wrong gets uninstalled:
|
|
402
|
+
|
|
403
|
+
| rule | because |
|
|
404
|
+
|---|---|
|
|
405
|
+
| an edit to any file resets a retry streak | run tests, edit, run tests again is the loop working, not a retry |
|
|
406
|
+
| a streak is blocked once; the same call straight after goes through, with a warning | the agent has been told, and a guard that can trap an agent is worse than none |
|
|
407
|
+
| a call it cannot place is allowed | a subagent call not yet in the transcript cannot be put on the right branch |
|
|
408
|
+
|
|
409
|
+
It fails open: a malformed event, a missing transcript or any error means the
|
|
410
|
+
hook prints nothing and the call proceeds. `BLACKBOX_GUARD=off` turns it off
|
|
411
|
+
for one session. On long sessions it reads only the last few thousand rows of
|
|
412
|
+
the transcript, which holds any streak these windows can see.
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## Two agents, one model
|
|
417
|
+
|
|
418
|
+
`blackbox/adapters/` is the only place that knows a vendor's log format. An
|
|
419
|
+
adapter exposes `NAME`, `sniff(path)` and `parse(path) -> Trace`, and emits
|
|
420
|
+
canonical `Event` objects.
|
|
421
|
+
|
|
422
|
+
That boundary was an assertion until a second format tested it. **Adding
|
|
423
|
+
OpenAI Codex CLI support took one adapter file and no change to the graph, the
|
|
424
|
+
cost engine, or any detector** — but it did force two genuine generalisations,
|
|
425
|
+
which is the point of doing it:
|
|
426
|
+
|
|
427
|
+
| Codex does this | so the canonical model gained |
|
|
428
|
+
|---|---|
|
|
429
|
+
| no parent pointers; a flat sequence | the spine is rebuilt from `call_id` and turn order, shared by both adapters |
|
|
430
|
+
| cumulative token counts (summing per-request usage over-counts by ~5%) | per-turn usage is the delta between readings |
|
|
431
|
+
| `input_tokens` already includes cached ones | fresh input is the difference, and no cache-write tier is invented |
|
|
432
|
+
| one `apply_patch` edits several files | file operations are a list of `(path, kind)`, so `thrash` and `contradiction` work on patch tools unchanged |
|
|
433
|
+
| records a compaction boundary | `context_bloat` stops counting there instead of over-estimating |
|
|
434
|
+
|
|
435
|
+
Both formats are undocumented and will drift. That is not a reason to avoid
|
|
436
|
+
reading them; it is a reason to put the churn behind one boundary.
|
|
437
|
+
Unrecognised row types degrade to `meta` events rather than crashing, so a new
|
|
438
|
+
row type upstream costs fidelity, never a run.
|
|
439
|
+
|
|
440
|
+
### Prices for models this build does not ship
|
|
441
|
+
|
|
442
|
+
Rates are only included where they could be verified. Rather than guess at
|
|
443
|
+
another vendor's pricing, supply it:
|
|
444
|
+
|
|
445
|
+
```bash
|
|
446
|
+
blackbox run.jsonl --prices rates.json
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
```json
|
|
450
|
+
{ "gpt-5.4": { "input": 1.25, "output": 10.0, "cache_read": 0.125 } }
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
*(Illustrative values — put your own in.)* Supplied rates are stored with the
|
|
454
|
+
run and reapplied on replay, so a stored analysis prices identically forever.
|
|
455
|
+
Without them the tokens are still counted and the total is marked a floor.
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## Scored against waste someone else labelled
|
|
460
|
+
|
|
461
|
+
A tool that says "this was wasted" should be checked against someone who
|
|
462
|
+
looked without it. *How Do AI Agents Waste Your Money?* (Zeng, Lu, Cai et al.,
|
|
463
|
+
2026, [arXiv 2611.07238](https://arxiv.org/abs/2611.07238)) released 5,763
|
|
464
|
+
agent trajectories from six models, several harnesses and four benchmarks
|
|
465
|
+
(τ²-bench, SWE-bench Verified, Claw-Eval, MCP-Atlas), with every deletable span
|
|
466
|
+
of output marked by an LLM judge that read the whole run and named the kind of
|
|
467
|
+
waste:
|
|
468
|
+
|
|
469
|
+
| label | meaning | can a model-free detector see it? |
|
|
470
|
+
|---|---|---|
|
|
471
|
+
| `duplicate-fetch` | a tool call fetching what the agent already had | yes: `retry_loop` |
|
|
472
|
+
| `detour` | work that looked reasonable but the task did not need | partly: `thrash`, `error_cluster`, `retry_loop` |
|
|
473
|
+
| `restated` | prose repeating what is already in context | no: it is in the prose, not the calls |
|
|
474
|
+
| `padding` | preambles, sign-offs, narration | no |
|
|
475
|
+
|
|
476
|
+
`blackbox bench` runs the detectors over those trajectories exactly as they run
|
|
477
|
+
on a Claude Code or Codex trace (a third adapter, `labelled-turns`, reads the
|
|
478
|
+
format; the detectors never see the labels), then asks two questions: of the
|
|
479
|
+
turns Agent Black Box flags, how many did the judge also call waste, and how
|
|
480
|
+
much of the judge's waste do the flags reach?
|
|
481
|
+
|
|
482
|
+
<!-- bench:start -->
|
|
483
|
+
On 5,763 labelled trajectories (85,877 judged turns), Agent Black Box flagged 1,741 turns as wasted work in 5.47 seconds, with no model calls. 82.0% of them were also marked as waste by the paper's judge (against 65.4% of all turns, 1.25x the rate for a turn picked at random). They reached 9.0% of the turns labelled duplicate-fetch and 4.6% of those labelled detour.
|
|
484
|
+
|
|
485
|
+
| detector | settings | turns flagged | also judged waste | lift | duplicate-fetch found | detour found | restated found | padding found |
|
|
486
|
+
|---|---|---:|---:|---:|---:|---:|---:|---:|
|
|
487
|
+
| retry_loop | shipped | 1,027 | 89.5% | 1.37x | 8.1% | 3.5% | 0.1% | 0.2% |
|
|
488
|
+
| thrash | shipped | 155 | 61.3% | 0.94x | 0.0% | 0.2% | 0.0% | 0.2% |
|
|
489
|
+
| error_cluster | shipped | 722 | 79.4% | 1.21x | 2.1% | 1.6% | 0.5% | 0.8% |
|
|
490
|
+
| contradiction | shipped | 595 | 53.8% | 0.82x | 1.3% | 0.7% | 0.5% | 0.5% |
|
|
491
|
+
| waste detectors (combined) | shipped | 1,741 | 82.0% | 1.25x | 9.0% | 4.6% | 0.6% | 1.1% |
|
|
492
|
+
| retry_loop | retry at 2 repeats | 1,566 | 80.5% | 1.23x | 12.9% | 4.2% | 0.5% | 0.7% |
|
|
493
|
+
| waste detectors (combined) | retry at 2 repeats | 2,254 | 77.4% | 1.18x | 13.5% | 5.3% | 1.0% | 1.5% |
|
|
494
|
+
|
|
495
|
+
Judged turns: 85,877. Turns with any labelled waste: 56,171 (65.4%). Labelled turns per kind: duplicate-fetch 2,761, detour 19,309, restated 20,201, padding 38,379, unread 548.
|
|
496
|
+
|
|
497
|
+
| benchmark | trajectories | turns flagged | also judged waste | detour found |
|
|
498
|
+
|---|---:|---:|---:|---:|
|
|
499
|
+
| claw_eval | 902 | 116 | 98.3% | 4.5% |
|
|
500
|
+
| mcp_atlas | 1,402 | 142 | 99.3% | 1.6% |
|
|
501
|
+
| swe_bench | 2,107 | 1,441 | 79.4% | 6.0% |
|
|
502
|
+
| tau2-airline | 450 | 17 | 100.0% | 3.7% |
|
|
503
|
+
| tau2-retail | 902 | 25 | 44.0% | 1.6% |
|
|
504
|
+
|
|
505
|
+
Model calls: 0. Wall time: 5.47 s on one CPU core. Results digest: `8a9fd8b10ecbf494`.
|
|
506
|
+
<!-- bench:end -->
|
|
507
|
+
|
|
508
|
+
What the numbers say:
|
|
509
|
+
|
|
510
|
+
* **A flag is worth looking at.** Four in five flagged turns were waste by the
|
|
511
|
+
judge's reading, against two in three for any turn. `retry_loop` is the
|
|
512
|
+
strongest: 89.5% of its flags, 1.37x random.
|
|
513
|
+
* **Two detectors do not earn their place on this data.** `thrash` and
|
|
514
|
+
`contradiction` score at or below random here, so on runs like these their
|
|
515
|
+
findings are leads to read, not waste to count. (`contradiction` was never
|
|
516
|
+
part of the waste total.)
|
|
517
|
+
* **It finds a small share of the waste.** 9% of the duplicate fetches and 5%
|
|
518
|
+
of the detours. Most labelled waste is prose (`padding` and `restated` are
|
|
519
|
+
nearly three quarters of the labels), which a detector that reads tool calls cannot see.
|
|
520
|
+
This is a precise tool, not a complete one.
|
|
521
|
+
* **Small slices swing.** `tau2-retail` rests on 25 flagged turns and
|
|
522
|
+
`tau2-airline` on 17.
|
|
523
|
+
|
|
524
|
+
How a finding becomes a flagged turn: for `retry_loop`, every repeat after the
|
|
525
|
+
first call (the first was a reasonable thing to do); for `thrash`, every write
|
|
526
|
+
after the first in a burst; for `error_cluster`, every failed call. Repeats the
|
|
527
|
+
tool already calls polling or bookkeeping are not claimed as waste, so they are
|
|
528
|
+
not counted. The combined row is the same three detectors the cost report
|
|
529
|
+
already treats as waste. "Lift" compares precision with the share of all judged
|
|
530
|
+
turns that carry any waste, which is what flagging turns at random would score.
|
|
531
|
+
|
|
532
|
+
What this benchmark can and cannot say:
|
|
533
|
+
|
|
534
|
+
* **The judge is a model, not ground truth.** A flagged turn the judge did not
|
|
535
|
+
mark counts against precision here, though the judge may be the one that is
|
|
536
|
+
wrong. The paper validates its labels by intervention, not by human agreement.
|
|
537
|
+
* **Prose waste is out of reach by design.** `restated` and `padding` live in
|
|
538
|
+
what the agent wrote, not what it called. They are reported so the gap is
|
|
539
|
+
visible, not to be claimed.
|
|
540
|
+
* **Two detectors cannot fire on this data.** It has no timestamps (`stall`)
|
|
541
|
+
and no input-token counts (`context_bloat`), so neither is scored, and no
|
|
542
|
+
dollar figure is reported.
|
|
543
|
+
* **One threshold differs.** The dataset counts a single repeat as
|
|
544
|
+
`duplicate-fetch`; the shipped `retry_loop` waits for two. The table shows
|
|
545
|
+
both settings rather than retuning the tool to the test.
|
|
546
|
+
|
|
547
|
+
Reproduce it (the data is CC BY 4.0 and downloads without signing in):
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
pip install -e . huggingface_hub
|
|
551
|
+
hf download huiminz3/How_Do_AI_Agents_Waste_Your_Money \
|
|
552
|
+
--repo-type dataset --local-dir waste-data
|
|
553
|
+
blackbox bench waste-data/data --json bench.json --update-readme README.md
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
The scores and their digest are identical on every run; only the wall time
|
|
557
|
+
changes. Data: Zeng et al., *How Do AI Agents Waste Your Money?*, CC BY 4.0.
|
|
558
|
+
None of it is committed here; the tests run on a hand-written file in the same
|
|
559
|
+
format (`tests/fixtures/make_labelled_fixture.py`).
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
## Limitations
|
|
564
|
+
|
|
565
|
+
Stated plainly, because a tool that overclaims about trustworthiness has
|
|
566
|
+
defeated itself:
|
|
567
|
+
|
|
568
|
+
* **Two agent adapters.** Claude Code and OpenAI Codex CLI. A third,
|
|
569
|
+
`labelled-turns`, reads a research dataset's format for the benchmark; it
|
|
570
|
+
has no timestamps or input tokens, so stalls, context bloat and dollars are
|
|
571
|
+
not available on it.
|
|
572
|
+
* **Only Anthropic rates ship.** Other vendors' models are reported as
|
|
573
|
+
unpriced unless you supply rates with `--prices`.
|
|
574
|
+
* **Shell reads are matched loosely.** A file read with `cat` or `sed` is
|
|
575
|
+
matched to an edit by trailing path components, because one is usually
|
|
576
|
+
relative and the other absolute. The bias is deliberate: over-matching
|
|
577
|
+
suppresses a blind-edit report, under-matching invents one.
|
|
578
|
+
* **`context_bloat` is an estimate.** Token counts are derived from character
|
|
579
|
+
length, and context editing or compaction would evict a result early. It is
|
|
580
|
+
an upper bound on a context that is never cleared, and it is labelled as one
|
|
581
|
+
everywhere it appears.
|
|
582
|
+
* **Stall timings are upper bounds.** The gap between a call and its result
|
|
583
|
+
includes any wait for approval. The report says so where it reports one.
|
|
584
|
+
* **Prices are a table, not an API.** Rates in `blackbox/pricing.py` were
|
|
585
|
+
verified on 2026-11-10. Tokens on a model missing from the table are counted
|
|
586
|
+
and reported as unpriced, and the total is marked a floor.
|
|
587
|
+
* **Waste attribution is a floor.** It counts the turns behind a finding, not
|
|
588
|
+
the downstream context those turns created.
|
|
589
|
+
* **Blind-edit detection is per-trace.** A file read in an earlier session
|
|
590
|
+
looks unread here.
|
|
591
|
+
* **The guard is Claude Code only.** Codex runs can be replayed through it,
|
|
592
|
+
but only Claude Code has the hook it installs into. It judges streaks from
|
|
593
|
+
the transcript, which Claude Code writes asynchronously, so a call made in
|
|
594
|
+
the last moment may not be counted yet.
|
|
595
|
+
* **A resumed session may reference rows in another file.** Those parents are
|
|
596
|
+
reported as orphan events rather than silently dropped.
|
|
597
|
+
|
|
598
|
+
---
|
|
599
|
+
|
|
600
|
+
## Development
|
|
601
|
+
|
|
602
|
+
```bash
|
|
603
|
+
pip install -e ".[dev]"
|
|
604
|
+
pytest -q
|
|
605
|
+
python tests/fixtures/make_fixture.py # regenerate the synthetic trace
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
python tests/fixtures/make_codex_fixture.py # and the Codex one
|
|
610
|
+
python tests/fixtures/make_labelled_fixture.py # and the labelled-turns one
|
|
611
|
+
python -m tests.fixtures.make_guard_fixture # and the run the guard demo replays
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
The fixtures are hand-written rather than copied from real sessions: every
|
|
615
|
+
detector has a case planted for it, *and every false positive has a negative
|
|
616
|
+
case planted next to it* — a file written then edited, a file read in two
|
|
617
|
+
regions, a file inspected with `sed`, a question a human took four minutes to
|
|
618
|
+
answer, a token count reported twice. A fixture nobody can read is a fixture
|
|
619
|
+
nobody trusts.
|
|
620
|
+
|
|
621
|
+
## License
|
|
622
|
+
|
|
623
|
+
MIT
|