CodeSkill: Latent Skill Abstraction for Long-Horizon Code Agents

Song-Li Wu, Jingyi Wang, Zhaocheng Du, Weinan Gan, Weiwen LiuarXiv 2026

TL;DR

CodeSkill is a novel framework that shifts reinforcement learning (RL) for code agents from fine-grained token-level optimization to high-level latent skill abstraction. By distilling complex interaction trajectories into a hierarchical latent space, it enables agents to reason about multi-step procedural behaviors, leading to a 45% reduction in interaction steps and state-of-the-art performance across general and industrial coding benchmarks.

What Problem Does This Paper Address?

Building autonomous code agents is difficult because software engineering is a "long-horizon" task. An agent might need to perform hundreds of actions—editing files, running tests, and tracing dependencies—before receiving a single reward (e.g., a passing unit test).

Existing RL approaches typically optimize at the token level. This creates a massive mismatch: the agent is trying to learn high-level behavioral reasoning (like "refactor this module") by tweaking individual characters. This leads to two major issues:

  1. Inefficient Exploration: The search space of possible token sequences is astronomical.
  2. Weak Credit Assignment: When a long trajectory fails, it’s nearly impossible to tell which specific token caused the error.

Furthermore, flat trajectory modeling fails to capture reusable patterns. A "debugging loop" looks similar across different projects, but token-level representations are too noisy to allow the agent to reuse that experience effectively.

Methods

CodeSkill introduces a two-stage framework to move beyond token-level reasoning:

1. Skill Discovery (Hierarchical VAE)

Instead of looking at raw code, CodeSkill uses a teacher model to distill trajectories into a three-level hierarchy of textual abstractions:

  • High-level: Global intent/goal.
  • Mid-level: Execution skills (temporally extended subtasks).
  • Low-level: Token control.

To bridge the gap between discrete text and continuous RL, they use a Hierarchical Variational Autoencoder (VAE). This "Skill Weaver" maps these textual descriptions into a continuous latent space ($z_t$), providing a semantically grounded prior for the agent.

Figure 2: Overview of the CodeSkill framework. We present a two-stage framework for code agents: (1) Skill Discovery: A hierarchical VAE distills offline expert trajectories into a multi-level skill bank; (2) Skill Evolution: A planning-execution loop with RL refines skills based on environment feedback.

2. Skill Evolution (Reinforcement Learning)

The agent is then trained using Proximal Policy Optimization (PPO) in this latent space. Crucially, they introduce an adaptive boundary mechanism: skill transitions are not fixed but are gated by environment feedback (like interpreter errors).

The framework also leverages counterfactual skills extracted from failed trajectories. By learning what went wrong in a failed rollout and what the "corrected" skill should have been, the agent receives a much stronger supervisory signal than simple binary success/failure.

Datasets

The authors evaluated CodeSkill against a massive battery of benchmarks:

  • General Coding: HumanEval, MBPP, EvalPlus, BigCodeBench, and FullStackBench.
  • Agentic & Tool Use: Terminal-Bench (v1 & v2), SWE-bench (Verified and Lite), Mind2Web, and BFCL V3.
  • Industrial Domains: Specialized benchmarks for Chip Design (VeriScope, RealBench), GPU Optimization (TritonBench, KernelBench), and 3D Modeling (CAD-Coder).

For training, they utilized the SWE-Smith dataset for supervised fine-tuning and the daVinci-Dev dataset for RL.

Key Insights and Ideas

  • Latent vs. Discrete: Unlike previous "skill library" approaches that treat skills as discrete, symbolic units, CodeSkill uses a continuous latent space. This allows the model to capture the continuity and compositionality of behaviors, making joint optimization much smoother.
  • Learning from Failure is Critical: The inclusion of failed trajectories ($T^-$) in the training set, paired with counterfactual skill extraction, was a major stabilizer for long-horizon RL.
  • Pruning the Search Space: By operating at the skill level, the agent effectively "chunks" its decision-making. As shown in the training curves, this leads to significantly lower exploration entropy and faster reward convergence compared to vanilla RL.
Figure 1: (a) CodeSkill pipeline overview. CodeSkill distills reusable skills from trajectories into a skill library, enabling efficient evolution of code agents, unlike vanilla training that directly learns from raw experience. (b) Training comparison with Qwen2.5-Coder-32B-Instruct backbone. All runs use fixed seeds, repeated three times with std-based confidence intervals; rewards are normalized to identical scales. Vanilla RL refers to skill-free Proximal Policy Optimization (PPO). Curves are averaged over general and industrial code benchmarks. CodeSkill delivers faster reward convergence and lower exploration entropy, validating skill abstraction improves sample efficiency.

Key Results

CodeSkill, built on a 32B backbone, consistently outperformed much larger models and specialized baselines:

  • Efficiency: Agents equipped with the skill library saw a 45% reduction in the average number of steps required to solve a task (from 12.3 steps down to 6.8).
  • Success Rate: Under a strict 15-step interaction limit, the success rate jumped from 62% to 94%.
  • State-of-the-Art: On SWE-bench Verified, CodeSkill achieved a resolve rate of 58.7%, significantly outperforming its base model (37.7%) and other open-weight competitors.
  • Industrial Generalization: The model showed remarkable transferability, leading the pack in complex hardware-aware tasks like Verilog generation for chip design and writing efficient GPU kernels.

Limitations and Future Work

  • Teacher Dependency: The initial skill discovery phase relies on a teacher model to generate textual abstractions. If the teacher is biased or misses certain patterns, the latent space may be suboptimal.
  • Fixed Hierarchy: The three-level hierarchy (Goal/Execution/Token) is predefined. Future work could explore dynamic hierarchy discovery, where the agent learns the optimal number of abstraction levels for a given domain.
  • Computational Overhead: While inference is efficient, the two-stage training process (VAE distillation followed by RL) is more complex than standard fine-tuning.

Summary updated

BibTeX
@misc{wu2026codeskill,
  author = {Song-Li Wu and Jingyi Wang and Zhaocheng Du and Weinan Gan and Weiwen Liu},
  title = {{CodeSkill: Latent Skill Abstraction for Long-Horizon Code Agents}},
  year = {2026},
  eprint = {2609.33243},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.33243},
}
Figure