Up and Down the Abstraction Ladder: Code-Based Skills for Language Agents

Bartłomiej Cupiał, Jens Tuyls, Maciej Wołczyk, Davide Paglieri, Martin Klissarov, Benjamin Eysenbach, Piotr Miłoś, Karthik R. NarasimhanarXiv 2026

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.

Figure 2: CodeHack as a shared control layer for primitive-only, skill-only, and mixed agents. 1. The controller can be either a language-model agent or a learned RL policy, since CodeHack supports both natural-language control and a discrete action-space interface. 2. Depending on the configured action interface, the controller selects code skills such as explore or fight_melee, primitive commands such as movement, kick, or search, or both. 3. All three interfaces use the same runtime for symbolic state, inventory tracking, map memory, panic handlers, and no-progress feedback. Primitive commands are registered as one-step strategies. Code skills can expand into multiple primitives. 4. This runtime supports both NetHack and MiniHack, allowing the same skill library to transfer across environments while preserving a path back to low-level control when abstractions are insufficient.

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 explore or fight_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):

  1. MiniHack: A suite of controlled, smaller tasks used to isolate specific behaviors like navigation, combat, and item usage.
  2. 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.
Learning curves show that skill-based agents (green) learn significantly faster than those restricted to primitives (blue).

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.
Figure 4: Zero-shot NetHack cost-performance frontier. Each point represents a model evaluated with a particular action interface, showing its average dungeon level reached against its average inference cost per episode. For most models, switching from primitives to skills increases dungeon depth while reducing inference cost.
  • 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

BibTeX
@misc{cupia2026up,
  author = {Bartłomiej Cupiał and Jens Tuyls and Maciej Wołczyk and Davide Paglieri and Martin Klissarov and Benjamin Eysenbach and Piotr Miłoś and Karthik R. Narasimhan},
  title = {{Up and Down the Abstraction Ladder: Code-Based Skills for Language Agents}},
  year = {2026},
  eprint = {2609.31076},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.31076},
}
Figure