Reusable skills allow large language model agents to package task-specific procedures, tool affordances, and execution guidance into modular units. Prior work has largely studied how agents retrieve, compose, or synthesize skills before execution. In coding agents, however, execution poses an additional runtime control problem: the same task may be solved through primitive tool calls, macro skills, or hybrid execution that starts with a macro and falls back to micro-level recovery. We introduce Adaptive Skill Granularity, a framework that treats skill granularity as an action-abstraction policy conditioned on task structure, execution state, and macro-skill failures. The system combines a feature-based granularity controller and a finite-state recovery executor. We evaluate the framework with a deterministic coding-agent protocol using verifier-defined success, total cost, and process metrics such as macro adoption, failure recovery, route match, and transition correctness. Results show that fixed macro execution is efficient when applicable but brittle under mismatch, while runtime routing and explicit macro-to-micro recovery improve robustness and recover controlled macro failures that fixed-granularity execution leaves unresolved. Our findings suggest that skill libraries for coding agents should be treated not only as retrievable resources, but also as controllable, verifiable, and recoverable execution abstractions.
Figures & tables
Figure 1: Adaptive Skill Granularity framework. Online execution selects and applies a micro, macro, or hybrid granularity mode, then validates the final workspace. Offline logs support router updates, confidence reporting, and macro-skill registry decisions.
Figure 2: Finite-state recovery executor. Macro runs downgrade to micro tools after recoverable failures when recovery is enabled; otherwise they terminate with macro_failure_no_recovery . Success requires verifier acceptance.
Family
Target count
Purpose
Simple
20
Single-file bugs, documentation examples, and configuration fixes.
Medium
20
Multi-file changes with moderate dependency structure.
Refactor
20
Module moves, symbol renames, import rewrites, and API migration.
Recovery
20
Macro failure, partial execution contamination, and downgrade recovery.
Table 1: GranBench-Code task families
Variant
Success
Mean Steps
Mean Tokens
Macro Adoption
G-score
A-Micro
1.000
6.00
7217.75
0.000
0.1667
B-Macro
0.583
2.71
3609.00
0.916
0.4305
C-Heuristic
0.750
3.22
4097.67
0.833
0.4103
Table 2: Fixed-granularity and heuristic routing results (12 mixed tasks). Pure micro is robust but costly, while pure macro is efficient but brittle.
Fault Mode
Variant
Success
Mean Steps
Mean Tokens
Transition Rate
Before
C-Heuristic-NoRecovery
0.000
-
-
0.000
Before
E-FSM-Downgrade
1.000
6.86
11293.43
1.000
After
C-Heuristic-NoRecovery
1.000
2.71
2440.14
0.000
After
E-FSM-Downgrade
1.000
5.71
7566.71
1.000
Table 3: Dynamic downgrade under injected macro failures (7 tasks). The FSM downgrade recovers early failures perfectly but wastes tokens on late failures.
Variant
Success
Mean Steps
Mean Tokens
Heuristic Match
Emp. Match
C-Heuristic-ModeOnly
0.750
3.11
4172.89
1.000
0.667
D-Learned-ModeOnly
1.000
4.17
5518.33
0.667
1.000
Table 4: Learned vs. Heuristic mode routing (12 tasks). Aligning with empirical labels allows the learned router to achieve 100% success where the heuristic fails.
Fault Mode
Variant
Success
Mean Tokens
G-score
Transition Rate
Before
C-Heuristic-NoRecovery
0.000
-
-
0.000
Before
E-FSM-Downgrade
1.000
11293.43
0.0845
1.000
Before
F-Learned-Full
1.000
9763.57
0.1061
0.857
After
C-Heuristic-NoRecovery
1.000
2280.00
1.1866
0.000
After
E-FSM-Downgrade
1.000
7566.71
0.2142
1.000
After
F-Learned-Full
1.000
3694.43
0.5720
0.143
Table 5: Full end-to-end routing under fault injection (7 tasks). The learned full controller preserves perfect recovery success while significantly reducing token cost.
Figure 3: Evaluation outcome breakdown. Bars separate micro success, macro success, hybrid-recovery success, and terminal failure.