Where the Tokens Go: Heat, Entropy and Error in Agentic Coding

Alán Aspuru-Guzik, Varinia BernalesarXiv 2026 · arXiv

TL;DR

This paper introduces software thermodynamics, a novel framework that treats LLM tokens as physical fuel to quantify the efficiency of coding agents. By applying principles from stochastic thermodynamics, the authors demonstrate that roughly 80% of tokens in a successful coding task are "heat" (overhead like reading and testing), while only 14-22% represent the "free energy" or minimum work required for the change.

What Problem Does This Paper Address?

As AI coding agents become ubiquitous, we are increasingly "billed by the token," yet software engineering lacks a formal theory to explain what a token actually buys. We measure code by correctness and coverage, but we have no instrument to measure the efficiency of the agentic process itself.

The authors address this gap by drawing a direct analogy between agentic coding and classical thermodynamics. In their model:

  • Tokens are the fuel/energy.
  • The Repository is the system being acted upon.
  • The Test Suite acts as a Maxwell’s Daemon, a gatekeeper that decides which "molecules" (code changes) are allowed to pass into the final state.

The goal is to provide a predictive theory that helps engineers understand where tokens are "wasted" and how to optimize agent harnesses.

Methods

The researchers conducted an experiment inspired by single-molecule biophysics (pulling an RNA hairpin open and letting it refold). They tasked an agent (deepseek-v4.1-flash) with a "cycle" of coding:

  1. Coding (Forward): Make a specific change to a repository (e.g., renaming a module).
  2. Uncoding (Reverse): Undo that exact change to return the repository to its original state.

They measured the Work ($W$)—tokens spent on turns that actually moved the "reaction coordinate" (the fraction of target edits in place)—and the Heat ($h$)—tokens spent on turns that left the state unchanged (reading files, searching, running tests).

Figure 1. The three experiments described in this article, shown schematically. In every panel the forward direction is drawn in rose and the reverse direction in black. (A) Carnot’s engine. A Maxwell daemon moves the piston, so that the gas expands and is then compressed. The cycle has two isotherms (solid) and two adiabats (dashed), and the area that they enclose is the work delivered. (B) The pulling of a single molecule. A Maxwell daemon holds optical tweezers and pulls an RNA molecule with their optical trap. Moving the trap away unfolds the molecule, and moving it back lets the molecule refold [4]. The force against the extension differs from one repetition to the next, and the shaded area under the refolding curve is the work that the molecule returns as it refolds. (C) Coding and uncoding (this work). An agent changes a repository (coding, forward) and then undoes the change (uncoding, reverse). The gate daemon stands for the test suite and judges every change. The plot shows the output tokens that three runs in each direction had spent after each turn. Both directions cost tokens.

Crucially, they distinguished between two types of temperature:

  • Hinton Temperature ($T_H$): The standard LLM sampling parameter.
  • Software Temperature ($1/\beta$): A measured value derived from the variance of token costs across many runs, representing the "exchange rate" between tokens and information.

Datasets

The study used a private Python codebase consisting of several hundred modules. They evaluated two specific tasks:

  • Task A: Renaming a module responsible for backgrounding long-running test checks.
  • Task B: Renaming a module that guards software deployments.
  • Toy System: A simplified environment with a hidden defect used specifically to measure the error rates and "temperature" of the test suite (the gate).

Key Insights and Ideas

  • The 80/20 Rule of Tokens: In a successful run, about 80% of tokens are "heat." This isn't necessarily pure waste; it is the thermodynamic price the agent pays to acquire the information it needs to act.
  • Coding is Harder than Uncoding: The "asymmetry" of the cycle showed that making a change costs 1.1 to 1.5 times more than undoing it. This suggests that "building" creates more entropy/dissipation than "destroying" in the context of code.
  • Cold Agents Get Stuck: At low sampling temperatures ($T_H \le 0.25$), agents frequently fall into "metastable states"—infinite loops where they repeat the same search command, burning tokens without making any edits.
  • The "Hot" Test Suite: A flaky test suite acts like a "hot" Maxwell's Daemon. If the gate is "hotter" than the agent (noisier), it cannot effectively extract disorder from the system, leading to "false landings" where broken code is accepted.

Key Results

  • Efficiency: The "free energy" (minimum possible cost) of a change was estimated to be only 14% to 22% of the mean cost of a successful run.
  • Token Dissipation: On Task A at a Hinton temperature of 0.5, a landed run cost ~2,300 tokens: ~1,900 were heat and ~400 were work. The estimated free energy was only 351 tokens.
  • Looping Costs: In cold conditions, unfinished runs (those that got stuck in loops) accounted for 66% of all tokens generated across the entire experiment.
  • Gate Temperature: When the test suite was intentionally made "noisy" (error rate of 0.10), its software temperature was 3 to 16 times higher than the model's temperature, significantly degrading its ability to catch defects.

Limitations and Future Work

The authors acknowledge that this is currently an analogy rather than a proven physical law. LLMs have "memory" and do not start from true thermal equilibrium, which complicates the application of theorems like Jarzynski’s equality.

Future directions include: * Testing if "free energy" is a true state function (independent of the path taken to change the code). * Applying the theory to larger, non-reversible changes (e.g., adding new features). * Studying swarms of agents and agents with persistent memory systems. * Developing "thermodynamic" debugging tools that automatically detect when an agent is "overheated" (wasting tokens) or "stuck" in a metastable loop.

Summary updated

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.
BibTeX
@misc{aspuruguzik2026where,
  author = {Alán Aspuru-Guzik and Varinia Bernales},
  title = {{Where the Tokens Go: Heat, Entropy and Error in Agentic Coding}},
  year = {2026},
  eprint = {2611.23375},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.23375},
}
Figure