TL;DR
This paper introduces CodeHack, a library of code-based skills that allows language agents to operate at higher levels of temporal abstraction in the notoriously difficult game of NetHack. By enabling agents to move "up and down the abstraction ladder"—switching between high-level code routines and low-level primitive actions—the authors demonstrate a 3x improvement in game progression, an 86% reduction in inference costs, and up to 8.6x faster learning in reinforcement learning settings.
What Problem Does This Paper Address?
Language models (LMs) are increasingly used as autonomous agents, but they struggle in environments that require long-horizon planning and thousands of low-level actions (like mouse clicks or keystrokes). Chaining these "primitives" is computationally expensive and difficult for models to learn.
While high-level abstractions (skills) can make agents more productive, these abstractions are often "leaky." A fixed library of skills can never anticipate every edge case in a complex environment. If an agent is restricted only to high-level skills, it may get stuck when a situation falls outside its library's capabilities. The authors tackle this trade-off between productivity (using skills) and flexibility (using primitives).
Methods
The researchers developed CodeHack, a framework that sits between the agent (the "controller") and the environment.
Key components include:
- The Abstraction Ladder: A hierarchy where the top level is planning (choosing skills), the middle level consists of code-based skills (Python functions like
exploreorfight_melee), and the bottom level is raw environment actions. - Code-Based Skills: Unlike "latent" skills learned by a neural network, these are human-readable Python procedures. They handle local decision-making (e.g., pathfinding to a room) while the LM decides which skill to invoke.
- Mixed Control: A novel interface that allows the agent to choose either a high-level skill or a primitive action at any step.
- Panic Handlers: A safety mechanism that interrupts a long-running code skill if the environment state changes dangerously (e.g., the agent loses health or a new monster appears), handing control back to the LM.
Datasets
The study uses two primary environments based on the NetHack Learning Environment (NLE):
- MiniHack: A suite of controlled, smaller tasks used to isolate specific behaviors like navigation, combat, and item usage.
- NetHack: The full, procedurally generated roguelike game, serving as the primary benchmark for long-horizon evaluation and reinforcement learning.
Key Insights and Ideas
- Abstractions are a Pareto Improvement: For almost every model tested, switching from primitives to skills moved the agent to a better "performance-cost frontier." Agents reached deeper dungeon levels while spending significantly less on API tokens.
- The "Leaky" Abstraction Fallback: The paper provides qualitative evidence that "mixed control" is essential. When a skill fails (e.g., the library lacks a specific command to drop gold for a guard), the agent can descend the ladder, perform the primitive actions manually, and then return to high-level exploration.
- RL Scaling: Skills don't just help zero-shot performance; they radically change the feasibility of Reinforcement Learning. By reducing the number of decisions the RL policy needs to make, the agent explores the state space much more effectively.
Key Results
- Zero-Shot Efficiency: Across 14 different LMs, using skills nearly tripled game progression and reduced inference costs per episode by 86% compared to primitive-only control.
- Cost-Performance: As shown in the frontier plot, skill-based models consistently outperform primitive-based models even when the primitive models are much larger and more expensive.
- RL Acceleration: In reinforcement learning experiments, skill-based agents achieved a 7.2x larger average gain in dungeon level over the same training budget compared to primitive-only agents. Mixed-control agents performed even better, with an 8.6x gain.
- MiniHack Success: On every MiniHack task, skills improved success rates, with an average gain of 55 percentage points over primitive control.
Limitations and Future Work
The primary limitation is that the CodeHack library is hand-designed and incomplete. While it covers frequent behaviors, it cannot solve NetHack entirely. The authors suggest that a promising future direction is automated skill construction, where the agent identifies its own failures and writes new Python code to expand its own abstraction ladder. Additionally, the "routing problem"—deciding exactly when to move between abstraction levels—remains an open challenge for agentic reasoning.
Summary updated