Where the Tokens Go: Heat, Entropy and Error in Agentic Coding
Organizations: Department of Computer Science, University of Toronto, Toronto, Canada · Department of Chemistry, University of Toronto, Toronto, Canada · Acceleration Consortium, Toronto, Canada · Vector Institute for Artificial Intelligence, Toronto, Canada ·
Abstract
Coding agents are billed by the token, yet software engineering says nothing about what a token actually buys. Here we introduce a theory of software thermodynamics. The theory draws analogues from classical and stochastic thermodynamics, extends them, and applies them to modern agentic coding. We count the tokens an agent generates as its cost and divide that cost into work and heat. The test suite acts as a software Maxwell's daemon that judges every coding change. We test the theory with an analogue of the experiments in which a single molecule is pulled open and let fold again: an agent makes a change to a repository (coding) and then undoes it (uncoding), many times over, and we count the tokens of every model call. The cycle returns the requested edits to where they began, with each direction started from a stored reference tree, and the spread of its cost over repeated cycles defines a software temperature, which rose with the sampling temperature of the model. About 80 per cent of the tokens of a successful run are generated in model calls that leave the requested change where it was, and we call these tokens heat. The free energy of a change, which we estimate by analogy with the equality of Jarzynski, is 14 to 22 per cent of the mean cost of a successful coding run. Coding costs 1.1 to 1.5 times as much as uncoding. The daemon is imperfect: the verdict of a test suite varies with its environment, and a suite that accepts a broken change has a cost in tokens. The practical implication of the proposed theory could be new tools for analysing and optimising coding agents through the lens of thermodynamics.
Figures & tables
| Idea | Symbol(s) | Classical thermodynamics | Software thermodynamics | Status | Defined | Measured |
| The system, work and heat | ||||||
| System | A gas in a cylinder | A tree : a code repository at one exact version | d x | § 2.1.1 | ||
| Process | One stroke of the piston | A run : an agent edits the tree, call by call, until the tests pass | d x | § 2.1.2 | ||
| Reaction coordinate | The extension of a pulled molecule | The fraction of the change’s blocks that are in place in the tree | d x | § 2.1.1 | § 4.1 | |
| Cost | The fuel burned | The tokens that the model generates in a run, whether or not the run lands | d x | § 2.1.2 | § 2.2 | |
| Work | The energy that the piston puts in | The tokens of the turns that add target edits to the tree; turns that remove them count negative (Eq. 6 ) | d x | § 2.1.3 | § 2.5 | |
| Carnot’s cycle | Unfolding and refolding a single molecule [ 11 , 4 ] | Coding and uncoding a single repository (this work) | |
|---|---|---|---|
| The system | A gas in a cylinder | A single RNA molecule held in optical tweezers | A code repository edited by a coding agent |
| The baths | Two, one hot and one cold | One, the solution around the molecule | One, the model sampled through its harness, at the software temperature ; the gate is read as a second, colder one (§ 1 ) |
| What is driven | The piston | The distance between the two ends of the molecule | The instruction given to the agent: make the change, or undo it |
| The cycle | The gas expands at the hot bath and is compressed at the cold one, back to its start | The molecule is pulled open (unfolding, forward) and then let fold again (refolding, reverse) | The agent makes a change (coding, forward) and then undoes it (uncoding, reverse) (§ 2.1.4 ) |
| What the cycle delivers | Work, taken from the heat of the hot bath | Nothing: opening costs more work than folding returns, and the difference is lost as heat | Nothing: every token of the cycle is heat (§ 2.2 ) |
| What is recorded | The heat drawn and the work delivered | The force against the extension, and from it the work of each pull | The tokens of each turn and the progress toward the goal, and from them the work of each run (Eq. 6 , § 2.1.3 ) |
| estimate | Task A, | Task B, | Task B, |
|---|---|---|---|
| , coding (Eq. 13 ) | 351 | 275 | 339 |
| Test 1: , uncoding | 334 ( 5%) | 297 ( 8%) | 360 ( 6%) |
| Test 2: (Eq. 16 ) | 352 (0%) | 295 ( 7%) | 340 (0%) |
| Test 3: crossing | 373 ( 6%) | 243 ( 12%) | 333 ( 2%) |
| Test 4: mixture of two Gaussians | 348 ( 1%) | 275 (0%) | 338 (0%) |
| Test 4: Bennett’s acceptance ratio | 346 ( 2%) | 269 ( 2%) | 327 ( 4%) |
| question | answer | section |
|---|---|---|
| What does it cost to make a change and then undo it? | The cycle returns the requested edits to their start, and it still costs tokens. It is a hysteresis loop at one temperature, like that of a molecule pulled open and folded again, and all of its tokens are lost. | § 2.2 , § 2.3 |
| How much of a run is heat, and what must a change cost at the least? | About 80 per cent of the tokens of a landed run are heat. The free energy of a change, our estimate of the least that the change can cost, is 14 to 22 per cent of the cost of a landed coding run. Coding and uncoding are two driven processes, and their rates do not measure that free energy. | § 2.5 |
| Where do the tokens go when the agent is cold? | Most of them go to runs that never land, because the agent is caught in a loop. The price of a landing stays the same. The lost runs add heat and almost no free energy. | § 2.4 , § 2.5.6 |
| How good an instrument is the test suite? | It is a noisy one. The number of tests failed by the suite varies from one clean run to the next, so a threshold set on one run fixes no false-alarm rate. In sixty trials the whole suite caught no more planted defects than the tests of the changed file. | § 2.6 |
| What does an error of the gate cost? | More than its rate suggests. A verdict is a measurement with an error, and sound changes are refused while broken ones land. The share of false landings exceeded the error on the toy system, where more than half of the attempts were truly red. It stayed close to the error on the repository, where about half were. | § 2.7 |
| task | [97.5%] | zero | landed F/R | |||
|---|---|---|---|---|---|---|
| Task A | 0.1 | 4,158 | inside | 63 | 14/21 h | |
| Task A | 0.5 | 3,999 | inside | 118 | 24/24 | |
| Task A | 1.0 | 3,670 | outside | 132 | 24/24 | |
| Task B | 0.1 | 2,745 | outside | 56 | 18/24 h | |
| Task B | 0.5 | 2,757 | outside | 85 | 22/24 h | |
| Task B | 1.0 | 2,835 | outside | 80 | 20/24 h |
| Hinton temperature, | 0.01 | 0.25 | 0.5 | 0.75 | 1 |
|---|---|---|---|---|---|
| coding (forward) | 24 | 32 | 29 | 39 | 19 |
| uncoding (reverse) | 3 | 5 | 2 | 10 | 5 |
| Task | Start | Runs | Trees | Cost (tokens) | Work (tokens) | Slope (per token) | Crossing (tokens) |
|---|---|---|---|---|---|---|---|
| A | single tree | 100 | 1 | 1,804 | 317 | 0.0032 | 383 |
| A | ensemble | 100 | 24 | 1,831 | 397 | 0.0007 | 350 |
| B | single tree | 100 | 1 | 1,153 | 212 | 0.0221 | 286 |
| B | ensemble | 100 | 2 | 1,179 | 222 | 0.0190 | 304 |
| landed/runs | unfinished | cost | heat | cost | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| coding | uncoding | share, % | coding | uncoding | share, % | ratio | |||||
| Task A | 0.01 | 29/46 | 50/53 | 91/66 | 2,510 | 2,030 | 83/85 | 118 | 354 | 367 | 1.24 |
| Task A | 0.1 | 32/48 | 43/48 | 93/79 | 2,297 | 2,060 | 82/84 | 156 | 368 | 373 | 1.12 |
| Task A | 0.25 | 46/53 | 52/54 | 74/63 | 2,374 | 1,883 | 83/83 | 141 | 360 | 362 | 1.26 |
| Task A | 0.5 | 48/48 | 48/48 | 0/0 | 2,305 | 1,710 | 82/83 | 153 | 351 | 352 | 1.35 |
| Task A | 0.75 | 51/53 | 51/51 | 22/0 | 1,986 | 1,580 | 80/82 | 147 | 342 | 341 | 1.26 |
| gate | trials | planted | caught | clean passed | landed with a defect | share |
|---|---|---|---|---|---|---|
| none | 20 | 8 | 0 | 12 of 12 | 8 of 20 | 0.40 |
| the file’s own tests | 21 | 8 | 3 | 12 of 13 | 5 of 17 | 0.29 |
| whole suite, one reading | 19 | 8 | 3 | 11 of 11 | 5 of 16 | 0.31 |
| whole suite, calibrated | 19 | 8 | 2 | 11 of 11 | 6 of 17 | 0.35 |
| truly green | truly red | false-landing | |||||
|---|---|---|---|---|---|---|---|
| judged | served green | served red | served green | served red | rate | ||
| 0.01 | 76 | 36 | 1 | 1 | 38 | 0.51 | 1/37 |
| 0.02 | 76 | 34 | 0 | 0 | 42 | 0.55 | 0/34 |
| 0.05 | 75 | 38 | 3 | 1 | 33 | 0.45 | 1/39 |
| 0.10 | 79 | 31 | 1 | 4 | 43 | 0.60 | 4/35 |
| 0.15 | 81 | 34 | 3 | 5 | 39 | 0.54 | 5/39 |
| quantity | reported in | kind | level | resampled unit, draws |
|---|---|---|---|---|
| asymmetry | Table 5 | normal, unequal variances | 97.5% | none |
| mean cost of a landed run, temperature of the work , free energies and | Fig. 8 b, d, Table 8 | bootstrap | 90% | runs, each direction on its own; 2,000 |
| cost of one landing, heat, asymmetry and software temperature of the cycle, under the three approximations | Figs. 3 , 4 and 8 a, c; Supplementary Figs. 2 and 3 | bootstrap | 95% | runs; 2,000 |
| crossing of the two work distributions | § 2.5 | bootstrap | 90% | runs, each direction on its own; 1,000 |
| trapped share and landing rates | Fig. 7 | bootstrap | 90% | runs of a condition; 4,000 |
| bound on the relative entropy of a run and its reverse | § 2.3 | bootstrap | 95% | runs kept out of the fit |
Coding Agents
Coding agents use language models, tools, and feedback to modify software and complete engineering tasks.
See all 164 papers