Large Language Models (LLMs) are increasingly being used as "brains" for embodied agents, but they face a major bottleneck: prompt bloat. When an agent interacts with an environment, every observation is converted to text and appended to a history. These histories quickly become long, redundant, and verbose, exhausting the model's context window and drowning out important signals in a sea of "no-op" information.
In their paper "diff History for Neural Language Agents," researchers propose a surprisingly simple solution: use the classic Unix diff command to summarize what changed between observations.
TL;DR
By replacing full-text environment observations with symbolic "deltas" generated by the Unix diff command, the authors created diff history. This simple abstraction allows LLM agents to match state-of-the-art performance on the complex game NetHack while requiring 1800x fewer training examples than previous methods.
What Problem Does This Paper Address?
LLM-based controllers struggle with sequential decision-making in complex environments. The standard approach is to feed the model a "full-text history" of every observation and action.
However, in high-dimensional environments, observations are huge. If an agent moves one step to the right in a dungeon, 99% of the text describing the room remains the same. Re-sending that 99% at every timestep is computationally expensive and makes it harder for the model to "see" the 1% that actually matters for the next decision. This limits agents to simple domains with small observation sizes or very short memory horizons.
Methods: Introducing diff History
Instead of a sequence of full observations $(o_1, o_2, ..., o_n)$, the authors provide the model with:
- An Anchor: The first full-text observation ($o_1$).
- Deltas: A sequence of changes ($\Delta o_t$) computed using the standard Unix
diffutility between consecutive timesteps.
Why diff?
* Task-Agnostic: It doesn't care if the text describes a robot arm or a dungeon crawler; it just finds the changed lines.
* Relational Abstraction: It naturally highlights movement and state changes (e.g., a line starting with - showing an old position and + showing a new one).
* Compression: In complex environments like NetHack, it reduces the average token count per timestep by 460%, effectively extending the agent's "memory" within a fixed context window.
The researchers finetuned a relatively small GPT-2 (127M parameters) model using these diff prompts to predict the next expert action.
Datasets
The study evaluates the method on two procedurally generated environments:
- BabyAI-Text: A low-dimensional grid-world where agents perform tasks like "go to the red ball."
- NetHack (LangHack): The authors introduced a new dataset called LangHack. NetHack is a notoriously difficult, "unsolved" roguelike game. They used a symbolic bot to generate 500,000 interaction "chunks" and converted the game's ASCII/binary state into natural language descriptions.
Key Insights and Ideas
- The "Aha!" Moment on Efficiency: The most striking finding is that the representation of the data matters more than the amount of data. By focusing on changes, the model learns the underlying logic of the environment much faster.
- Soft Compression vs. Prompt Length: Interestingly, in the simple BabyAI environment,
diffactually made prompts longer because the observations were already tiny. Yet, even there, thediffrepresentation provided a 25% improvement in training efficiency, suggesting that the "delta" format is a fundamentally better learning signal for LMs. - Symbolic but Human-Readable: Unlike learned latent embeddings,
diffoutputs are symbolic and human-interpretable. This makes it easy for researchers to inspect what the model is "seeing" at any given timestep.
Key Results
- NetHack Performance: Agents using
diff historyachieved a mean score of 1885, matching the performance of state-of-the-art vision-based agents. Crucially, they did this with 1800x less data than those prior models. - Ablation Impact: When the authors removed the
diffobservations and used full-text history instead, the agent's score on NetHack plummeted by 98%. - Scaling: The method scales beautifully. Doubling the training data led to a 47% increase in the mean NetHack score, suggesting that even better performance is possible with more compute.
Limitations and Future Work
- Structured Text Dependency: The method assumes that environment observations can be converted into a consistent, line-based text format. It might struggle with purely "narrative" or unstructured text where
diffmight not produce meaningful deltas. - Reactive vs. Planning: The current model is a "policy" that predicts the next action; it doesn't have an explicit "System 2" planning component. The authors suggest that combining
diff historywith world models or explicit planning is a promising next step. - The "Anchor" Problem: Currently, they use the very first observation as an anchor. In extremely long-horizon tasks, they may need a strategy for "re-anchoring" to prevent the delta chain from becoming too detached from the current state.
Summary updated