CaveAgent: Transforming LLMs into Stateful Runtime Operators

Maohao Ran, Zhenhua Wan, Cooper Lin, Yanting Zhang, Hongyu Xin, Hongwei Fan, Yibo Xu, B. Luo, Yaxin Zhou, Wangbo Zhao, Lijie Yang, Lang Feng, Fuchao Yang, Jingxuan Wu, Yiqiao Huang, Chendong Ma, Dailing Jiang, Jianbo Deng, Sihui Han, Bo An, Yike Guo, Jun Song

Abstract

LLM-based agents are increasingly capable of complex task execution, yet current agentic systems remain constrained by text-centric paradigms that struggle with long-horizon tasks due to fragile multi-turn dependencies and context drift. We present CaveAgent, a framework that shifts tool use from "LLM-as-Text-Generator" to "LLM-as-Runtime-Operator." CaveAgent introduces a dual-stream architecture that inverts the conventional paradigm: rather than treating the LLM's text context as the primary workspace with tools as auxiliary, CaveAgent elevates the persistent Python runtime as the central locus of state, with a lightweight semantic stream serving as its orchestrator. Beyond leveraging code generation to resolve interdependent sub-tasks (e.g., loops, conditionals) in a single step, CaveAgent introduces Stateful Runtime Management: it injects, manipulates, and retrieves complex Python objects (e.g., DataFrames, database connections) that persist across turns, unlike existing code-based approaches that remain text-bound. CaveAgent further provides a runtime-integrated skill management system that extends the Agent Skills open standard, enabling ecosystem interoperability through executable skill injections. This persistence mechanism serves as a high-fidelity external memory that reduces context drift in multi-turn interactions and preserves processed data for downstream applications without information loss. Evaluations show consistent improvement across challenging benchmarks, enabling CaveAgent to handle data scales that cause context overflow in both JSON-based and code-based agents. The accessible runtime state further provides programmatically verifiable feedback, enabling automated evaluation and reward signal generation without human annotation and establishing a structural foundation for future research in Reinforcement Learning with Verifiable Rewards (RLVR).

1. Introduction

Most contemporary LLM agents interact with external tools using a JSON-centric paradigm. In this model, the LLM generates a JSON string, the system executes the corresponding function, and the result is serialized back into text for the LLM to process in the next turn. This architecture introduces three critical bottlenecks:

  1. Statelessness: Every turn is an isolated transaction. Intermediate results must be constantly re-serialized, consuming token limits and causing context degradation.
  2. Rigid Control Flow: Executing loops or conditionals requires multiple error-prone dialogue turns.
  3. The Textualization Bottleneck: Complex data structures, such as massive DataFrames or database connections, cannot be converted to text without significant information loss or context window overflow.

CaveAgent addresses these issues by shifting from stateless text generation to stateful runtime manipulation.

2. The CaveAgent Framework

CaveAgent fundamentally inverts the standard agent paradigm by making a persistent Python runtime the central hub of the system. It utilizes a dual-stream architecture consisting of a Semantic Stream, where the LLM acts as a lightweight orchestrator generating Python code, and a Runtime Stream, a persistent kernel that executes code and stores state across turns.

Code-based initialization of a shared Python runtime and object injection.

Through Stateful Runtime Management, CaveAgent injects complex Python objects directly into the runtime. The LLM manipulates these objects via code and stores intermediate results as variables in memory. This allows the LLM to see only lightweight metadata and execution summaries, achieving massive "context compression." Furthermore, CaveAgent extends the Agent Skills standard to inject executable artifacts directly into the runtime upon activation.

3. Experimental Evaluation

CaveAgent was evaluated across several rigorous benchmarks:

  • Tau²-bench: A multi-turn tool-use benchmark where CaveAgent outperformed traditional JSON-based calling in 11 out of 12 settings, boosting the success rate of Qwen3-Coder (30B) by 13.5%.
  • Berkeley Function Calling Leaderboard (BFCL): DeepSeek-V3.2's performance jumped from 53.1% to 94.0% due to the native support for sequential statements in Python code.
  • Stateful Management Benchmark: A new benchmark testing variable persistence. In IoT and finance scenarios, CaveAgent reduced token consumption by 28.4% and required 38.6% fewer steps.
  • Data-Intensive Scenario: On stock market analysis tasks, CaveAgent achieved 100% accuracy using ~120K tokens, while JSON-based baselines failed (10% success) due to context overflow, even after consuming 1.3 million tokens.

4. Discussion: State-as-Memory and Verifiability

By maintaining heavy data in the Python runtime and passing only variable names to the LLM, the runtime acts as a high-fidelity external memory. This programmatic state allows for deterministic inspection using code assertions, which is a significant advancement for Reinforcement Learning with Verifiable Rewards (RLVR).

Dynamic state updates and multi-agent reasoning within the CaveAgent runtime.

Furthermore, CaveAgent enables lossless multi-agent coordination. Instead of agents communicating via lossy text messages, they can share a runtime or inject native Python objects into each other's environments, shifting the paradigm from "communication by talking" to "communication by shared state."

5. Conclusion

CaveAgent demonstrates that treating the LLM as a runtime operator significantly improves efficiency and success rates in complex tasks. While currently constrained to Python-callable tools and requiring careful memory management for long sessions, it establishes a structural foundation for future research in verifiable rewards and stateful multi-agent systems.

Summary updated

BibTeX
@misc{ran2026caveagent,
  author = {Maohao Ran and Zhenhua Wan and Cooper Lin and Yanting Zhang and Hongyu Xin and Hongwei Fan and Yibo Xu and B. Luo and Yaxin Zhou and Wangbo Zhao and Lijie Yang and Lang Feng and Fuchao Yang and Jingxuan Wu and Yiqiao Huang and Chendong Ma and Dailing Jiang and Jianbo Deng and Sihui Han and Bo An and Yike Guo and Jun Song and Jun Song},
  title = {{CaveAgent: Transforming LLMs into Stateful Runtime Operators}},
  year = {2026},
  eprint = {2601.01569},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.01569},
}
Figure