SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Ma, George, Koul, Anurag, Chen, Qi, Wu, Yawen, Kuhar, Sachit, Yu, Yu, Sengupta, Aritra, Kumar, Varun, Ramanathan, Murali Krishna
Format: Preprint
Veröffentlicht: 2025
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866908984335663104
author Ma, George
Koul, Anurag
Chen, Qi
Wu, Yawen
Kuhar, Sachit
Yu, Yu
Sengupta, Aritra
Kumar, Varun
Ramanathan, Murali Krishna
author_facet Ma, George
Koul, Anurag
Chen, Qi
Wu, Yawen
Kuhar, Sachit
Yu, Yu
Sengupta, Aritra
Kumar, Varun
Ramanathan, Murali Krishna
contents Large Language Models (LLMs) excel at code-related tasks but often struggle in realistic software repositories, where project-specific APIs and cross-file dependencies are crucial. Retrieval-augmented methods mitigate this by injecting repository context at inference time. The low inference-time latency budget affects either retrieval quality or the added latency adversely impacts user experience. We address this limitation with SpecAgent, an agent that improves both latency and code-generation quality by proactively exploring repository files during indexing and constructing speculative context that anticipates future edits in each file. This indexing-time asynchrony allows thorough context computation, masking latency, and the speculative nature of the context improves code-generation quality. Additionally, we identify the problem of future context leakage in existing benchmarks, which can inflate reported performance. To address this, we construct a synthetic, leakage-free benchmark that enables a more realistic evaluation of our agent against baselines. Experiments show that SpecAgent consistently achieves absolute gains of 9-11% (48-58% relative) compared to the best-performing baselines, while significantly reducing inference latency.
format Preprint
id arxiv_https___arxiv_org_abs_2510_17925
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion
Ma, George
Koul, Anurag
Chen, Qi
Wu, Yawen
Kuhar, Sachit
Yu, Yu
Sengupta, Aritra
Kumar, Varun
Ramanathan, Murali Krishna
Software Engineering
Artificial Intelligence
Large Language Models (LLMs) excel at code-related tasks but often struggle in realistic software repositories, where project-specific APIs and cross-file dependencies are crucial. Retrieval-augmented methods mitigate this by injecting repository context at inference time. The low inference-time latency budget affects either retrieval quality or the added latency adversely impacts user experience. We address this limitation with SpecAgent, an agent that improves both latency and code-generation quality by proactively exploring repository files during indexing and constructing speculative context that anticipates future edits in each file. This indexing-time asynchrony allows thorough context computation, masking latency, and the speculative nature of the context improves code-generation quality. Additionally, we identify the problem of future context leakage in existing benchmarks, which can inflate reported performance. To address this, we construct a synthetic, leakage-free benchmark that enables a more realistic evaluation of our agent against baselines. Experiments show that SpecAgent consistently achieves absolute gains of 9-11% (48-58% relative) compared to the best-performing baselines, while significantly reducing inference latency.
title SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion
topic Software Engineering
Artificial Intelligence
url https://arxiv.org/abs/2510.17925