arXiv:2610.01108cs.CLOct 2026

Manuscript Offprint

arXiv:2610.01108

AgSpec: Pushing the Limits of Retrieval-Based Speculative Decoding in Coding Agent Pipelines

Sumin Lee, Sukmin Cho, Suengjae Lim, Youngjin Kwon

ABSTRACT

Retrieval-based speculative decoding (SD) drafts tokens by copying continuations from existing text, which suits coding agents that repeatedly reproduce code, logs, and earlier attempts. Yet existing methods fall short in agent pipelines: much of the reusable text is missing from their corpora or stored in a form that differs from what the agent emits, and their draft lengths ignore that accept length varies across agents and drifts over turns. We present AGSPEC, a framework that supplies the corpus and draft-length policies that existing retrieval engines lack in coding-agent pipelines. AGSPEC retrieves from session, workspace, and global corpora, retaining the ongoing session trajectory and indexing opened files in the agent's emission format. It bounds each agent's draft length with an offline-profiled cap and adapts the length online from verification feedback. On two repository-level multi-agent coding benchmarks, AGSPEC outperforms five retrieval-based drafters and EAGLE-3 in most evaluated settings, raising generation throughput over autoregressive decoding up to 4.37×4.37\times at batch size 1 and 4.76×4.76\times at batch size 16. AGSPEC also remains effective on benchmarks without a repository or a multi-agent pipeline, showing that its gains generalize to coding agents broadly.

1 INTRODUCTION

Coding agents have become a representative LLM application (Liu et al., 2026a). Unlike a chatbot, a coding agent handles a single user request as a multi-turn session that alternates between model calls and tool execution (Yang et al., 2024). Within a session, the work is often divided among specialized agents, such as a coder that edits files and an executor that runs tests and scripts to check the result (Hong et al., 2024). As user requests have shifted from synthesizing a single function (Chen et al., 2021) to resolving repository-level issues (Jimenez et al., 2024), agents rarely succeed in one pass and instead refine their attempts over multiple turns (Madaan et al., 2023). Each additional turn can improve the output, but it also lengthens the time a user waits for the result (Tiwari et al., 2026).

Speculative decoding (SD) attacks this cost directly, reducing decoding latency without changing the output (Chen et al., 2023). In SD, a drafter proposes several tokens, and the target model verifies them in parallel and commits the accepted tokens. Each accepted token saves a sequential target-model step. This saving comes at the cost of generating draft tokens and verifying tokens that are later rejected. Rejected tokens are nearly free at small batch sizes but become expensive at large batch sizes, where verification demands much more compute (Liu et al., 2024; Sadhukhan et al., 2025). SD thus pays off only when the drafter is both cheap and accurate. Existing designs range from small draft models (Leviathan et al., 2023) and trained draft heads (Li et al., 2025) to retrieval-based SD, which retrieves draft tokens from a text corpus.

Retrieval-based SD is particularly effective for code generation (Liu et al., 2026b). It copies continuations from text the system already has, such as the current prompt, earlier responses, or a prebuilt datastore, without running a separate draft model. Code suits this copying, since identifiers, code fragments, and repository conventions recur, and coding-agent sessions offer still more of it, as repeated subtasks and refinement loops produce long, predictable sequences. However, previous

Figure

(c) decoding speedup, b=16

Figure 1: (a) Accept length when restoring availability, then matchability. (b) Achievable accept length for Gemma3-27B, taking the best available continuation at each step. Markers are medians and bars the interquartile range. (c) Decoding throughput of SAM-Decoding and AGSPEC-SAM relative to no speculation for Gemma3-27B. All data is from SWE-bench Verified.

works do not elicit the full performance of retrieval-based SD at coding agents. They overlook what makes a coding agent different, and leave much of that reuse out of reach.

A draft helps only if two conditions hold: the text the agent reuses must be available in the corpus, and it must be matchable against what the agent generates. Existing corpora fall short on both. First, they limit availability: they hold either a prebuilt datastore or the text of the current call, whereas coding agents reuse text from the ongoing session and the repository. A file drops out of reach once the prompt truncates it, and a retry cannot draw on the previous attempt once its call ends; covering these requires corpora that span the session and the repository. Second, they limit matchability: they store text as the agent read it, yet a coder emits a patch whose copied lines each carry a diff prefix absent from the file. Fig. 1(a) shows that expanding retrieval scope raises accept length on every model, with the largest gain from session history and smaller additional headroom from repository history and emission-form indexing.

Even when a reusable match exists, choosing the draft length remains critical, as it directly determines how many drafted tokens are rejected. Existing methods fix the draft length policy before a session runs, deriving it from a static cap (Saxena, 2023; Hu et al., 2025; He et al., 2024; Zhao et al., 2025) or from properties of the match such as its length (Oliaro et al., 2025) or occurrence count (He et al., 2024; Zhao et al., 2025; Oliaro et al., 2025). However, in coding agents, the achievable accept length follows the agent pipeline. Fig. 1(b) shows that each agent occupies a distinct accept-length range that shifts differently across and within turns. Each agent and context thus has a characteristic accept length, which can guide the draft length better than a fixed or match-derived policy.

These limitations stem not from how existing methods match text but from the policies around the matching. A retrieval-based SD method pairs a retrieval engine that finds a continuation for the current context (e.g., a suffix tree in SuffixDecoding (Oliaro et al., 2025)) with policies that decide what the corpus holds and how many tokens to draft. Existing policies are built around the individual request, the unit an inference engine serves: they index the current call, a prebuilt datastore, or outputs pooled across requests (Saxena, 2023; He et al., 2024; Oliaro et al., 2025), and size drafts by a static cap or the match itself. In a coding agent, however, reuse and acceptance depend on structure above the request, namely the session, the repository, and the role of each agent.

We present AGSPEC, a retrieval-based SD framework that builds its policies on this structure while leaving the engine unchanged, so it applies to existing engines as is. AGSPEC realizes each policy with a simple yet effective design. (1) Coding-agent-aware retrieval. For the corpus, AGSPEC organizes text by origin into session, workspace, and global reference corpora. The workspace corpus indexes the artifacts a session opens, in full and in the forms the agent emits. (2) Agent-aware draft-length control. For the draft length, AGSPEC profiles agent-specific accept lengths offline to set per-agent draft caps, and learns a draft-length scale that adapts the length per turn and per request from verification feedback.

We compare AGSPEC against AR decoding, five retrieval-based SD methods (Saxena, 2023; He et al., 2024; Oliaro et al., 2025; Hu et al., 2025; Zhao et al., 2025), and EAGLE-3 (Li et al., 2025) on two repository-level benchmarks, SWE-bench and TeamBench (Jimenez et al., 2024; Kim et al., 2026). AGSPEC consistently outperforms most baselines. Especially, with SAM-Decoding as its retrieval engine, AGSPEC raises the speedup of Gemma3-27B on SWE-bench over AR decoding from 2.72×2.72 \times to 3.61×3.61 \times at batch size 16 (Fig. 4). AGSPEC also generalizes beyond this setting, achieving the highest throughput on single-agent and non-repository benchmarks. These results highlight the effectiveness of AGSPEC as a training-free acceleration framework for coding agent applications.

References (53)