Agents Learn Their Runtime: Interpreter Persistence as Training-Time Semantics

Victor May, Aaditya Salgarkar, Yishan Wang, Diganta Misra, Huu NguyenarXiv 2026 · arXiv

TL;DR

This paper investigates whether interpreter persistence—the ability of an LLM agent's coding environment to retain variables across turns—is a fundamental property absorbed during training or merely an inference-time convenience. Through a controlled 2×2 study, the authors demonstrate that mismatching training and deployment runtime semantics doesn't significantly impact final solution quality, but it severely penalizes efficiency and stability. Misaligned agents either waste massive token budgets re-deriving state (an "amnesia tax") or collapse into destructive error loops.

What Problem Does This Paper Address?

Many state-of-the-art LLM agent frameworks (like CodeAct) allow agents to interact with a persistent Python interpreter, meaning variables and data structures defined in Turn 1 remain accessible in Turn 3. However, the synthetic datasets used to fine-tune these models rarely make this environmental assumption explicit.

This creates a blind spot: Do LLM agents actually learn and rely on the persistence of their runtime environment during post-training, or is persistence just an execution scaffold? Understanding this alignment matters because developers frequently train models in one environment setup and deploy them in another, unaware of how subtle runtime mismatches might alter agent behavior.

Methods

The authors design a rigorous 2×2 cross-evaluation study that isolates interpreter persistence as a training-time variable. They hold the base model (Qwen3-8B), prompts, tools, and task instances completely fixed, while manipulating two dimensions:

  1. Training Semantics: Fine-tuning on trajectories generated with a persistent interpreter vs. a stateless (reset each turn) interpreter.
  2. Runtime Semantics: Evaluating the fine-tuned models in a persistent vs. stateless deployment environment.

To ensure fair comparison, the runtime explicitly exposes metadata about active global variables to the agent in both setups, isolating the actual execution mechanics from pure observability.

Figure 1: Interpreter persistence as an execution semantic for tool-augmented agents. (Top) OPAQUE KNAPSACK hides item attributes and feasibility constraints behind a budgeted tool API, forcing multi-turn inspection and plan revision rather than a single one-shot script. (Bottom) Example rollout for the same task instance under two deployment runtimes. With a persistent interpreter (left), variables defined by earlier actions remain live and the agent can accumulate and reuse executable state across turns (e.g., items, inspect_data). With a stateless interpreter (right), globals are cleared after each step while the text history remains; a policy trained under persistence may still reference prior bindings, producing missing-variable (NameError) failures and costly reconstruction loops. We quantify how these behaviors depend on train–runtime alignment in a controlled 2×2 study (persistent vs. stateless traces × persistent vs. stateless runtime).

Datasets

The authors introduce OPAQUE KNAPSACK, a procedurally generated, partially observable optimization benchmark. Unlike standard tool-use tasks that can be solved with a single long script, this environment hides item weights, values, and class constraints behind a budgeted tool API (list_items, inspect, take_item).

Because information acquisition is budget-limited and feedback-driven, the task is strictly "non-collapsible"—agents are forced to iteratively gather information, track state, and revise plans over multiple turns. The dataset consists of 1,000 Easy instances for training and 100 Hard instances for testing difficulty generalization.

Key Insights and Ideas

  • Persistence is a Learned Prior, Not Just a Prompt: When a persistent-trained model is forced into a stateless runtime, it doesn't adapt dynamically—even when explicitly shown stateless few-shot examples. It continues to guess and reference old variables, proving that execution semantics are absorbed as a deep behavioral prior during fine-tuning.
  • The "Amnesia Tax": Stateless-trained models carry an ingrained habit of text-based state reconstruction. When deployed in a persistent runtime, they completely fail to exploit the interpreter's memory. Instead, they redundantly re-import libraries and re-define variables on every single step, incurring a massive token overhead.
  • Productive Externalization vs. Destructive Thrashing: While both a stateless-aligned agent and a mismatched persistent-to-stateless agent consume high token volumes, they do so for opposite reasons. The stateless agent uses tokens productively to rebuild state via text. The mismatched persistent agent wastes its token budget on cascading recovery loops trying to fix NameError exceptions.

Key Results

  • Solution Quality is Unaffected: Surprisingly, across all four train-runtime combinations, there was no statistically significant difference in final solution optimality. Interpreter persistence shapes how agents reach solutions, not whether they do.
  • Massive Token Savings: On Hard tasks, the aligned persistent configuration (Persistent $\rightarrow$ Persistent) is highly efficient, requiring roughly 3.5× fewer tokens than the aligned stateless configuration (67,898 vs. 18,612 tokens).
Figure 2: Cost–performance tradeoff under persistent vs. stateless runtime. The y-axis reports mean normalized optimality (percentage of the ground-truth optimal value). The x-axis reports total tokens generated per episode (log scale). Removing runtime persistence substantially increases token cost with modest impact on normalized optimality.
  • High Error Rates in Mismatched Deployments: Deploying a persistent-trained model in a stateless environment triggers missing-variable errors (NameError) in ~80% of episodes, frequently causing the agent to enter cascading execution failures that consume its entire turn budget.

Limitations and Future Work

The authors note several limitations in their current study:

  • Evaluation Power: The sample size ($n = 100$ tasks per split) is sufficient to expose massive behavioral and efficiency shifts, but underpowered to detect subtle differences in absolute solution optimality.
  • Token-Budget Confounds: Matching training sets by episode count meant that the stateless-trained model was exposed to substantially more raw text during training (~3.5×). Future work should ablate token-matched training budgets.
  • Scope of Generalization: The findings are currently bounded by a single task family (Opaque Knapsack) and a single base model (Qwen3-8B). Testing across varied agent architectures and diverse benchmarks remains an important next step.

Summary updated

Abstract

Tool-augmented LLMs are increasingly deployed as agents that interleave natural-language reasoning with executable Python actions, as in CodeAct-style frameworks. In deployment, these agents rely on runtime state that persists across steps. By contrast, the traces used to post-train these models rarely encode how interpreter state is managed. We ask whether interpreter persistence is merely a runtime scaffold, or a property of the training data that shapes how agents learn to use the interpreter. We isolate state persistence as a training-time variable. We introduce Opaque Knapsack, a procedurally generated family of partially observable optimization tasks designed to prevent one-shot solutions. Item attributes and constraints are hidden behind budgeted tool calls, forcing multi-turn control flow and iterative state revision. Holding task instances, prompts, tools, model, and supervision fixed, we generate matched trajectories differing only in whether interpreter state persists across steps or resets after each action. We then fine-tune identical base models (Qwen3-8B) on each trace variant and evaluate all four train-runtime combinations. Our 2x2 cross-evaluation shows that interpreter persistence shapes how agents reach solutions, not whether they do: solution quality is statistically indistinguishable across conditions, but token cost and stability differ substantially. A persistent-trained model in a stateless runtime triggers missing-variable errors in roughly 80% of episodes; a stateless-trained model in a persistent runtime redundantly re-derives retained state, using roughly 3.5x more tokens. Interpreter persistence should be treated as a first-class semantic of agent traces. Aligning fine-tuning data with deployment runtimes improves efficiency and reduces brittle train-runtime mismatches.
BibTeX
@misc{may2026agents,
  author = {Victor May and Aaditya Salgarkar and Yishan Wang and Diganta Misra and Huu Nguyen},
  title = {{Agents Learn Their Runtime: Interpreter Persistence as Training-Time Semantics}},
  year = {2026},
  eprint = {2603.01209},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.01209},
}
Figure