让AI实验时记住历史,减少重复读取,大幅节省计算资源。
Remember, Don't Re-read: Stateful ReAct Agents for Token-Efficient Autonomous Experimentation

- 用可持久化状态替代每次重读,实现高效迭代。
- 超参调优少用90%令牌,代码优化少用52%令牌。
- 适合需要长期实验的开发者,降低算力开销。
自研究(autoresearch)模式通过大语言模型(LLM)迭代修改代码以优化目标指标。然而其无状态设计在每轮迭代中需从头重建实验上下文,导致每轮消耗$O(n)$令牌,总计$O(n^{2})$。本文将该模式重构为基于LangGraph的状态化ReAct代理,通过类型化持久状态经工具调用接口传递实验历史。评估两个基准任务:超参调优(15轮,单轮观测小)与代码性能优化(40轮,单轮观测包含完整源码和测试结果)。在超参调优中,状态化代理令牌消耗减少90%(2,492 vs. 24,465);在代码优化中减少52%(627K vs. 1,275K),且优化质量相当。该节省为结构性优势:无状态代理每轮$O(n)$读取历史,而状态化代理在固定窗口内以$O(1)$成本运行。本文详细描述架构,供实践者复现自有工作流中的状态化自研究代理。
原文摘要 · Abstract (English)
The autoresearch pattern enables autonomous experimentation by having a large language model (LLM) iteratively modify code to optimize a target metric. Its stateless design, however, reconstructs experimental context from scratch at every iteration, incurring $O(n)$ token cost per iteration and $O(n^{2})$ total. This work reformulates the pattern as a stateful ReAct agent using LangGraph, where typed persistent state carries experimental history across iterations via a tool-calling interface. Two benchmarks are evaluated: hyperparameter tuning (15 iterations, small per-iteration observations) and code performance optimization (40 iterations, large per-iteration observations containing full source code and benchmark results). On hyperparameter tuning, the stateful agent consumes 90\% fewer tokens (2{,}492 vs.\ 24{,}465). On code optimization, the stateful agent consumes 52\% fewer tokens (627K vs.\ 1{,}275K) while achieving comparable optimization quality on both tasks. The token reduction is structural: the stateless agent re-reads the full history at $O(n)$ cost per iteration, while the stateful agent operates within a fixed-size conversation window at $O(1)$ cost. This paper describes the architecture in sufficient detail for practitioners to implement a stateful autoresearch agent for their own workflows.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。