arXiv(opens in a new tab)cs.LGSep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.05274

How to Speculate about Uncertainty in Agentic Coding? A Draft-Model Gate Method

Konstantin Grotov, Valentin Malykh

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

LLM agents deployed for software engineering fail expensively: they act confidently wrong, and bad actions are recognized only after costly execution and retry. We present Speculative Uncertainty (SU), a method that recovers a predictive failure signal for a black-box agent from its output tokens alone, with no access to logits, weights, activations, or repeated sampling. Inverting speculative decoding, a small open-weight draft model scores the agent's already-generated trajectory in a single forward pass. From these speculative cross-likelihoods we extract phase-aware features by separating the reasoning and action spans, and calibrate them against a verifiable objective. SU produces a failure-likelihood score that any downstream policy, such as routing, human intervention, or extra test-time compute, can consume directly. To show the signal is actionable, we instantiate one such policy, a pre-execution veto gate, on software engineering agents Qwen3-Coder-480B and closed-source Claude 3.5 Sonnet, cutting execution error rate by 6–8 percentage points and token cost by 14–19% in deployment, transferring to out-of-distribution benchmarks without retraining, and generalizing across agent models.

1 Introduction

LLM agents are increasingly deployed in production software engineering workflows, where they autonomously draft patches, run tests, and query databases (Jimenez et al., 2024; Badertdinov et al., 2026; Yang et al., 2026). Yet behind strong benchmark scores lies an expensive failure mode: agents are often confidently wrong (Kaddour et al., 2026). They propose an action with no signal that it could fail, and the failure appears only when an environment rejects it—after the code has run, the context has been filled up, and the retry has been paid for. At production scale, these silent failures inflate API

cost and latency, since a rejected action is appended to the context and the agent pays for the retry — frequently looping on the same problem until the budget is exhausted (Kaddour et al., 2026).

Two properties of realistic deployments constrain the space of admissible methods. First, the most capable deployed agents are closed API-served models exposing no logits, weights, or activations, so any method that needs internal signals is something that we cannot use for models. Second, sampling-based uncertainty estimators require many generations per step, which is prohibitive at agentic horizons. Taken together, these requirements rule out most of the uncertainty-quantification toolbox: single-turn calibration ignores features specific to the trajectories (Guo et al., 2017; Kuhn et al., 2023), white-box probing needs internal access, whereas sampling is too costly. The closest prior work, Holistic Trajectory Calibration (HTC) (Zhang et al., 2026), fits a calibrator on an agent's full log-probability sequence. However, it still assumes white-box access and treats the trajectory as a homogeneous token stream. Both assumptions break in the real deployments we care about.

We address the access constraint with an idea inverted from speculative decoding (Leviathan et al., 2023; Chen et al., 2023): rather than having a small draft model propose tokens to accelerate a large one, we have it score the large agent's already-generated tokens via teacher-forced cross-likelihood. The agent doesn't share its internal state, the draft reads only its output text and recovers a rich uncertainty signal in a single forward pass. We empirically observed that agent generation has a phase structure: a high-entropy reasoning phase is followed by a sharply lower-entropy action phase pinned down by syntax and tool-call structure. Averaging over the whole trajectory, as HTC does, dissolves this failure-relevant signal into the noise of the reasoning phase, while reading the two

  • Corresponding author.

phases apart surfaces it.

Combining these considerations, we shape the method of Speculative Uncertainty (SU): a small draft scores the agent's trajectory, phase-aware features are extracted separately from reasoning and action spans, and a linear calibrator maps them to a probability that the next action will follow the verifiable objective. We study code execution in software engineering agents, but the approach applies to any agent producing reasoning-then-action trajectories under a verifiable objective.

This study shows that the uncertainty of a black-box agent can be recovered from its trajectory alone, before the environment is ever called, and that the recovered signal is reliable enough to act positively in deployment. We insert a lightweight gate between code generation and execution that predicts whether the next action will be executed without exceptions. When failure is likely, this triggers a cheap replan instead of an expensive execute-fail-retry cycle. On two agentic coding benchmarks (Jimenez et al., 2024; Huang et al., 2024) the gate cuts per-call execution error rate by 6-8 percentage points and average token cost by 14–19%, with gains transferring to an out-of-distribution benchmarks.

References (16)