Loop-Driven Agentic Behavior Distillation: Teaching Small Language Models to Self-Correct from Their Own Failures

Moaz Eldegwy ยท additional authors to be announced

The Faculty of Computer Studies (FCS), Arab Open University (AOU)

๐Ÿ”’ Code and artifacts will be made public upon publication.

Abstract

Small and mid-scale language models frequently fail to revise an incorrect first attempt. Prompting-based self-correction presupposes a latent self-critique ability that these models often do not possess, while reinforcement learning applied directly at small scale tends to be unstable.

We present Loop-Driven Agentic Behavior Distillation (LABD), a two-stage post-training procedure that treats self-correction as a behavior to be taught rather than an ability to be elicited. In the first stage, each student model operates inside a closed execution loop and generates complete agent trajectories consisting of reasoning, execution, feedback, and, when necessary, recovery. Some trajectories succeed immediately, while others require one or more repair steps. A stronger teacher, conditioned as the author of the trajectory, intervenes only when recovery is needed and produces corrected actions under sandbox feedback. The resulting execution-grounded trajectories are then distilled back into the same model through supervised fine-tuning. In the second stage, Group Relative Policy Optimization (GRPO) grounds the learned behavior using execution-based rewards.

Evaluating four Qwen3 sizes (0.6Bโ€“8B) on MBPP and HumanEval under an iterative execution-feedback protocol, we find that the agentic loop produces a net improvement over single-pass generation at every scale, with third-iteration gains over the base model of approximately +10 to +20 percentage points (pp) on MBPP and +5 to +25 pp on HumanEval. Recovery from failure tends to increase with model capacity rather than appearing only beyond a fixed size, and the additional inference cost of the loop is modest (ร—1.08โ€“ร—1.38 in generated tokens). All training was performed on a single mid-range GPU using a few hundred distilled trajectories per model. These results indicate that self-correction in small models is best obtained by teaching the behavior directly from a model's own failures, rather than by prompting for it or discovering it through reinforcement learning alone.

Methodology Overview

Methodology Overview: Thought, Execute, Feedback, Repair

Figure 1: The LABD Framework โ€” Turning Failure into Signal. (A) A student attempts a task and fails, producing an error trace. (B) A teacher, conditioned as the author of the failed attempt, repairs the code using execution feedback. (C) The corrected trajectory is distilled back into the same student, teaching it how to recover. (D) GRPO then grounds this learned behavior using execution-based rewards.

Results

Models are evaluated as autonomous self-correcting agents under a closed-loop protocol: THOUGHT โ†’ EXECUTE โ†’ FEEDBACK โ†’ REPAIR. Base is single-pass; LABD and LABD+GRPO are evaluated in the agentic loop (up to three iterations). Δbase = Iter-3 โˆ’ Base; CR is the Correction Rate (Eq. 3).

Model MBPP HumanEval
Base Iter-1 Iter-3 Δbase CR (%) Base Iter-1 Iter-3 Δbase CR (%)
Full results will be released upon publication.

Model Zoo

All eight models are fine-tuned from Qwen3 base checkpoints โ€” four with LABD SFT and four with LABD SFT followed by GRPO. They will be released on Hugging Face upon publication.

Model Parameters Link
Qwen3-0.6B + LABD 0.6B ๐Ÿค— View on HF
Qwen3-0.6B + LABD+GRPO 0.6B ๐Ÿค— View on HF
Qwen3-1.7B + LABD 1.7B ๐Ÿค— View on HF
Qwen3-1.7B + LABD+GRPO 1.7B ๐Ÿค— View on HF
Qwen3-4B + LABD 4B ๐Ÿค— View on HF
Qwen3-4B + LABD+GRPO 4B ๐Ÿค— View on HF
Qwen3-8B + LABD 8B ๐Ÿค— View on HF
Qwen3-8B + LABD+GRPO 8B ๐Ÿค— View on HF

โ†’ View the collection on Hugging Face

Citation

Publicly available upon publication