Up and Down the Abstraction Ladder: Code-Based Skills for Language Agents
Organizations: University of Warsaw · AKCES NCBR · Princeton University · IDEAS NCBR ·
Abstract
Language agents struggle to act and learn in environments that require long sequences of low-level actions. Code-based abstractions can make these agents more productive by letting them invoke reusable skills instead of repeatedly selecting individual actions. The code handles recurring local decisions, while the language model decides which skills to use and how to combine them. Yet abstractions are leaky, and situations beyond a skill's capabilities may require a return to primitive actions. Motivated by this tradeoff between productivity and flexibility, we systematically study how code-based action abstraction affects the performance, inference cost, and learning of language agents. We study this in NetHack, a challenging, long-horizon game environment, using CodeHack, our library of code-based skills with natural-language descriptions. We use this library to compare agents restricted to primitives with those using semantic skills alone or in combination with primitives. We evaluate these agents in three settings: zero-shot prompting, supervised fine-tuning, and reinforcement learning. Across a broad zero-shot evaluation on NetHack, we find that compared with primitives, skills nearly triple game progression, while reducing inference cost per episode by 86%. Combining skills with primitives retains much of this benefit while preserving a path back down to low-level actions. Finally, in RL, we find that skill-based agents learn significantly faster than agents acting on primitives, achieving a 7.2x larger average gain in dungeon level over the same training budget. These results show that a supplied skill library can improve performance, efficiency, and learning, while retaining primitives provides flexibility when the library is insufficient. We release CodeHack together with training and evaluation code.
Figures & tables
| Regime | Interface | Model | Score | Progression | Dungeon Level |
| Zero-shot | Primitives | Llama-3.1-8B-Instruct | 22.0 2.9 | 0.12 0.05 | 1.08 0.03 |
| Primitives | Qwen-3.5-4B | 36.3 6.5 | 0.29 0.08 | 1.17 0.06 | |
| Mixed | Llama-3.1-8B-Instruct | 78.6 8.0 | 0.90 0.11 | 1.48 0.08 | |
| Mixed | Qwen-3.5-4B | 92.0 11.1 | 0.94 0.11 | 1.81 0.12 | |
| Skills | Llama-3.1-8B-Instruct | 178.4 15.5 | 1.59 0.10 | 2.48 0.15 | |
| Skills | Qwen-3.5-4B | 215.9 22.1 | 1.49 0.13 | 2.45 0.18 |
Appendix figures & tables28 assets
Supplementary material from the paper’s appendix.
Appendix
| Stage | Hyperparameter | Value |
|---|---|---|
| SFT | Teacher model | Gemma-4-31B |
| SFT | Teacher episodes | 1,024 zero-shot episodes |
| SFT | Trainable parameters | LoRA adapter only |
| SFT | LoRA rank / alpha / dropout | 128 / 64 / 0.0 |
| SFT | Learning rate | |
| SFT | Local minibatch size | 64 |
| Model | Action | Progression | Score | Dlvl | L2 | L4 | L6 | L8 | Oracle | Mines | Cost/ep. ($) | Tokens/ep. |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GPT-5 | skills | 4.64 0.38 | 1279.29 151.62 | 5.73 0.29 | 0.94 0.03 | 0.84 0.05 | 0.54 0.06 | 0.25 0.06 | 0.06 0.03 | 0.47 0.06 | 6.44 | 2,007,700 |
| mixed | 3.99 0.54 | 922.84 179.63 | 5.25 0.42 | 0.94 0.04 | 0.78 0.07 | 0.38 0.09 | 0.22 0.07 | 0.06 0.04 | 0.53 0.09 | 14.88 | 5,196,745 | |
| primitives | 1.78 0.13 | 232.56 22.59 | 1.50 0.14 | 0.34 0.09 | 0.03 0.03 | 0.00 0.00 | 0.00 0.00 | 0.00 0.00 | 0.03 0.03 | 50.41 | 13,866,723 | |
| GPT-OSS-120B | skills | 2.88 0.17 | 447.72 39.81 | 4.06 0.23 | 0.95 0.03 | 0.61 0.06 | 0.22 0.05 | 0.05 0.03 | 0.03 0.02 | 0.45 0.06 | 0.06 | 1,176,438 |
| mixed | 3.17 0.22 | 495.48 41.31 | 4.47 0.25 | 0.95 0.03 | 0.67 0.06 | 0.33 0.06 | 0.06 0.03 | 0.05 0.03 | 0.36 0.06 | 0.21 | 4,151,999 | |
| primitives | 1.39 0.11 | 152.97 14.46 | 1.28 0.08 | 0.20 0.05 | 0.02 0.02 | 0.00 0.00 | 0.00 0.00 | 0.00 0.00 | 0.00 0.00 | 0.63 | 10,399,676 |
| Metric | Primitives avg | Skills avg | Skills / primitives | % change |
|---|---|---|---|---|
| Progression (%) | 0.690 0.164 | 1.978 0.325 | 2.866 | +187% |
| Score | 83.948 20.157 | 318.268 89.226 | 3.791 | +279% |
| Max DLvl | 1.188 0.052 | 2.880 0.340 | 2.425 | +143% |
| L2 reach | 0.133 0.032 | 0.719 0.062 | 5.411 | +441% |
| L4 reach | 0.013 0.005 | 0.286 0.068 | 21.320 | +2032% |
| L6 reach | 0.001 0.001 | 0.117 0.043 | 104.540 | +10354% |
| Example | Skill limitation | Primitive fallback | Return to skills |
|---|---|---|---|
| Ranged combat | 732: fight_ranged reports no ranged weapon or ammunition and executes zero environment steps. | 733–735: throw , i , east select a javelin and kill the gas spore. 736–739: east moves to the dropped weapons. | 740: pickup_weapon recovers the weapons. |
| Vault guard | 480: explore executes zero environment steps. 483: the guard repeats its demand to drop the gold; no drop-gold skill is available. | 484–485: drop , $ drop all 650 gold pieces. 486–487: east follows the corridor. | 488: explore resumes navigation. |
Long-Horizon LLM Agents
Long-horizon large language model agents plan, use tools, and preserve task state across extended, multi-step interactions.
See all 443 papers