Stateful ReAct Agents Boost LLM Experimentation Efficiency.

Faramarz Jabbarvaziri· June 16, 2026 View original

Summary

This research introduces stateful ReAct agents using LangGraph to significantly reduce token costs in autonomous experimentation with large language models. By maintaining experimental history through persistent state, the new design avoids re-reading full context, leading to substantial token savings.

Autonomous experimentation, often called the autoresearch pattern, allows large language models (LLMs) to iteratively refine code to optimize specific metrics. However, current stateless designs incur high token costs because they rebuild the experimental context from scratch in each iteration. This leads to a quadratic increase in total token usage over time. A new approach reformulates this pattern using a stateful ReAct agent, built with LangGraph. This agent leverages typed persistent state to carry experimental history across iterations via a tool-calling interface. This design fundamentally changes how context is managed, moving from an O(n) cost per iteration to a fixed-size conversation window with O(1) cost. Evaluations on hyperparameter tuning and code performance optimization benchmarks demonstrated significant token reductions. The stateful agent achieved 90% fewer tokens for hyperparameter tuning and 52% fewer for code optimization, all while maintaining comparable optimization quality. The paper provides architectural details for practitioners to implement this token-efficient method.

Why it matters

Professionals can drastically cut operational costs and improve the efficiency of autonomous AI development workflows by adopting stateful agent designs, making iterative experimentation more practical and scalable.

How to implement this in your domain

  1. 1Adopt LangGraph or similar state management frameworks for agentic workflows.
  2. 2Design agents to use persistent state to carry context across iterations, avoiding full history re-reads.
  3. 3Integrate tool-calling interfaces for agents to interact with and update their state.
  4. 4Benchmark current autonomous experimentation workflows to identify token cost bottlenecks.
  5. 5Refactor existing stateless autoresearch patterns into stateful designs for cost optimization.

Who benefits

AI DevelopmentSoftware EngineeringResearch & DevelopmentData Science

Key takeaways

  • Stateless LLM experimentation incurs high, quadratically increasing token costs.
  • Stateful ReAct agents significantly reduce token consumption by maintaining persistent context.
  • LangGraph can be used to implement token-efficient stateful agents.
  • This approach offers substantial cost savings without sacrificing optimization quality.

Original post by Faramarz Jabbarvaziri

"arXiv:2606.14945v1 Announce Type: new Abstract: 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…"

View on X

Originally posted by Faramarz Jabbarvaziri on X · view source

Want to go deeper?

Turn these trends into skills with Learnijoy's hands-on AI & tech courses.

Explore courses