betaFeedback

WorksComputer Science

DeLoop: Repeated Actions as Self-Supervision for Long-Horizon Agents

Abstract

Language-model agents that run long tasks often redo work they have already done: they re-issue a tool call they made earlier and get back exactly the same observation, a step that adds no new information. We identify this failure as a loop. Loops appear natively in Qwen, Llama, and Gemini agents and become far more common once the agent's history is compressed to fit its context window. To reduce these loops, we propose DeLoop, a self-supervised training method. DeLoop builds on a simple observation: the agent's own rollout can provide the supervision needed to learn from its loops. We use a looping action as a negative example and the first later non-looping action in the same rollout as a positive example. DeLoop learns from these pairs through direct preference optimization and does not require task rewards, gold answers, or LLM judges. On CodeGym under compression, DeLoop reduces the share of Qwen3-8B tasks containing loops from 57.3% to 6.1%. It also uses about one third as many steps per task, with similar task success. On Qwen3-32B, DeLoop reduces loops and steps while raising task success from 37.7% to 44.8%.

Introduction

Language-model agents increasingly solve tasks over long interaction horizons: they inspect repositories, execute commands, call tools, and act on environment feedback across many steps (Du et al., 2025; Jimenez et al., 2024; Yang et al., 2024a; Yao et al., 2023). Yet they often redo work they have already done. The agent calls the same tool with the same arguments, receives the same observation, and then issues the same call again (Figure 1). Each repeated call is a looping action: it gets back an observation the agent already has and adds no new information. We formulate this failure as a loop.

Figure 1. Training an agent on its own loops breaks the loop. (Left) A repeated search and the later action that marks the server as visited form a preference pair. DPO trains the agent to prefer the recovery. (Right) Qwen3-8B on CodeGym: DeLoop and the baseline summarize at 4,096 tokens; full history is the uncompressed reference.

The failure is already present even when the full, uncompressed history is available, but compression makes it worse. On CodeGym (Du et al., 2025), the loop rate of Qwen3-8B (Yang et al., 2025), the share of tasks with at least one loop, rises from 29.0% with the full history (no summarization) to 57.3% under summarization, while looping actions per task increase more than 3.5×! More importantly, in addition to wasted tool calls, we empirically observed that trajectories that enter a loop fail in all six Qwen3 and Gemini models we evaluate: on average, 59.5% of looping runs fail, compared with 33.4% of loop-free runs (Figure 2). Thus, context compression makes looping more likely and increases the chances of task failure.

Figure 2. Failure rates of looping and loop-free runs. Task-failure rate for runs with a loop (red) and without one (gray), for Qwen3-8B, Qwen3-14B, and four Gemini models in their compressed settings. Detector details: Appendix § 11.

Recent work manages growing interaction histories through external memory (Fox et al., 2026; Packer et al., 2023), hierarchical or summarized working context (Hu et al., 2025; Sun et al., 2026; Wu et al., 2025), compact learned state (Zhou et al., 2025), and learned context compression or management (Kang et al., 2026; Liu et al., 2025; Lu et al., 2026). These works study what history should an agent retain to continue acting well under a bounded context window. In contrast, we study a complementary question about how the agent’s policy uses its history after compression. That is, when the history records an action, does the agent use that record to avoid repeating it? We find that most agents do so only partly.

Another way to reduce looping is to improve the agent’s policy. Some methods address agent failures at inference time through reflection (Shinn et al., 2023) or early stopping (Lu et al., 2025). Others train agents using demonstrations ([4] (Zeng et al. 2024)), search-based training data (Yuan et al., 2025), or step-level supervision ([5] (Tang 2026; Xiong et al. 2024)). We instead ask: can the failure itself provide a useful signal to improve agent’s policy?

Based on these observations, we propose DeLoop, a self-supervised training method. Our key observation is that loops can provide their own training signal. We note that a loop is a simple trajectory-level event that can be identified directly from the action-observation trace, without requiring post-hoc failure attribution ([2] Hou et al., 2026). Within a single rollout, we pair a looping action with the first later non-looping action that differs from it. The looping action provides a natural negative, while the later action provides a positive signal. Figure 1 illustrates this. These pairs are mined directly from the interaction, without gold answers, LLM judges, external rewards, or task-success labels. We train the policy on these pairs through direct preference optimization (DPO Rafailov et al., 2023).

On Qwen3-8B, DeLoop cuts the loop rate 9.4× while lowering interaction cost, with similar task success. On Qwen3-32B, the self-mined pairs alone reduce loop rate from 38.5% to 12.9% and raise task success from 37.7% to 44.8%, while also lowering interaction cost. Adding cross-domain pairs (DeLoop-Mix) raises Qwen3-8B task success from 25.1% to 30.3%. Our contributions are:

  1. Identifying loops in long-horizon agents: we identify and characterize loops, a simple failure in which an agent repeats an earlier action and receives the same observation. We show that loops occur even with the full history, grow sharply under compression, and are associated with task failure.

  1. Mining loop actions as self-supervision: we introduce a simple mining method that turns discovered loops into preference pairs from the agent’s own rollouts, with no external supervision.

  1. Reducing loops in long-horizon agents: DeLoop reduces loops (57.3% to 6.1% on Qwen3-8B) while lowering interaction cost. The gains also extend to larger models, where there is pronounced improvement in task success (45.1% to 52.3% on Qwen3-14B and 37.7% to 44.8% on Qwen3-32B).

Related work

Repeated actions in agents. Repetition is a known failure of LLM agents. AgentBench found that agents mainly exceed their task limit because they repeat earlier content (Liu et al., 2024). MAST also lists step repetition as a failure mode of multi-agent systems (Cemri et al., [3]), and RAGEN shows that multi-turn RL can trap agents in repetitive reasoning (Wang et al., 2025b). Closest to our setting, Min et al. (2026) find that repeated context compression increases repeated exploration and improve the compression prompt to reduce it; we keep the compressor fixed and change the policy. IAL-Scan finds code paths that can run without bound (Hou et al., 2026), and other work locates agent failures in execution traces (Barke et al., [2]; Deshpande et al. [8]; Liu et al. (2026); Yeh et al. (2026); Zhang et al. (2025)). At inference time, agents can reflect, stop early, or escalate to a stronger model (He et al., 2026; Lu et al., 2025; Shinn et al., 2023). Open-Hands flags an agent as “stuck” when the same action returns the same observation four times in a row (Wang et al., 2025a). These methods do not change the agent policy. Even with a blocker that refuses repeated calls and returns their earlier result, Qwen3-8B on CodeGym still proposes an already executed call in 71.3% of tasks, as often as without the blocker (69.8%); DeLoop lowers this to 13.6% (Appendix § 16.§ 1.1). We define a loop as a repeated tool call that returns the same observation. Loops persist even with summaries designed to keep past actions (§ 2.3), so we train the agent policy itself to break the loop.

Context management. Long-horizon agents need to fit their history into a limited context. Common context management methods store the history in external memory or searchable logs ((Fox et al., 2026; Packer et al., 2023; Wang et al., 2026b)), summarize older interactions ((Hu et al., 2025; Su et al., 2026; Sun et al., 2026; Wu et al., 2025)), keep a compact learned state (Zhou et al., 2025), learn what to keep ((Kang et al., 2026; Liu et al., 2025; Lu et al., 2026)), or validate their summaries ([6]). However, removing plans from the context sharply hurts performance (Mehta and Datta, 2026). These methods decide what history to keep. We instead ask whether the agent uses the kept history to avoid repeating actions.

Learning from agent trajectories. Most methods that train agents on trajectories need an external signal to pick the better action. Agent tuning uses filtered or teacher-generated trajectories ([4] (Fu et al. 2025; Zeng et al. 2024)), or successful attempts and outcome feedback ((Guo et al., 2025; Jung et al., 2025; Le et al., 2026; Wang et al., 2024; Yang et al., 2024b; Zelikman et al., 2022)). ETO and Agentic-DPO take the better action from experts ([5] (Song et al. 2024)). Step-DPO, IPR, and Tool-Graph use step-level labels or rewards ((Lai et al., 2024; Tang, 2026; Xiong et al., 2024)). Agent-R and Agent Q use tree search guided by rewards or critiques ((Putta et al., 2024; Yuan et al., 2025)), and SCoRe trains self-correction with online RL (Kumar et al., 2025). DeLoop instead takes the better action from the agent’s own later recovery in the same rollout and trains with DPO (Rafailov et al., 2023). Its only label is the exact-repeat rule of § 2.1, so it needs no rewards, expert actions, or step labels. Like hindsight experience replay (Andrychowicz et al., 2017), it also learns from failed rollouts.

Penalizing repetition. Repetition can also be penalized directly. RLTR adds a penalty on redundant tool calls to its reward (Li et al., 2025). In text generation, penalized sampling (Keskar et al., 2019), unlikelihood training (Welleck et al., 2020), and DITTO (Xu et al., 2022) reduce repeated tokens and sentences. These penalties mark what to avoid; DeLoop also supplies the agent’s own alternative action. Using our loop flag as a per-step penalty in online RL (GRPO) lowers the Qwen3-8B loop rate on CodeGym from 57.3% to 15.0%, against 6.1% for DeLoop (§ 4.3).

Loops in Long-Horizon Agents

Defining a Loop

A loop occurs when the agent repeats a previous tool call with identical arguments and receives the same observation. Thus, that step adds no new information.

For example, consider an agent counting clusters of online servers on a grid. The agent has tools to find unvisited servers and mark them as visited. In one rollout, it issues the same search three times without marking the returned server. Because that server remains unmarked, each call returns the same coordinates. The latter two calls therefore add no new information. This rollout comes from a Qwen3-8B agent on CodeGym (Du et al., 2025), where agents solve tasks through sequences of tool calls. Appendix § 8 shows the rollout excerpt.

We detect such repetitions by comparing each tool call and its observation with earlier steps. Let ata_t denote the tool call at step tt, and oto_t its returned observation. We denote a trajectory of TT steps by hTh_T. With κ\kappa canonicalizing each tool call so that formatting differences do not count, let xt=κ(at),otx_t = \kappa(a_t), o_t denote the signature of step tt. Step tt is a repeat if its signature appeared earlier:

st={1if xt=xi for some i<t,0otherwise.s_t = \begin{cases} 1 & \text{if } x_t = x_i \text{ for some } i < t, \\ 0 & \text{otherwise.} \end{cases}

A trajectory hTh_T loops if it contains at least one repeat:

hT loops⟺st=1 for some t≤T.h_T \text{ loops} \Longleftrightarrow s_t = 1 \text{ for some } t \le T.

A step with st=1s_t = 1 is a looping action. A repeated call with a new observation is not a looping action. We then label any run containing at least one looping action as a looping run. We report the percentage of looping runs as the loop rate.

Loops Are Costly

Each looping action consumes tokens and a tool execution without yielding a new observation. Under a fixed interaction budget, these repeated calls leave fewer opportunities to take actions that could advance the task. We compare looping and loop-free Qwen3-8B runs on CodeGym under summarization at 4,096 tokens. Both groups include successful and failed runs. Looping runs contain 6.5 looping actions on average. They execute 10.5 more actions per task on average than loop-free runs. Their interaction transcripts also contain 11k more tokens. The same pattern holds for all six models in the cost comparison (Appendix Figure 7).

Within each model’s compressed setting, looping runs are also more likely to fail than loop-free runs (Figure 2). The gap appears in all six Qwen3 and Gemini models: Qwen3-8B fails 85% of looping runs against 68% of loop-free runs. Gemini 3.1 Pro shows a wider gap: 48% against 12%. A loop thus marks a run that is more likely to fail and has a higher execution cost.

Compression Makes Loops More Common

An agent’s interaction history records what it has already done. To keep long rollouts within a context budget, the agent summarizes earlier interactions (Appendix § 10). We examine whether this compression makes the agent more likely to repeat completed actions. On CodeGym, Qwen3-8B loops in 29.0% of runs with the full history. Summarization at 4,096 tokens raises the loop rate to 57.3%. Lowering the threshold to 2,048 tokens raises it further to 64.7% (Figure 3a).

Figure 3. Loop rates with and without compression. (a) Qwen3-8B on CodeGym across context settings. (b) Gemini full-history runs versus compression-triggered episodes of summarization runs.

The same pattern appears in all three Gemini models that we run with and without compression (Figure 3b). We compare CodeGym runs with the full history against the subset of summarization runs in which compression fires. Gemini 3.1 Pro loops least with the full history yet shows the largest increase, 2.9×.

To investigate this increase, we ask whether removing a completed action’s record makes the agent more likely to repeat it. We reconstruct 300 histories from 253 CodeGym tasks after compression. Each ends just before Qwen3-8B chooses its next action. One version of each history keeps the most recent completed tool call and its observation. The other removes this record. We sample the next action eight times from each version. The agent repeats that call in 3.3% of samples with the record present and 48.8% with it removed (Appendix § 12).

The record therefore helps the agent avoid an immediate repeat. This explains why compression causes more loops. However, over a whole episode, keeping the record is not enough: Qwen3-8B still loops in 29.0% of runs with the full history. Under compression, a quarter of runs (25.2%) repeat a call that is still in the context word for word (Appendix § 16.§ 1).

Better context management does not close this gap. Summaries that keep an explicit record of past actions, such as a trace of every executed call or a ledger of tried actions, still loop in 52.0% to 62.7% of runs, close to standard summarization at 57.3% (Appendix Table 4). The compressors ACON (Kang et al., 2026) and LLMlingua-2 (Pan et al., 2024) lower the loop rate to 46.3% and 46.7%, still well above the 29.0% with the full history. The agent often fails to use a record it has, so we train the policy itself (§ 3). This complements better compression: DeLoop-Mix lowers the loop rate under every memory policy we test (§ 5.1).

Repeated Actions as Self-Supervision

To reduce looping under compressed context, we propose DeLoop, preference optimization on self-mined loop pairs. A detected looping action serves as a negative example. If the same rollout later contains a different, non-looping action, the first such action serves as a positive example (Figure 4).

Figure 4. A self-mined preference pair. Abridged Qwen3-8B CodeGym rollout (tool names shortened; Appendix § 8). xx: history before the looping action; y−y^-: looping action; y+y^+: first later loop-breaking action.

Mining Preference Pairs from Loops

We run the compressed agent on training tasks and apply the structural detector of § 2.1 to each rollout. For each detected looping action ata_t, we use that action as the rejected response y−y^-. If the agent later recovers from the loop in the same rollout, we use the first action that breaks the loop as the chosen response y+y^+.

For training, we pair both actions with the history x=h<tx = h_{<t} that preceded the looping action:

x=h<t,y−=at,y+=at′,t′=min⁡{u>t:su=0, κ(au)≠κ(at)}.x = h_{<t}, \qquad y^- = a_t, \qquad y^+ = a_{t'}, \qquad t' = \min\{u > t : s_u = 0,\ \kappa(a_u) \ne\kappa(a_t)\}.

If the agent does not recover from the loop before the rollout ends, we do not construct a training pair for that looping action. A single rollout can contribute multiple pairs.

For instance, the episode in Appendix § 8 yields one of our self-mined pairs. The rejected action is the looping FindUnvisitedOnlineServer(start_row=3, start_col=0). The chosen action is the agent’s own later MarkVisited(row=3, col=0), which breaks the loop.

Such a recovery provides a training pair even if the rollout ultimately fails the task. We identify the looping action and the subsequent recovery from the actions and observations alone. Pair construction therefore requires no task reward, gold label, or LLM judge.

Preference Training

We train the policy πθ\pi_\theta to prefer the chosen action over the looping action under the same context xx. We use direct preference optimization (DPO; Rafailov et al., 2023), with the frozen base policy πref\pi_{\mathrm{ref}} as the reference:

L=−log⁡σ(βlog⁡πθ(y+∣x)πref(y+∣x)−βlog⁡πθ(y−∣x)πref(y−∣x)).\mathcal{L} = -\log\sigma\left(\beta\log\frac{\pi_\theta(y^+ \mid x)}{\pi_{\mathrm{ref}}(y^+ \mid x)} - \beta\log\frac{\pi_\theta(y^- \mid x)}{\pi_{\mathrm{ref}}(y^- \mid x)}\right).

For Qwen3-8B, we train for one epoch with LoRA DPO (β=0.05\beta= 0.05) on 8,000 self-mined CodeGym pairs. For Qwen3-14B and Qwen3-32B, we use the same mining rule and β\beta, with pairs mined from each model’s own rollouts (Sections G.1 and G.1.7).

At inference time, we use the trained policy throughout the rollout to generate each next action. In our standard setting, the harness triggers compression when the estimated history exceeds 4,096 tokens. The same trained model summarizes older interactions under a separate prompt. It then continues acting from the updated context (Appendix § 10). DPO directly trains action preferences. Summary generation shares the updated weights but has no separate training objective.

Experiments

We first evaluate DeLoop on CodeGym and examine its training signal. We then vary the training data, context settings, and agent environments.

Experimental Setup

Benchmarks and models. CodeGym (Du et al., 2025) is our primary benchmark for both mining and evaluation: its tasks require many act–observe rounds, so the history grows until compression fires. We also evaluate on four further agent environments: ALFWorld (Shridhar et al., 2021), Open-AgentRL (Wang et al., 2026a), AppWorld (Trivedi et al., 2024), and ScienceWorld (Wang et al., 2022). Terminal-Bench (Merrill et al., 2026) and BrowseComp-Plus (Chen et al., [7]) provide further evaluations in their native agent harnesses (§ 5.3). Our main agent is Qwen3-8B, and we repeat the CodeGym study with Qwen3-14B and Qwen3-32B (Yang et al., 2025).

Training variants. DeLoop trains on self-mined CodeGym pairs (§ 3.2). We also evaluate DeLoop-Mix, a variant trained with additional cross-domain pairs (§ 4.4). Its training data include pairs mined from Terminal-Bench rollouts.

Evaluation protocol and metrics. In our standard compressed setting, the agent summarizes its history whenever it exceeds 4,096 tokens; the same model writes the summary and continues from it. Unless noted otherwise, each policy in the main CodeGym comparison acts in this setting on 300 held-out tasks, and the full-history agent serves as the uncompressed reference. We report four metrics: the loop rate (§ 2), task success, steps per task, and estimated tokens per task (Appendix § 7).

Baselines. Training-free context methods change what the agent keeps from its history, including retrieval memory, ACON (Kang et al., 2026), and LLMLingua-2 (Pan et al., 2024). Training-free inference-time controls act during inference, including an exact duplicate blocker and Reflexion (Shinn et al., 2023). Trained baselines learn from task outcomes, solved trajectories, or gold actions, and distillation SFT on full-history traces is, like DeLoop, label-free. We do not run GRPO on task success: its reward arrives only once per episode, and even a per-step gold-action reward leaves only 2.7% of GRPO groups informative (Appendix § 13.10). The full battery is in Appendix Tables 4 and 18.

Main Results on CodeGym

We first test whether DeLoop reduces loops and interaction cost while maintaining task success on CodeGym (Table 1).

MethodSupervision (labels needed)Loop (%) ↓Success (%) ↑Steps ↓Tokens/task (k) ↓
Reference
Full historynone29.031.712.2324.3
Training-free context methods
Compressed baselinenone57.325.115.0023.9
Retrieval memorynone42.727.713.3426.1
ACON compressornone46.329.314.8420.5
LLMLingua-2 compressornone46.723.714.4826.8
History truncationnone65.318.016.0534.8
Training-free inference-time controls
Exact duplicate blockernone46.725.314.7124.9
Reflexion on stucknone55.324.314.6224.1
Trained with labels
Outcome DPOoutcome-ranked pairs (task success)34.725.710.9915.9
SFT on solved tracessolved trajectories (task success)42.721.310.6125.2
Gold-label DPOlooping pairs from outcomes (task success)22.325.78.1011.3
Gold-action GRPOgold-action match reward (gold action)52.725.014.2321.0
Trained without labels
Distillation SFTfull-history traces (none)43.726.311.5226.6
Ours
DeLoop (ours)self-mined pairs (none)6.1 (−51.2)25.9 (+0.8)4.67 (−10.33)12.7 (−11.2)
DeLoop-Mix (ours)+ cross-domain pairs (none)10.1 (−47.2)30.3 (+5.2)5.94 (−9.06)9.6 (−14.3)

Table 1. Main comparison on CodeGym. Qwen3-8B under summarization at 4,096 tokens unless noted. Steps and estimated tokens are per-task averages. Shading: our methods; green: best compressed result; parentheses: change from the compressed baseline.

Qwen3-8B results. Self-mined pairs give the lowest loop rate of all methods. DeLoop cuts the loop rate 9.4×, from 57.3% to 6.1%. Training-free methods in Table 1 remain between 42.7% and 65.3%, and the strongest labeled baseline, gold-label DPO, reaches 22.3%. Breaking the loop also removes wasted interaction: steps per task fall from 15.00 to 4.67, fewer than any other method, and tokens per task fall by 47%, while task success holds.

Model scaling. We next test the same training signal at larger model sizes. We mine pairs from the compressed CodeGym rollouts of Qwen3-14B and Qwen3-32B with the same rule and train each model with DPO (Figure 5). Loops fall at every scale, 3.5×3.5 \times on Qwen3-14B and 3.0×3.0 \times on Qwen3-32B. Tokens per task fall by 35% and 29%, respectively. At these scales the repair also raises task success, by 7.2 points on Qwen3-14B and 7.1 points on Qwen3-32B.

Model scaling on CodeGym

Figure 5. Model scaling on CodeGym. Qwen3-8B, Qwen3-14B, and Qwen3-32B under summarization at 4,096 tokens. Task success versus loop rate, steps, and estimated tokens per task (left to right). Squares: compressed baseline; stars: DeLoop; colors: model size.

General capability. We also check capabilities beyond agent rollouts. Performance is preserved on LiveCodeBench, MT-Bench, and IFEval (Appendix § 13.15).

Ablation Studies

We next examine the roles of the preference pair and the training objective (Table 2).

PolicyLoop (%) ↓Success (%) ↑
Compressed baseline57.325.1
Objective (same loop signal)
DPO (DeLoop)6.1 (−51.2)25.9 (+0.8)
KTO12.623.8
IPO11.724.0
Looping-action penalty GRPO15.024.7
SFT (chosen action only)37.721.3

Table 2. Training-objective ablations. Qwen3-8B on CodeGym under summarization at 4,096 tokens. DPO, KTO, IPO, and SFT use the same 8,000 self-mined pairs; SFT uses only chosen actions. GRPO penalizes looping actions in online rollouts. Parentheses: change from the compressed baseline.

Contribution of each side of the pair. The looping action matters. Imitating only the loop-breaking action leaves a loop rate of 37.7%, while the contrast with the looping action brings it to 6.1%.

Effect of Cross-Domain Training Data

Alternative training objectives. We then test the loop signal beyond DPO, using KTO (Ethayarajh et al., 2024), IPO [1], and online GRPO (Shao et al., 2024). Every objective cuts the loop rate to 15.0% or below, and DPO (DeLoop) gives the lowest loop rate (6.1%) and the highest task success.

Remaining repeated actions. We also examine which repeated actions remain after training. The share of repeats that return new information rises from 29.9% to 69.8% (Appendix § 13.§ 6).

Self-mined CodeGym pairs preserve task success at 8B. We next test whether adding experience from other agent tasks can improve it. We keep the 8,000 CodeGym pairs fixed, add 4,635 cross-domain pairs from ALFWorld, Open-AgentRL, and

Terminal-Bench rollouts, mined with the same label-free rule, and train Qwen3-8B on all 12,635 pairs with the same DPO recipe to obtain DeLoop-Mix.

DeLoop-Mix raises success both with and without compression (Figure 6a). Under summarization at 4,096 tokens, the CodeGym success of Qwen3-8B rises from 25.1% to 30.3%, a gain of 5.2 points, compared with +0.8 points for DeLoop. With the full history, success rises from 31.7% to 36.2%, a gain of 4.5 points. The loop repair stays in place: the loop rate falls from 29.0% to 10.1% without compression and from 57.3% to 10.1% with it. Under summarization, DeLoop-Mix also uses the fewest tokens per task shown in Table 1.

Figure 6. Cross-domain data and context management. Qwen3-8B on CodeGym. (a) Task success with and without compression. (b) Loop rate across context settings. (c) Loop rate across memory policies. Base: untrained policy.

Robustness and Generalization

The CodeGym results show that self-mined pairs reduce loops and interaction cost. We now test whether these gains extend to other context settings, memory policies, and agent environments.

Generalization Across Compression Settings and Memory Policies

We first evaluate our Qwen3-8B DeLoop policy on CodeGym under five context settings, from the full history to summarization at 2,048 tokens and truncation at 4,096 tokens. The loop rate falls in every setting, remaining between 4.7% and 12.8% while the untrained baseline reaches 65.3% (Figure 6b).

Beyond the amount of retained history, we vary how it is represented. We run DeLoop-Mix (§ 4.4) under seven alternative memory policies, from retrieval memory and Claude-style compaction to summaries augmented with an action ledger. The loop rate, steps per task, and tokens per task fall under all seven (Figure 6c); with the action ledger, the loop rate falls from 62.7% to 11.3% and task success rises by 5.7 points.

The Improvement Extends to Other Agent Environments

The context comparisons above all use CodeGym. We next run DeLoop-Mix in four further environments, ALFWorld, Open-AgentRL, AppWorld, and ScienceWorld, scored with each environment’s native loop and success metrics (Table 3). ALFWorld and Open-AgentRL are evaluated on unseen games, disjoint from the training games behind their pairs (Appendix § 13.§ 1). Loops fall in all four, by up to 32.8 points on AppWorld. Tokens per task fall wherever recorded, and task success on Open-AgentRL rises from 43.9% to 45.5%.

Env.Loop (%) ↓ BaseLoop (%) ↓ OursSuccess (%) ↑ BaseSuccess (%) ↑ OursTokens (k) ↓ BaseTokens (k) ↓ Ours
ALFWorld55.227.6 (−27.6)37.338.1 (+0.8)9.36.2 (−3.1)
Open-AgentRL79.073.5 (−5.5)43.945.5 (+1.6)––
AppWorld73.740.9 (−32.8)7.05.8 (−1.2)17.914.1 (−3.8)
ScienceWorld96.583.5 (−13.0)3.51.5 (−2.0)6.56.0 (−0.5)

Table 3. Evaluation in four additional agent environments. Base: untrained Qwen3-8B. Ours: DeLoop-Mix. Native metrics; green: improvement; parentheses: change from Base.

The Repair Transfers to New Benchmarks

Finally, we test DeLoop and DeLoop-Mix in native agent harnesses with different tools and interactions. Terminal-Bench tests terminal tasks, and BrowseComp-Plus tests web research. On Terminal-Bench, DeLoop cuts unproductive duplicate calls from 16.6 to 6.9 per task. On all 830 BrowseComp-Plus queries, DeLoop-Mix lowers the loop rate from 22.4% to 1.2% while matching the untrained model’s accuracy; DeLoop, trained on CodeGym pairs alone, already lowers it to 6.4%. We also test zero-shot transfer from CodeGym to ALFWorld. DeLoop on Qwen3-32B, trained only on CodeGym pairs, lowers the ALFWorld loop rate from 64.9% to 54.5% and raises task success from 33.6% to 42.5%.

Conclusion

Long-horizon agents that compress their history fall into loops: they re-issue an action they already ran and receive the same result. On CodeGym, summarizing the history raises the loop rate of Qwen3-8B from 29.0% to 57.3%, and better context management alone does not remove it. Our key observation is that the loop labels itself: the looping action is the rejected action, and the agent’s later loop-breaking action is the chosen one. Trained on these self-mined pairs, DeLoop cuts the loop rate 9.4×, from 57.3% to 6.1%, at about one third of the steps per task while maintaining task success, and raises task success by 7.2 points at 14B and 7.1 points at 32B. An agent’s own loops become its supervision: break the loop, keep the progress. We believe our work could help the community better understand and reduce loops in long-horizon agents.

Evaluation Details

Evaluation runs. Unless noted otherwise, every number comes from the 300 held-out CodeGym tasks under summarization at 4,096 tokens. When a number averages several evaluation runs, each run evaluates the same trained policy on the same tasks. In Table 1, the full-history agent, the compressed baseline, DeLoop, and DeLoop-Mix each average three runs, history truncation averages two, and every other row is one run. In Table 2 and Figure 8, DPO (DeLoop) and KTO average three runs, while IPO and the looping-action penalty GRPO are one run each; the KTO tokens per task come from one of its three runs. In Figure 5, the Qwen3-14B compressed baseline averages three runs and its DeLoop policy is one run; the Qwen3-32B compressed baseline averages two runs and its DeLoop policy three. In Figure 6, the summarization cells at 8,192 and 2,048 tokens and the seven memory policies are one run each. In Table 3, each cell is one run except ScienceWorld, the App-World DeLoop-Mix cells, and the Open-AgentRL base, which average three.

Figure 8. Training objectives on the loop signal. Qwen3-8B on CodeGym under summarization at 4,096 tokens. Task success versus loop rate, steps, and estimated tokens per task (left to right). Red square: compressed baseline; blue: DeLoop; purple: KTO, IPO, and looping-action penalty GRPO.

Steps and tokens per task. Steps per task count the actions the agent executes in a task. We estimate tokens per task by counting the logged trajectory with the Qwen tokenizer; the trajectory holds the task prompt, the observations, and the model’s outputs, each counted once. Open-AgentRL does not record tokens, so Table 3 leaves its token cells empty.

Loop measurement. On CodeGym, the loop rate uses the structural detector of § 2.1 (Appendix § 10); each environment in Table 3 uses its own native repeat detector. Figure 2 and Figure 7 compare runs within each model’s compressed setting; Appendix § 11 gives the runs behind Figure 2.

Figure 7. Interaction cost of looping and loop-free runs. (a) Transcript tokens and (b) steps per task for runs with a loop (red) and without one (gray), for Qwen3-8B on CodeGym and five Gemini models. Tokens use the Qwen tokenizer (Appendix § 7); panel (a) uses a separate scale for Qwen3-8B.

A Real Loop from CodeGym

The episode below is excerpted from a training rollout of the compressed Qwen3-8B agent. The task is to count clusters of online servers on a grid:

· · · 13 earlier act–observe turns compressed · · ·

FindUnvisitedOnlineServer(start_row=3, start_col=0) → 3,0

· · · further act–observe turns of real work · · ·

FindUnvisitedOnlineServer(start_row=3, start_col=0) → 3,0

FindUnvisitedOnlineServer(start_row=3, start_col=0) → 3,0

later in the episode: MarkVisited(row=3, col=0)

The agent runs the same search three times and gets 3,0 back every time: nothing has marked that server as visited, so the search can only return the same cell. The loop sits inside an otherwise productive episode, and the action the search was waiting for, MarkVisited, appears later in the same rollout. This is the structure DeLoop mines (§ 3): the repeated search is the looping action, and MarkVisited is the loop-breaking action.

Loop-breaking actions range from tool calls that make progress to final answers. Another self-mined pair rejects a looping FindUnvisitedLand() call and chooses the agent’s later Done(answer=1).

More Compression Methods and Model Sizes

Every compression method raises looping on Gemini 3.5 Flash-Lite. Figure 3b compares Gemini models with and without summarization. Table 5 repeats this comparison for Gemini 3.5 Flash-Lite under five compression methods. Every method raises the loop rate, from 34.0% without compression to between 47.1% and 64.4%, and every method lowers task success. The structured action trace loops most often, so an explicit record of past actions does not stop the loop on Gemini either.

Context methodLoop (%) ↓Success (%) ↑
No compression (full history)34.057.0
Summarization47.154.7
Truncation48.746.0
Claude-style compact summary49.056.0
LangChain-style summary49.749.7
Structured action trace64.446.3

Table 5. Compression methods on Gemini 3.5 Flash-Lite. Gemini 3.5 Flash-Lite on CodeGym. As in Figure 3b, the loop rate counts the episodes in which compression fired (all episodes without compression); task success counts all tasks.

The repair holds for every model we train. Table 6 gives the CodeGym results behind Figure 5, together with steps per task and a fourth model, Qwen3.5-9B. Steps per task fall at every size: from 15.00 to 4.67 on Qwen3-8B, from 15.28 to 8.18 on Qwen3-14B, and from 13.54 to 8.82 on Qwen3-32B. Qwen3.5-9B follows the same pattern: DeLoop cuts its loop rate from 54.7% to 26.0% and raises task success by 5.6 points, from 49.7% to 55.3%.

ModelLoop (%) ↓ BaseLoop (%) ↓ DeLoopSuccess (%) ↑ BaseSuccess (%) ↑ DeLoopSteps ↓ BaseSteps ↓ DeLoopTokens (k) ↓ BaseTokens (k) ↓ DeLoop
Qwen3-8B57.36.125.125.915.004.6723.912.7
Qwen3-14B42.912.345.152.315.288.1813.38.6
Qwen3-32B38.512.937.744.813.548.8211.48.1
Qwen3.5-9B54.726.049.755.319.1514.958.05.8

Table 6. Per-model CodeGym results. CodeGym under summarization at 4,096 tokens: compressed baseline (Base) and DeLoop trained on pairs mined from the same model’s rollouts. Tokens are estimated tokens per task. Shaded columns: DeLoop; green marks an improvement over the baseline.

Setup Details

Environment and agent. CodeGym (Du et al., 2025) turns static coding problems into interactive tool-use environments. Each task exposes a function API with Observe(), task-specific actions, and Done(), and the environment server scores the agent’s answer against the task’s gold answer. Unless noted otherwise, the agent is Qwen3-8B with greedy decoding and a budget of 30 rounds, where a round is one model turn and a step is one executed action. Training and evaluation tasks share no task instance or code ID. Appendix § 7 lists the evaluation runs behind each result.

Loop detector. The canonicalization κ\kappa of § 2.1 normalizes each tool call for whitespace and argument order. A step is a looping action when its canonical call appeared earlier in the episode and the environment returns a byte-identical observation. Practical agent frameworks use a similar rule: the OpenHands stuck detector flags an agent when the same action returns the same observation four or more times (Wang et al., 2025a).

Compression. When the estimated history exceeds the threshold, the harness keeps the system prompt, the task, and the six most recent messages, and replaces everything in between with a summary. The same served model writes the summary at temperature zero, following an instruction that asks it to keep exact values, environment returns, and executed actions. The standard threshold is 4,096 tokens; Figure 3a and Figure 6b also use 8,192 and 2,048 tokens and hard truncation at 4,096 tokens. Every comparison holds the model and the threshold fixed. Table 4 lists, for each context method, the share of episodes in which compression fired.

Context methodLoop rate (%) ↓Success (%) ↑Steps/task ↓Tokens/task ↓Fired (%)
No compression (full history)29.031.712.2324,3190.0
Summaries
Standard rolling summary57.325.115.0023,91596.6
Instruction-ledger summary50.027.012.4019,53595.7
Claude-style compact summary50.326.313.6720,94495.0
LangChain-style summary51.726.313.2520,72596.7
Action-trace summary52.025.014.2130,93796.7
Action-warning summary54.024.014.1222,88697.0
Action-ledger summary62.723.315.5124,50996.7
Memory and learned compressors
Retrieval memory42.727.713.3426,12797.0
ACON compressor46.329.314.8420,54297.7
LLMLingua-2 compressor46.723.714.4826,78897.0
Truncation
Round clipping (keep 6 of 12)37.028.312.1725,95644.0
History truncation65.318.016.0534,79496.7

Table 4. Context-management comparison. Qwen3-8B on 300 held-out CodeGym tasks. Fired: share of episodes in which compression fired. Steps and estimated tokens are per-task averages. The shaded row is the compressed baseline: summarization at 4,096 tokens.

Gemini Runs

The Gemini models (Gemini Team et al., 2023) run the 300 held-out CodeGym tasks in the same harness and summarize at 1,400 tokens so that compression fires within their shorter episodes. Figure 3b compares each model’s full-history run with the episodes of its summarization run in which compression fired; Figure 2 uses all 300 episodes of the summarization run.

models.

Loop Labels

Loop labels in Figure 2 and Figure 7. Both figures use the loop rate of § 2.1: a run loops when it contains at least one looping action. Figure 2 splits each model’s compressed-baseline runs by this label (Table 7): 1,500 episodes on five disjoint sets of 300 CodeGym tasks outside the evaluation set for Qwen3-8B, 400 CodeGym tasks for Qwen3-14B, and the 300 held-out tasks for the four Gemini models.

ModelCompressionEpisodesFailure, loop (%)Failure, no loop (%)
Qwen3-8BSumm. 4,0961,50084.967.7
Qwen3-14BSumm. 4,09640070.847.7
Gemini 3.5 Flash-LiteSumm. 1,40030061.136.5
Gemini 3.1 FlashSumm. 1,40030051.323.9
Gemini 3.6 FlashSumm. 1,40030041.412.8
Gemini 3.1 ProSumm. 1,40030047.611.7

Table 7. Failure rates behind Figure 2. For each model’s compressed baseline on CodeGym: the compression setting, the number of episodes, and the task-failure rate of runs with and without a loop (§ 2.1).

How the Policy Uses Its Action Record

These probes, which complement § 15.§ 1, ask how Qwen3-8B uses the record of an action it has already run.

The record matters, its wording does not. We take 150 looping points from training-side tasks that never appear in evaluation and rebuild the context in five length-matched variants: (A) the original action–observation block; (B) a one-line assertion of the action and its result; (C) no record; (D) the assertion inside the summary; and (E) the returned value without saying that the agent ran the action. We sample 16 completions per point at temperature 0.7 and measure re-issue, the share of completions that repeat the looping action. For the compressed baseline, deleting the record raises re-issue from 15.3% (A) to 43.3% (C), while re-

wording it keeps re-issue close to the verbatim rate (17.6% for B, 16.5% for D, 18.9% for E).

Training lowers re-issue in every condition. On the same points (Table 8), DeLoop re-issues 3.4% of the time with the verbatim record, 4.5% with the assertion, and 15.0% with the record deleted, against 15.3%, 17.6%, and 43.3% for the compressed baseline.

PolicyA: verbatim ↓B: assertion ↓C: deleted ↓
Compressed baseline15.317.643.3
DeLoop (ours)3.44.515.0

Table 8. Action-record probe. Re-issue rate (%) of the looping action for Qwen3-8B at 150 CodeGym looping points, with the record verbatim (A), as a one-line assertion (B), or deleted (C); 16 completions per point at temperature 0.7.

The deletion effect holds on an unselected sample. To avoid selecting on loops, we fix 300 decision points after compression from 253 tasks before any model call, stratified by whether the episode eventually loops. At each point, the untrained policy chooses its next action with the most recent completed action–observation record present or deleted (eight samples each). It re-issues that action 3.3% of the time with the record present and 48.8% with it deleted in this stratified sample; weighting the two strata by their population shares gives a difference of 44.3 points.

Training Suppresses the Looping Action

Two probes at 250 loop points from tasks outside all preference-training data ask what training changes (Table 9). First, we score the recorded loop-breaking action against the looping action. The untrained policy ranks the loop-breaking action higher at 49.6% of points, a coin flip; the two-source DeLoop-Mix variant (CodeGym, ALFWorld, and Open-AgentRL pairs) raises this to 69.2%. Second, we freeze each loop prefix and take one greedy action. Every trained policy re-issues the looping action less often than the untrained one (15.6%): 6.0% for DeLoop, 5.2% for DeLoop-Mix, and 5.6% for looping-action penalty GRPO. The share that copies the recorded loop-breaking action stays between 18.8% and 20.8% for every policy, while calls to Done() rise from 3.6% to between 12.4% and 26.0%. Training thus suppresses the looping action rather than teaching one memorized recovery.

Policylog⁡p\log p (loop-breaking)log⁡p\log p (looping)MarginLoop-breaking higher (%)
Compressed baseline−3.377−3.5140.13749.6
Two-source DeLoop-Mix (CodeGym, ALFWorld, Open-AgentRL pairs)−3.979−5.2111.23269.2
PolicyLooping ↓Loop-breakingDone()OtherUnparsed
Compressed baseline15.620.83.645.214.8
DeLoop (ours)6.019.224.033.217.6
DeLoop-Mix (ours)5.220.417.242.414.8
Two-source DeLoop-Mix (CodeGym, ALFWorld, Open-AgentRL pairs)8.420.412.442.416.4
Looping-action penalty GRPO5.618.826.032.017.6

Table 9. Action scores and greedy choices after training. Qwen3-8B at 250 held-out CodeGym loop points. Top: log-probabilities of the recorded loop-breaking and looping actions, their margin, and the share of points where the loop-breaking action scores higher. Bottom: one greedy action from each frozen prefix, by kind (%).

Training Details and Additional Results

This appendix gives the training recipe, the trained baselines of Table 1, and ablations. Unless noted otherwise, every row is Qwen3-8B on the 300 held-out CodeGym tasks under summarization at 4,096 tokens.

Training Details

Mining. We run the compressed agent on CodeGym training tasks and flag looping actions with the detector of § 2.1, comparing canonicalized calls (whitespace and argument order normalized) and exact observations. Each looping action that the agent later breaks yields one pair: the prompt is the history just before it, the rejected action is the looping action, and the chosen action is the first later action in the same rollout that is neither a looping action nor the same call. Without the second condition, a later repeat that returns a new observation could be chosen, and both sides of the pair would be the same text.

No labels. The miner reads only actions and observations. It never reads the reward, the task status, or a gold answer, and no LLM judge takes part. Of the 8,000 CodeGym pairs, 82.6% come from runs that fail.

Hyperparameters. The Qwen3-8B DeLoop policy trains LoRA (Hu et al., 2022) adapters (r=32r = 32, α=64\alpha= 64, all projection modules) from the base model with DPO for one epoch on 8,000 of the 9,403 mined pairs, with β=0.05\beta= 0.05, learning rate 8×10−68 \times10^{-6}, effective batch 16 (batch 1, 16 accumulation steps), and maximum sequence length 4,500. We chose β\beta from {0.02,0.05,0.1,0.2,0.5}\{0.02, 0.05, 0.1, 0.2, 0.5\} on a separate 128-task screening set, disjoint from the 300 evaluation tasks. Qwen3-14B and Qwen3-32B use the same mining rule and β\beta on 2,331 and 2,244 pairs mined from their own compressed CodeGym rollouts, and train for two epochs. All policies decode greedily.

Cross-domain pairs. DeLoop-Mix adds 4,635 cross-domain pairs to the 8,000 CodeGym pairs (12,635 in total) and keeps the optimizer and β\beta. Each pair again contrasts a looping action with a later loop-breaking action from the same rollout, mined with the same label-free rule: no reward, task status, gold answer, or other supervision is used. The pairs come from ALFWorld (1,712), ALFWorld tasks run in the Open-AgentRL harness (1,711), and Terminal-Bench (1,212). The ALFWorld and Open-AgentRL pairs come from ALFWorld training games; Table 3 evaluates both environments on the 134 unseen validation games, which share no game with the training split. A two-source variant uses the same number of cross-domain pairs, 2,511 from ALFWorld and 2,124 from the Open-AgentRL harness.

Matched Baselines

Baselines. The four offline trained baselines of Table 1 share our model, optimizer settings, and budget of 8,000 examples, and differ only in how the examples are built. Outcome DPO uses

outcome-ranked pairs (Shi et al., 2024; Song et al., 2024) whose rejected side is a random step from a failed run. SFT on solved traces imitates runs that solve the task (Gulcehre et al., 2023; Zelikman et al., 2022). Gold-label DPO also rejects looping actions but uses task outcomes to build its corpus. Distillation SFT imitates the full-history agent and, like DeLoop, uses no labels. Gold-action GRPO trains online on the same 8,000 prompts and rewards an exact match with the gold action.

More data does not close the gap. At 3,910 and at 8,000 examples, DeLoop gives the lowest loop rate (18.6% and 6.1%) and the fewest steps per task; the strongest baseline, gold-label DPO, reaches 37.5% and 22.3% (Table 10).

MethodExamplesLoop (%) ↓Success (%) ↑Steps ↓
Full history—29.031.712.23
Compressed baseline—57.325.115.00
Outcome DPO3,91049.525.812.95
Outcome DPO8,00034.725.710.99
Gold-label DPO3,91037.526.310.23
Gold-label DPO8,00022.325.78.10
SFT on solved traces3,91044.523.711.71
SFT on solved traces8,00042.721.310.61
Distillation SFT3,91047.024.011.80
Distillation SFT8,00043.726.311.52
DeLoop (ours)3,91018.622.27.47
DeLoop (ours)8,0006.125.94.67

Table 10. Matched baselines at two training budgets. Qwen3-8B, CodeGym, summarization at 4,096 tokens. Each offline baseline is trained on 3,910 and on 8,000 examples; the 8,000-example rows appear in Table 1.

More Pairs, Fewer Loops

The loop rate falls as we add self-mined pairs, from 45.1% at 1k pairs to 6.1% at 8k, and steps per task fall from 11.88 to 4.67 (Table 11). The loop rate levels off after 8k pairs.

Self-mined pairsLoop (%) ↓Success (%) ↑Steps ↓
Compressed baseline57.325.115.00
1k45.126.411.88
2k34.524.79.57
3.9k18.622.27.47
8k (DeLoop)6.125.94.67
9.4k6.723.04.82

Table 11. Effect of the number of self-mined pairs. Qwen3-8B, CodeGym, summarization at 4,096 tokens; the DeLoop recipe on the number of self-mined pairs shown.

How Much Cross-Domain Data to Add

Every mixture of CodeGym and cross-domain pairs raises task success above the compressed baseline (25.1%) and DeLoop (25.9%), and keeps the loop rate at or below 24.3% up to a 50% cross-domain share (Table 12). A 37% share gives the highest success among the mixtures. At that share, three sources instead of two keep task success (30.3% vs. 30.9%) and lower the loop rate from 19.0% to 10.1%; this three-source mixture is DeLoop-Mix.

Training dataShareLoop (%) ↓Success (%) ↑Steps ↓
Compressed baseline—57.325.115.00
CodeGym only (DeLoop)0%6.125.94.67
+ two sources10%8.327.65.55
+ two sources20%11.926.86.74
+ two sources37%19.030.98.80
+ three sources (DeLoop-Mix)37%10.130.35.94
+ two sources50%24.327.39.48
Cross-domain only100%55.331.315.13

Table 12. Cross-domain data mixtures. Qwen3-8B, CodeGym, summarization at 4,096 tokens; DPO on the 8,000 CodeGym pairs plus cross-domain pairs at the share shown (last row: cross-domain pairs only). The highlighted rows hold the share at 37%; the three-source row is DeLoop-Mix in Table 1.

Comparison with Agent-R-Style Splicing

Agent-R (Yuan et al., 2025) learns from whole trajectories and task outcomes: it splices a failed path onto a reward-selected branch at the point where the two diverge. We adapt this divergence splicing to our rollouts, where it yields 1,000 training pairs, and run DeLoop on 1,000 self-mined pairs next to it. Without outcome labels, self-mined pairs lower the loop rate more (45.1% vs. 52.3%), take fewer steps per task (11.88 vs. 13.62), and keep higher task success (26.4% vs. 24.0%; Table 13).

MethodBudgetLabelsLoop (%) ↓Success (%) ↑Steps ↓Tokens/task (k) ↓
Compressed baseline—none57.325.115.0023.9
DeLoop (ours)1,000none45.126.411.8822.4
Agent-R-style divergence splice1,000task success52.324.013.6227.1

Table 13. Comparison with Agent-R-style splicing. Qwen3-8B, CodeGym, summarization at 4,096 tokens. Both trained rows use 1,000 training pairs. Labels: the supervision each method needs.

Hyperparameters, Mining Rules, and Model Size

Hyperparameters. Changing one field of the recipe at a time, every setting lowers the loop rate below the compressed baseline’s 57.3% (Table 14). The default recipe keeps the highest task success (25.9%), and β=0.05\beta= 0.05 gives the lowest loop rate of the β\beta values. A higher learning rate, a larger LoRA rank, or a second epoch on the 8,000 pairs lowers the loop rate further, to 0.7–1.7%, with 1.60–3.59 steps per task.

SettingLoop (%) ↓Success (%) ↑Steps ↓
Compressed baseline57.325.115.00
Default recipe (DeLoop)6.125.94.67
DPO β\beta
β=0.01\beta= 0.0117.316.32.06
β=0.1\beta= 0.117.723.06.88
β=0.2\beta= 0.236.725.010.57
Learning rate
lr 2×10−62 \times10^{-6}35.323.710.33
lr 3×10−53 \times10^{-5}0.719.31.60
LoRA rank
r=8r = 8 (α=16\alpha= 16)25.324.07.84
r=64r = 64 (α=128\alpha= 128)1.324.03.59
Epochs and pairs
8,000 pairs, 2 epochs1.725.32.85
9,403 pairs, 2 epochs7.020.72.80
500 pairs, 1 epoch52.319.714.08

Table 14. Training hyperparameter ablations. Qwen3-8B, CodeGym, summarization at 4,096 tokens. Each block changes one field of the default recipe.

Mining rules. Changing one mining rule at a time, re-mining the same rollouts, and training on 8,000 pairs keeps the loop rate at or below 7.0%; the default rule keeps the highest task success (Table 15). The same table gives activity for the SFT control of Table 2: it shortens episodes less than the pair (11.71 rounds per task, against 5.47 for full pairs and 16.34 for the compressed baseline).

SettingMinedLoop (%) ↓Success (%) ↑Rounds ↓
Compressed baseline—57.325.116.34
Default (DeLoop)9,4036.125.95.47
SFT (chosen action only)—37.721.311.71
Mining rule (one change each)
Random later chosen9,3573.723.34.61
Exact-string match9,2947.022.75.02
Near-identical obs.10,2653.020.03.85

Table 15. Mining-rule and chosen-only ablations. Qwen3-8B, CodeGym, summarization at 4,096 tokens; 8,000 training pairs per row. “Mined”: pairs the rule yields. The variants pick a random later loop-breaking action, match actions as exact strings, or treat observations with similarity ratio ≥0.9\ge0.9 as the same. SFT trains on the loop-breaking (chosen) action alone. Rounds: agent turns per task.

Model size. Pairs transfer across model sizes (Table 16). Qwen3-8B trained on 2,331 pairs mined from Qwen3-14B lowers its loop rate from 57.3% to 35.0% and raises task success from 25.1% to 28.7%. Qwen3-14B trained on the 8,000 Qwen3-8B pairs lowers its loop rate from 42.9% to 9.3%.

ModelTraining pairsLoop (%) ↓Success (%) ↑Rounds ↓
Qwen3-8Bnone57.325.116.34
Qwen3-8B8,000 own6.125.95.47
Qwen3-8B2,331 from 14B35.028.711.28
Qwen3-14Bnone42.945.115.57
Qwen3-14B2,331 own12.352.38.26
Qwen3-14B8,000 from 8B9.344.37.21

Table 16. Preference-pair transfer across model sizes. CodeGym, summarization at 4,096 tokens; DPO on pairs mined from the model’s own rollouts or the other model’s. Highlighted rows: DeLoop from Figure 5. Rounds: agent turns per task.

Per-Step Selectivity

Not every repeated call is wasted: re-checking a state the agent has changed returns a new observation. We split repeated calls into looping actions, which get back the same observation, and informative repeats, which get back a new one. Selectivity is the share of repeats that are informative, pooled over all scored steps.

Training removes looping actions far more than informative repeats (Table 17). DeLoop lowers looping actions from 24.9% to 2.5% of steps and informative repeats from 10.6% to 5.8%, so selectivity rises from 29.9% to 69.8%; DeLoop-Mix reaches 74.2%. The trained policies still re-check the environment, but they rarely re-issue a call whose answer they already have.

PolicyLooping actions (% of steps) ↓Informative repeats (% of steps)Selectivity (%) ↑Scored steps
Compressed baseline24.910.629.913,504
DeLoop (ours)2.55.869.84,204
DeLoop-Mix (ours)2.67.574.25,347

Table 17. Informative repeats and looping actions. Qwen3-8B on CodeGym under summarization at 4,096 tokens, pooled over the 300 tasks and three evaluation runs. Selectivity is the share of repeats that return new information.

Training Objectives on the Same Loop Signal

DPO, KTO, and IPO in Table 2 and Figure 8 train Qwen3-8B on the same 8,000 self-mined CodeGym pairs; DPO uses the DeLoop recipe (Section G.1), and KTO and IPO use their published default settings. IPO (Azar et al., [1]) replaces the logsigmoid of DPO with a squared loss that bounds the preference margin. KTO (Ethayarajh et al., 2024) drops the pairing and scores each action on its own, with loop-breaking actions as desirable and looping actions as undesirable; it still cuts the loop rate to 12.6%. Looping-action penalty GRPO uses no pairs; it penalizes every flagged step in fresh online rollouts (Section G.10). All four objectives shorten episodes: steps per task fall from 15.00 to between 4.67 (DPO) and 6.72 (IPO), and tokens per task from 23.9k to between 12.4k and 13.6k.

Inference-Time Controls

Table 18 lists every training-free control we ran on the compressed baseline. The exact duplicate blocker refuses to run a call that repeats an earlier one, so its loop rate counts attempted repeats. Temperature 0.7 and a token repetition penalty (Keskar et al., 2019) of 1.2 change decoding. Reflexion, stuck-stop, and stuck-nudge act when a stuck detector fires: the model critiques itself before acting, the episode ends, or the model gets a reminder.

ControlLoop (%) ↓Success (%) ↑Steps ↓Tokens/task (k) ↓
Compressed baseline57.325.115.0023.9
Blocking and decoding
Exact duplicate blocker46.725.314.7124.9
Temperature 0.763.329.316.9918.5
Repetition penalty 1.265.729.016.8514.7
Within-episode controls (act when a stuck detector fires)
Reflexion on stuck55.324.314.6224.1
Stuck-stop (end the episode)57.321.713.0821.6
Stuck-nudge (remind the model)58.723.714.8523.2
Ours
DeLoop (ours)6.125.94.6712.7

Table 18. Inference-time controls. Qwen3-8B on CodeGym under summarization at 4,096 tokens. Every control runs on the compressed baseline without training.

Inference-time controls do not break the loop. Every control leaves the loop rate at 46.7% or above, against 6.1% for DeLoop. The blocker comes closest, but steps per task barely move (14.71 against 15.00) because the agent keeps proposing the blocked call. The decoding controls raise the loop rate to 63.3% and 65.7%, and the within-episode controls stay between 55.3% and 58.7%.

GRPO Variants

We train Qwen3-8B with online GRPO (Shao et al., 2024) under summarization at 4,096 tokens and vary the reward, sampling, or prompts (Table 19). Looping-action penalty GRPO penalizes every looping action; one version also mixes in prompts from other environments. Episode-level loop reward GRPO gives one sparse reward per episode, and loop-weighted SFT replaces RL with weighted imitation. Gold-action GRPO, the labeled baseline of Table 1, rewards an exact match with a gold action; its variants add partial credit and more diverse sampling. A group is informative when its rewards differ, so that it yields a gradient.

MethodReward or signalLoop (%) ↓Success (%) ↑Steps ↓Tokens/task (k) ↓Informative groups (%)
Compressed baselinenone57.325.115.0023.9—
Loop signal (no labels)
Looping-action penalty GRPOper-step penalty15.024.76.3913.4—
+ mixed promptsper-step penalty18.328.37.0813.8—
Episode-level loop reward GRPOone reward per episode47.325.313.5321.8—
Loop-weighted SFTweighted imitation42.319.09.9228.6—
Gold-action reward (labels)
Gold-action GRPOexact match52.725.014.2321.02.7
+ partial creditpartial match49.327.013.2222.25.3
+ partial credit, diverse samplingpartial match32.727.311.0820.220.5

Table 19. GRPO reward and sampling variants. Qwen3-8B on CodeGym under summarization at 4,096 tokens. Informative groups are the share of sampled groups whose rewards differ.

The per-step penalty is the strongest signal. It cuts the loop rate to 15.0%, and to 18.3% with 28.3% task success when prompts are mixed. A sparse episode-level reward leaves 47.3% of runs looping, and loop-weighted SFT 42.3%.

Gold-action rewards give GRPO little to learn from. With exact matching, only 2.7% of groups are informative and the loop rate stays at 52.7%. Partial credit raises informative groups to 5.3%

and diverse sampling to 20.5%, and the loop rate falls with them, to 49.3% and 32.7%.

The penalty holds across context settings. Trained once under summarization at 4,096 tokens, the policy loops in 13.7% of tasks with the full history and in 11.3%, 15.0%, and 16.0% under summarization at 8,192, 4,096, and 2,048 tokens, against 29.0%, 51.0%, 57.3%, and 64.7% for the untrained agent in the same settings. Under truncation, which it never saw in training, it loops in 24.7% of tasks against 65.3%. Task success rises from 20.0% to 24.3% at 2,048 tokens and from 18.0% to 25.7% under truncation.

A Stricter Chosen Rule Does Not Help

Requiring the agent to keep receiving new observations after the loop-breaking action does not improve the pairs. At 1,726 pairs from the same rollouts, this stricter rule gives a loop rate of 41.7% and task success of 23.0%, against 38.7% and 25.0% for the standard rule at the same number of pairs.

Combining SFT with DPO

When SFT and DPO are staged, DPO must come last (Table 20). In a separate screening evaluation, SFT on solved CodeGym traces after DPO reopens loops (6.5% to 29.7%), and a final DPO stage closes them again (2.3%).

Training sequenceSFT demonstrationsLoop (%) ↓Success (%) ↑Steps ↓
Main evaluation
DPO only (DeLoop)—6.125.94.67
Screening evaluation: objective order
DPO only—6.516.44.74
DPO →\to SFTsolved CodeGym traces29.712.510.79
DPO →\to SFT →\to DPOsolved CodeGym traces2.321.14.62

Table 20. Sequential SFT and DPO training. Qwen3-8B on CodeGym under summarization at 4,096 tokens. The lower block is a separate screening evaluation, compared only within the block.

A Likelihood Anchor Brings Loops Back

Plain DPO suits self-mined pairs better than DPO with a likelihood anchor. RPO adds a negative log-likelihood term on the chosen action to the DPO loss, with weight α=1.0\alpha= 1.0. On the same 8,000 self-mined CodeGym pairs, the anchor raises the loop rate of Qwen3-8B from 6.1% to 27.0%, steps per task from 4.67 to 7.90, and tokens per task from 12.7k to 24.8k, and task success goes from

25.9% to 21.3%. The anchor raises loops on other training data as well: from 19.0% to 42.1% on a two-source mixed corpus, and from 34.7% to 37.3% on the outcome-ranked pairs of Table 1.

The training logs show what the anchor changes. Plain DPO pushes the looping action far down and lowers the loop-breaking action only slightly; with the anchor, the loop-breaking action rises toward imitation. Appendix § 14.§ 2 derives this trade-off from the gradient of the objective and gives the log-probabilities. Imitation alone leaves many loops in place (37.7% for the chosen-only row of Table 2).

Cross-Domain Pairs from Public Trajectories

The gain from cross-domain pairs does not depend on one trajectory collection. We keep the self-mined CodeGym pairs and the size of the cross-domain portion fixed, build the cross-domain pairs from a public collection instead, either SWE-agent (Yang et al., 2024a) or OpenHands (Wang et al., 2025a) coding trajectories or WebArena (Zhou et al., 2024) browser trajectories, and train Qwen3-8B with the same DPO recipe (Table 21). With every source, the CodeGym loop rate falls from 57.3% to between 17.3% and 22.7%, task success rises from 25.1% to between 26.0% and 28.7%, and steps per task fall from 15.00 to 8.00 or fewer. The same policies also loop less on ALFWorld (33.6% to 46.3%, against 55.2%), and the WebArena pairs raise ALFWorld task success from 37.3% to 41.8%.

Cross-domain sourceCodeGymALFWorld
Loop (%) ↓Success (%) ↑Steps ↓Loop (%) ↓Success (%) ↑
Compressed baseline57.325.115.0055.237.3
SWE-agent17.326.07.1835.836.6
OpenHands21.028.77.8833.637.3
WebArena22.728.38.0046.341.8

Table 21. Cross-domain pairs from public trajectories. Qwen3-8B on CodeGym and ALFWorld with summarization. Each shaded row trains on the self-mined CodeGym pairs plus cross-domain pairs from the named public source.

General Capability Is Preserved

Training on loops leaves general ability intact. We evaluate the untrained Qwen3-8B, DeLoop, and DeLoop-Mix on three non-agentic benchmarks outside agent tasks (Table 22): the 182 LiveCodeBench (Jain et al., 2025) problems released from 2025 onward, with the official prompts and greedy pass@1; MT-Bench (Zheng et al., 2023), with 80 two-turn questions, the official category temperatures, and one LLM judge for all three models; and IFEval (Zhou et al., 2023), with 541 prompts and the official strict-prompt scorer. On LiveCodeBench, the base model solves 53 problems, DeLoop 52, and DeLoop-Mix 54. DeLoop scores higher than the base model on MT-Bench (4.463 against 4.225) and on IFEval (83.5% against 82.8%), and DeLoop-Mix reaches 83.4% on IFEval.

PolicyLiveCodeBenchMT-BenchIFEval (%)
Qwen3-8B (untrained)53/1824.22582.8
DeLoop (ours)52/1824.46383.5
DeLoop-Mix (ours)54/1824.21383.4

Table 22. General capability evaluation. Qwen3-8B on LiveCodeBench (problems solved of 182, greedy pass@1), MT-Bench (mean judge score, 1–10), and IFEval (strict-prompt accuracy).

Repair Across Memory Policies

Table 23 gives the numbers behind Figure 6c. The seven memory policies are retrieval memory, an instruction ledger, Claude-style compaction, a LangChain summary, and summaries augmented with an action trace, an action warning, or an action ledger. Under every one of them, DeLoop-Mix lowers the loop rate, from 42.7%–62.7% to 6.3%–20.7%, along with steps per task, and it cuts tokens per task by more than half. Task success rises under four of the seven, by up to 5.7 points with the action ledger.

Other Model Families and Sizes

Llama-3.1-8B. Llama (Grattafiori et al., 2024) loops natively. With the full history, Llama-3.1-8B loops in 44.0% of CodeGym episodes, and under summarization at 4,096 tokens it loops in 43.7% (Table 24). We train it with DPO on pairs mined from its own rollouts with the same rule. The trained policy loops in 2.0% of episodes, against 43.7% for the compressed baseline, and steps per task fall from 17.51 to 5.72, while task success goes from 17.8% to 19.4%.

ModelSettingLoop (%) ↓Success (%) ↑Steps ↓
Llama-3.1-8BFull history44.017.517.41
Compressed baseline43.717.817.51
DeLoop (ours)2.019.45.72
Qwen3-14BFull history33.354.014.36
Compressed baseline42.945.115.28
DeLoop (ours)12.352.38.18
Qwen3-32BFull history26.046.712.97
Compressed baseline38.537.713.54
DeLoop (ours)12.944.88.82

Table 24. Other model families and sizes. CodeGym. For each model: the agent with the full history, the compressed baseline (summarization at 4,096 tokens), and DeLoop, trained on that model’s self-mined pairs and evaluated under summarization at 4,096 tokens.

Qwen3-14B and Qwen3-32B. Compression raises looping at both sizes and costs task success. Summarization at 4,096 tokens raises the loop rate from 33.3% to 42.9% on Qwen3-14B and from 26.0% to 38.5% on Qwen3-32B, and lowers task success by 8.9 and 9.0 points. We train each model on pairs mined from its own compressed rollouts with the recipe of Section G.1. Both policies loop less than the agent with the full history (12.3% and 12.9%), and they win back most of the success that compression costs: 7.2 of the 8.9 points at 14B and 7.1 of the 9.0 points at 32B (Table 24).

DeLoop at 32B also helps when the history is not compressed. Evaluated with the full history, it lowers the loop rate from 25.0% to 11.7% and raises task success from 46.3% to 51.3%, compared with a base-model run matched to this test.

Memory policyPolicyLoop (%) ↓Success (%) ↑Steps ↓Tokens/task (k) ↓
Retrieval memoryCompressed baseline42.727.713.3426.1
DeLoop-Mix (ours)10.731.06.9311.8
Instruction ledgerCompressed baseline50.027.012.4019.5
DeLoop-Mix (ours)7.025.35.168.8
Claude-style compactCompressed baseline50.326.313.6720.9
DeLoop-Mix (ours)6.325.75.849.3
LangChain summaryCompressed baseline51.726.313.2520.7
DeLoop-Mix (ours)8.726.36.019.9
Action traceCompressed baseline52.025.014.2130.9
DeLoop-Mix (ours)20.727.77.6714.2
Action warningCompressed baseline54.024.014.1222.9
DeLoop-Mix (ours)9.327.35.999.7
Action ledgerCompressed baseline62.723.315.5124.5
DeLoop-Mix (ours)11.329.05.609.6

Table 23. DeLoop-Mix across memory policies. Qwen3-8B on CodeGym. Each memory policy has a compressed-baseline row and a DeLoop-Mix row (shaded) on the same tasks. Tokens are estimated tokens per task (Appendix § 7).

A Formal Account of Loops and Their Repair

Setup and Definitions

A trajectory hT=(a1,o1,…,aT,oT)h_T = (a_1, o_1, \ldots, a_T, o_T) alternates tool calls and observations, and h<th_{<t} is its prefix before step tt; sts_t and Loop⁡(hT)\operatorname{Loop}(h_T) are as in § 2.1. For a candidate action aa, s(a;h<t)s(a; h_{<t}) is the value sts_t would take if the agent issued aa at step tt. A context manager CC maps the history to the context the policy acts on, Xt=C(h<t)X_t = C(h_{<t}), with C=id⁡C = \operatorname{id} for the full history. A self-mined pair (§ 3.1) has prompt x=Xtx = X_t, the context the agent saw before the looping action y−=aty^{-} = a_t, and chosen action y+=at′y^{+} = a_{t'}.

Loop Ambiguity and an Activity Ceiling

Compression can map two histories that disagree on whether an action was already taken to the same context, which then cannot tell a new action from a looping one. Let work WCW_C count the actions other than Observe and Done issued after the first compression event, and define the loop ambiguity

δ=ess inf⁡Pr⁡[s(a;h<t)=1∣Xt, a issued]\delta= \operatorname{ess\,inf}\Pr\left[s(a; h_{<t}) = 1 \mid X_t,\ a\ \text{issued}\right]

over these actions. We start after compression because the first action of an episode never loops.

Proposition 1 (activity ceiling). A policy that cannot tell repeats from new actions loops less only by acting less: if δ>0\delta> 0 and the policy issues at most ε\varepsilon looping actions per task in expectation, then E[WC]≤ε/δ\mathbb{E}[W_C] \le\varepsilon/\delta.

Proof. Each work action issued after compression loops with conditional probability at least δ\delta, so ε≥E[#looping actions]≥δE[WC]\varepsilon\ge\mathbb{E}[\#\text{looping actions}] \ge\delta\mathbb{E}[W_C]. □

Driving loops close to zero thus requires a lower δ\delta or less activity, so we report steps and tokens per task next to the loop rates of Table 1. Reading the action record lowers δ\delta, yet the compressed baseline loops even with summaries that record its past actions (§ 2.3); training the policy targets this gap.

Why Both Sides of a Pair Matter

The DPO gradient on a self-mined pair raises the loop-breaking action and lowers the looping action under the same context. With zθ=log⁡πθ(y+∣x)πref(y+∣x)−log⁡πθ(y−∣x)πref(y−∣x)z_{\theta} = \log\frac{\pi_{\theta}(y^{+} \mid x)}{\pi_{\mathrm{ref}}(y^{+} \mid x)} - \log\frac{\pi_{\theta}(y^{-} \mid x)}{\pi_{\mathrm{ref}}(y^{-} \mid x)} and g=σ(−βzθ)g = \sigma(-\beta z_{\theta}), the loss of § 3.2 is L=−log⁡σ(βzθ)\mathcal{L} = -\log\sigma(\beta z_{\theta}) and

∇θL=−βg∇θlog⁡πθ(y+∣x)+βg∇θlog⁡πθ(y−∣x).\nabla_{\theta}\mathcal{L} = -\beta g \nabla_{\theta}\log\pi_{\theta}(y^{+} \mid x) + \beta g \nabla_{\theta}\log\pi_{\theta}(y^{-} \mid x).

Up to weights, the first term alone is chosen-only SFT, which does not break the loop (Table 2); the pair does.

A likelihood anchor dilutes the contrast. Adding αℓnll\alpha\ell_{\mathrm{nll}} with ℓnll=−1∣y+∣log⁡πθ(y+∣x)\ell_{\mathrm{nll}} = -\frac{1}{\lvert y^{+}\rvert}\log\pi_{\theta}(y^{+} \mid x) raises the coefficient on the first term to βg+α/∣y+∣\beta g + \alpha/\lvert y^{+}\rvert and leaves the second at βg\beta g. The contrast share

ρ(α)=βgβg+α/∣y+∣\rho(\alpha) = \frac{\beta g}{\beta g + \alpha/\lvert y^{+}\rvert}

is 1 for DPO and falls toward 0, the chosen-only limit, as α\alpha grows, so the loop rate should rise with α\alpha.

On the 8,000 self-mined CodeGym pairs, the loop rate follows this order: 6.1% for DPO (DeLoop), 27.0% with the anchor at α=1\alpha= 1 (Section G.13), and 37.7% for chosen-only SFT. In the training logs of two runs that differ only in the anchor (β=0.05\beta= 0.05), DPO lowers the loop-breaking action’s mean log-probability only slightly, from −44.0-44.0 to −51.1-51.1, and drives the looping action’s from −40.6-40.6 to −132.6-132.6. With the anchor, the loop-breaking action rises from −43.6-43.6 to −3.1-3.1 and the looping action rises with it, from −40.4-40.4 to −28.7-28.7, so the implied reward margin βzθ\beta z_{\theta} ends at 1.44 instead of 4.25.

Extension Studies

We report four further studies on Qwen3-8B in CodeGym: what the policy conditions on (§ 15.§ 1), why the detector uses exact repetition (§ 15.§ 1.1), a random-pair control (§ 15.§ 2), and what the chosen action adds (§ 15.§ 3).

The Policy Reacts to the Record of Its Own Executed Action

We probe the moments at which the agent loops. Unlike the training-side points of Section F, these come from the compressed baseline’s runs on the 300 evaluation tasks: 150 looping points, one per task at its first loop. We add 80 retry points, at which an earlier call to the same action returned a different observation, so calling it again is reasonable. At each point we rebuild the context from the raw history in six conditions: not yet executed (the history before the action was first run); proposed only (the same history plus a note that the action was proposed but not run, padded to the same length); proposed + observation (the note also states what the action would return); just executed (the history ending right after the action’s first run); record present (the full history up to the decision point); and record deleted (the same history with the record of the earlier run removed). We sample eight completions per condition at temperature 0.7 and report the re-issue rate, the share of completions whose next action is the probed action (Table 25).

Context conditionLooping points (n=150n=150) — BaseLooping points (n=150n=150) — DeLoopLooping points (n=150n=150) — DeLoop-MixRetry points (n=80n=80) — BaseRetry points (n=80n=80) — DeLoopRetry points (n=80n=80) — DeLoop-Mix
Not yet executed73.761.457.368.463.362.2
Proposed only73.941.024.466.731.925.2
Proposed + observation29.02.52.220.64.77.2
Just executed4.91.91.95.65.66.9
Record present16.58.36.851.736.138.0
Record deleted53.320.723.964.854.256.1

Table 25. Action re-issue under different context conditions. Re-issue rate (%) of the probed action under each context condition, at looping points and at retry points in Qwen3-8B CodeGym runs. Base is the untrained Qwen3-8B.

Untrained policy. Planning an action does not stop the agent from issuing it: with the action only proposed, the untrained Qwen3-8B re-issues it in 73.9% of completions, the same as before the action was ever run (73.7%). Stating the observation lowers re-issue to 29.0%, and the record of the agent’s own execution lowers it further, to 16.5%. Deleting that record brings re-issue back to 53.3%. The effect is strongest right after the run (4.9%) and fades as history accumulates.

The record also separates loops from reasonable retries. At retry points it lowers re-issue only from 68.4% to 51.7%, while a stated observation alone lowers it to 20.6% and blocks retries that are worth making. The executed record, together with what it returned, is what tells the policy whether an action is finished or worth checking again.

Trained policies. Both trained policies still tell loops from retries. With the record present, DeLoop re-issues a looping action in 8.3% of completions and DeLoop-Mix in 6.8%, against 36.1% and 38.0% at retry points. Deleting the record raises re-issue at looping points only to 20.7% and 23.9%, against 53.3% for the untrained model, while retries return to 54.2% and 56.1%. The trained policies thus avoid most loops even when the record of the earlier run is missing.

Compression Amplifies Exact Repetition Most

Our detector flags only exact repeats with an identical observation. We measure four broader signatures on the same CodeGym runs: near-duplicate calls (same tool, different arguments, with an identical observation or a small argument edit), argument thrash (A–B–A argument alternation within three calls), redundant observe (an action whose observation is already in context, word for word, from a different action), and productive repeats (the same action with a different observation). Table 26 gives the results.

SignatureTasks (%) FullTasks (%) Comp.Per action (%) FullPer action (%) Comp.Ratio (×\times)Trained, per action (%) DeLoopTrained, per action (%) DeLoop-MixFailure OR
Exact loop (our detector)28.657.06.624.83.772.32.51.62
Near-duplicate75.777.946.734.30.7319.023.70.68
Argument thrash3.33.40.40.30.920.10.23.10
Redundant observe52.356.321.122.51.076.77.70.69
Productive repeat30.039.28.910.71.215.97.62.00

Table 26. Repetition signatures under compression. Qwen3-8B on the 300 CodeGym evaluation tasks. Tasks: share of tasks with at least one event; per action: share of actions that are events, with the full history (Full) and under summarization at 4,096 tokens (Comp.); ratio: Comp./Full per action. The DeLoop and DeLoop-Mix columns are under summarization. Failure OR: odds ratio of task failure for tasks with the signature, with the full history. Rates are recomputed from the logged trajectories of three evaluation runs, and the exact-loop task shares differ slightly from the run averages in Table 1.

Exact loops are the signature that compression amplifies most. Under summarization, their share of actions rises 3.77×3.77\times, from 6.6% to 24.8%, while every broader signature changes by 0.73×0.73\times to 1.21×1.21\times. Near-duplicate and redundant-observe calls are common, in 77.9% and 56.3% of compressed tasks, but they behave like ordinary reprobing: with the full history they are more frequent in solved tasks (failure odds ratios 0.68 and 0.69). We therefore define the loop as exact repetition. Training lowers every signature per action, so the trained policies do not trade exact loops for near-duplicates: near-duplicate calls fall from 34.3% of actions to 19.0% under DeLoop and 23.7% under DeLoop-Mix.

Random Pairs Do Not Break the Loop

Does the loop label matter, or would any preference pair from the agent’s own rollouts do? We build a random-pair corpus from the compressed baseline’s CodeGym rollouts: each pair keeps a prompt and takes as its chosen and rejected actions two random later actions from the same rollout. We train on 877 random pairs and on random subsets of our 8,000 self-mined pairs with the same DPO recipe, match the number of optimizer updates to our main recipe (about 500), and evaluate on a separate 128-task held-out CodeGym set (Table 27).

Training dataPairsUpdatesLoop (%) ↓\downarrowSuccess (%) ↑\uparrowSteps ↓\downarrow
Compressed baseline——66.111.519.12
Random pairs877×\times1≈\approx5554.811.913.26
Random pairs877×\times9≈\approx49569.511.716.17
Self-mined pairs1,003×\times8≈\approx5049.423.45.82
Self-mined pairs4,012×\times2≈\approx5025.520.34.95
Self-mined pairs (DeLoop)8,000×\times1≈\approx5005.515.64.80

Table 27. Random-pair control. Qwen3-8B on another 128-task held-out CodeGym set under summarization at 4,096 tokens (Following setting from Kang et al. (2026)). Each row trains with the same DPO recipe; Pairs gives pairs ×\times epochs and Updates the number of optimizer updates. The compressed baseline is pooled over three evaluation runs.

At the same budget of about 500 optimizer updates, 1,003 self-mined pairs bring the loop rate to 9.4% and task success to 23.4%, while random pairs leave the loop rate at 69.5%, above the compressed baseline’s 66.1%, and task success at 11.7%. Training longer on random pairs makes looping worse, from 54.8% after one epoch to 69.5% after nine. With 4,012 self-mined pairs the loop rate reaches 5.5%, the same as DeLoop trained on all 8,000. What breaks the loop is the loop label, not preference training on the agent’s own rollouts.

The Loop-Breaking Action Matters

Each self-mined pair prefers the loop-breaking action to the looping action. To test what the chosen side adds, we keep the same 8,000 prompts, the same rejected actions, and the same recipe, and replace the chosen action in two ways: with a random action from the prompt’s own history, or with the chosen action of a random other pair, a plausible action from the wrong state (Table 28).

Chosen actionLoop (%) ↓\downarrowSteps ↓\downarrow
Compressed baseline (no training)57.014.91
Loop-breaking action (DeLoop)5.74.59
Random action from the same history41.98.17
Chosen action of another pair36.18.99

Table 28. Chosen-action controls. Qwen3-8B on the 300 CodeGym evaluation tasks under summarization at 4,096 tokens. All trained rows use the same prompts, rejected actions, and DPO recipe and differ only in the chosen action. Rows are recomputed from the logged trajectories of three evaluation runs and differ slightly from the run averages in Table 1.

The loop-breaking action carries more than “anything but the looping action”. With a random chosen action, the loop rate stays at 41.9% (random action from the history) and 36.1% (chosen action of another pair), against 5.7% with the loop-breaking action. Together with Table 2, this shows that both sides of each pair carry the signal.

Additional Analyses

This section reports four further analyses of the runs behind Table 1 and Figure 3. None of them needs new rollouts.

Loops on Calls Still in Context

Our loop rate compares each call with every earlier call in the run. Under compression, some of those earlier calls are no longer in the agent’s context word for word, because the harness has replaced them with a summary. We therefore also count a loop only when the earlier call and its observation are still in the context the agent sees. We rebuild this context at every step from the compression events in the logs (Section D).

DeLoop removes loops whether or not the earlier call is still in context (Table 29). Counting only repeats of calls still in context, DeLoop lowers the loop rate of Qwen3-8B on CodeGym from 25.2% to 3.2%. For repeats of calls that had been sum-

PolicyLoop rateIn contextSummarized
Compressed baseline57.325.232.1
DeLoop6.13.22.9
DeLoop-Mix10.14.35.8
Full history29.029.0–

caption: tbl:29: Loops by availability of the earlier record. Loop rate (%) of Qwen3-8B on CodeGym under summarization at 4,096 tokens, averaged over three runs; the full-history agent uses no compression. A run counts under In context if it repeats a call that is still in its context, and under Summarized if every call it repeats had been summarized.

PolicyTasks (%)Per taskLoop (%)StepsSuccess (%)
Compressed baseline69.85.2957.315.0025.1
Duplicate blocker71.34.775.714.7125.3
DeLoop13.60.386.14.6725.9
DeLoop + blocker13.70.251.34.8427.7

caption: Table 30: Proposed repeats and executed loops with a duplicate blocker. Qwen3-8B on CodeGym under summarization at 4,096 tokens; three runs for the compressed baseline and DeLoop, one run for each blocker row. Repeat proposals: tasks in which the agent proposes a call it has already run, and such proposals per task. Loop: loops among the calls that run (§ 2.1).

marized, it lowers the rate from 32.1% to 2.9%. The split also shows where compression adds loops. The compressed agent repeats a call that is still in its context in 25.2% of runs, close to the 29.0% loop rate of the full-history agent. The added loops come from calls that the harness has summarized, even though the summarization prompt asks the model to keep executed actions and their results (Section D).

The Duplicate Blocker

The exact duplicate blocker refuses to run a call that repeats an earlier one and returns the earlier result with a warning instead (Section G.9). Its loop rate in Table 18, 46.7%, counts these refused calls, since they never run. Counting only the calls that run, as for the other rows, its loop rate is 5.7%. Neither number shows what the agent does, so we also count how often it proposes a call it has already run (Table 30).

The blocker does not change what the agent

proposes. With the blocker, Qwen3-8B proposes an already executed call in 71.3% of tasks, close to the 69.8% without it, and steps and success barely move. The agent still generates every refused call in full, so the blocker saves no model compute: it uses 24.9k tokens per task, against 23.9k without it and 12.7k for DeLoop (Table 18). DeLoop lowers repeat proposals to 13.6% of tasks and cuts steps per task from 15.00 to 4.67.

The two methods are complementary. The blocker stops the few repeats that DeLoop still proposes, and DeLoop removes most of the calls that the blocker would refuse only after they are generated. With the blocker on, DeLoop runs a repeated call in 1.3% of tasks, uses 12.8k tokens per task, and solves 27.7% of them in a single run.

ModelTasksNoneSumm.NoneSumm.
Same tasksAll tasks
Gemini 3.5 Flash-Lite19140.847.134.036.0
Gemini 3.1 Flash22646.565.540.052.7
Gemini 3.1 Pro13933.161.921.334.3

caption: tbl:31: Gemini loop rates on matched task sets. Loop rate (%) on CodeGym without compression (None) and with summarization at 1,400 tokens (Summ.). Same tasks: the tasks on which compression fired in the summarization run. One run per model and setting.

Gemini Models on the Same Tasks

Figure 3b compares each Gemini model’s full-history run with the episodes of its summarization run in which compression fired. Compression fires only in longer episodes, and longer episodes loop more often even without compression. We therefore also compare the two runs on the same tasks, the ones on which compression fired (Table 31).

Compression raises the loop rate of every model on the same tasks. Gemini 3.1 Pro loops in 61.9% of these tasks with compression and in 33.1% without it, 1.9× as often (2.9× in Figure 3b). The ratio is 1.4× for Gemini 3.1 Flash and 1.2× for Gemini 3.5 Flash-Lite. Comparing against full-history episodes long enough for compression to fire gives similar ratios (1.8×, 1.4×, and 1.1×). Over all 300 tasks, including short episodes in which compression never fires, the ratios are 1.6×, 1.3×, and 1.1×.

Fewer Loops Are Not Just Shorter Episodes

DeLoop shortens episodes from 15.00 to 4.67 steps (Table 1), and a shorter episode has fewer chances to loop. We therefore measure looping in two ways that do not depend on episode length.

First, we compute the loop hazard: among the steps that episodes reach at a given step index, the share that are looping actions (Table 32). DeLoop lowers it at every step index, from 22.3% to 4.1% at steps 5–9 and from 32.8% to 7.0% at steps 10–14. Second, we compare episodes of similar length. Among episodes of 6–10 steps, the loop rate falls from 33.2% to 13.1%, and among episodes of 11–20 steps from 69.1% to 29.2%.

Policy0–45–910–1415–19
Compressed baseline4.122.332.842.8
DeLoop0.84.17.025.7
DeLoop-Mix1.83.64.57.3
Full history2.36.811.313.9

Table 32. Loop hazard by step index. Loop hazard (%): the share of steps that are looping actions among the steps an episode reaches, by step index. Qwen3-8B on CodeGym under summarization at 4,096 tokens (full history: no compression), pooled over three runs per policy.

DeLoop also answers earlier without losing accuracy on those tasks. It answers within four steps on average on 164 of the 300 tasks. On these tasks it solves 30.1% of runs in 2.7 steps, and the compressed baseline solves the same 30.1% in 13.0 steps (paired difference +0.0 points, 95% bootstrap interval over tasks [−6.3, +6.1]). The result is similar with a cutoff of three to six steps.

References

  1. [1]ing from human preferences. arXiv preprint arXiv:2310.12036, 2024.arxiv.org/abs/2310.12036
  2. [2]S. Barke, A. Goyal, A. Khare, A. Singh, S. Nath, and C. Bansal. AgentRx: Diagnosing AI agent failures from execution trajectories, 2026. URL https://arxiv.org/abs/2602.02475.
  3. [3]M. Cemri, M. Z. Pan, S. Yang, L. A. Agrawal, B. Chopra, R. Tiwari, K. Keutzer, A. Parameswaran, D. Klein, K. Ramchandran, M. Zaharia, J. E. Gonzalez, and L. Stoica. Why do multi-agent LLM systems fail? In Advances in Neural Information Processing Systems, Datasets and Benchmarks Track, 2025. URL https://proceedings.neurips.cc/paper_files/paper/2025/file/b1041e52d3be19f0a9bc491657488e4a-Paper-Datasets_and_Benchmarks_Track.pdf.arxiv.org/abs/2503.13657
  4. [4]B. Chen, C. Shu, E. Shareghi, N. Collier, K. Narasimhan, and S. Yao. FireAct: Toward language agent fine-tuning. arXiv preprint arXiv:2310.05915, 2023.arxiv.org/abs/2310.05915
  5. [5]Y. Chen and A. Yuille. Agentic-DPO: From imitation to agentic policy optimization on expert trajectories. arXiv preprint arXiv:2607.10601, 2026.
  6. [6]Y. Chen, H. Lai, Y. Feng, C. Han, Q. Zhang, B. Lu, M. Li, X. Wang, Z. Wang, S. Xu, Z. Li, Z. Jin, H. Wu, C. Li, and Q. Chen. Beyond semantic organization: Memory as execution state management for long-horizon agents, 2026. URL https://arxiv.org/abs/2606.06090.
  7. [7]Z. Chen, X. Ma, S. Zhuang, P. Nie, K. Zou, A. Liu, J. Green, K. Patel, R. Meng, M. Su, S. Sharifymoghaddam, Y. Li, H. Hong, X. Shi, X. Liu, N. Thakur, C. Zhang, L. Gao, W. Chen, and J. Lin. BrowseComp-Plus: A more fair and transparent evaluation benchmark of deep-research agent. arXiv preprint arXiv:2508.06600, 2025.
  8. [8]D. Deshpande, V. Gangal, H. Mehta, J. Krishnan, A. Kannappan, and R. Qian. TRAIL: Trace reasoning and agentic issue localization. arXiv preprint arXiv:2505.08638, 2025.arxiv.org/abs/2505.08638

Paper details

vlnc:W_jjbqp88y
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents