A Multi-Agent Framework for Stateful Inference-Time Search

Arshika Lalan, Rajat Ghosh, Aditya Kolsur, Debojyoti DuttaarXiv 2025

TL;DR

This paper introduces a training-free, stateful multi-agent framework that uses evolutionary search and adversarial mutation to generate high-coverage unit tests. By maintaining a persistent reasoning state across inference steps, it allows large language models (LLMs) to systematically discover robust edge cases, significantly outperforming traditional stateless prompting methods on complex codebases.

What Problem Does This Paper Address?

While LLMs excel at single-step tasks, they often struggle with complex, multi-stage reasoning problems like automated unit test generation. Standard LLM inference is inherently stateless—each API call discards prior intermediate reasoning unless it is explicitly re-injected into the prompt. This design choice limits the model's ability to explore multiple reasoning branches or iteratively refine its code based on execution feedback.

While task-specific fine-tuning or instruction-tuning can improve surface-level code generation, the resulting models remain brittle when faced with long-horizon dependencies and deep logical chains. The authors address this gap by introducing a stateful architecture directly at inference time, eliminating the need for costly gradient-based training.

Methods

The authors propose a stateful multi-agent evolutionary search framework based on an Adversarially Guided Actor-Critic (AGAC) setup. The system decomposes the test generation process into two phases: generating robust edge cases through an evolutionary loop, and then synthesizing those cases into a final unit test file.

The core evolutionary loop is managed by a Controller that maintains a non-Markovian persistent state (a history of prior edge cases, coverage scores, mutation feedback, and exception signals) across $N$ stages. It orchestrates four specialized agents:

  1. Actor: Proposes candidate edge cases using in-context learning, conditioned on the persistent state and source code.
  2. Executor: An auxiliary agent providing a sandboxed Docker environment to execute tests and return execution traces and coverage metrics.
  3. Adversary: Perturbs the source code by generating mutants to see if the actor's test cases can successfully distinguish the true program from the modified variants.
  4. Critic: Integrates structural coverage, exception discovery, and mutation robustness into a unified scalar reward to guide the evolutionary selection.
Overview of the stateful multi-agent architecture

The loop terminates when the reward crosses a predefined quality threshold or when the rewards plateau over a set number of iterations.

Datasets

The framework was evaluated using three diverse LLM families (Llama-70B, GPT-o4-mini, and Gemma-2-27B) across two benchmarks:

  • HumanEval: A standard benchmark consisting of 164 Python programming problems, used here as a standalone sanity check for file-level implementations.
  • TestGenEvalMini: A newly curated subset of TestGenEvalLite (derived from SWEBench). It contains 48 representative examples across 6 repositories, preserving real-world software engineering complexities like multi-parameter interactions, boundary conditions, and exception handling.

Key Insights and Ideas

  • Inference-Time State Management: Instead of using state updates to drive gradient descent (as in traditional reinforcement learning), this framework uses state updates to dynamically shape the actor's prompt context. This serves as a lightweight form of policy adaptation at inference time.
  • The Power of a "Cold-Start" Heuristic: At initialization ($n=1$), before any feedback is available, the actor is seeded deterministically using rule-based heuristics (boundary value analysis, equivalence partitioning). For simpler tasks like HumanEval, this cold-start is so powerful that it resolves roughly 62% of problems in a single step without needing further LLM refinement.
  • Adversarial Grounding Prevents "Shallow" Optimization: Simply optimizing for code coverage can lead to weak tests that pass easily but fail to catch bugs. By forcing the actor to defeat an adversary that actively mutates the code, the framework ensures the generated edge cases are semantically deep and robust.

Key Results

On the complex TestGenEvalMini benchmark, the stateful multi-agent framework (referred to as the system-under-test, or SUT) consistently outperformed standard zero-shot, one-shot, and three-shot baselines (with and without Chain-of-Thought prompting).

  • Llama-70B saw the most dramatic improvements, with the stateful framework achieving 43% line coverage and 76% branch coverage, compared to just 23% line coverage and 18% branch coverage for the three-shot baseline.
  • For GPT-o4-mini and Gemma-2-27B, the framework achieved the highest line and function coverage, though it was occasionally surpassed in branch coverage due to a search bias that favored discovering exception-heavy paths over exploring complementary control-flow branches.
Final edge case quality on TestGenEvalMini across different LLM families

Limitations and Future Work

Despite its strong performance, the framework has a few notable limitations:

  • High Computational Cost: Stateful multi-agent search incurs significant inference-time compute costs and longer runtimes compared to standard feed-forward generation.
  • Single-File Constraint: The current Executor agent only supports single source files and lacks comprehensive repository indexing, meaning it cannot handle complex cross-file dependencies or relative package imports.
  • Server Instability: Modules that trigger rapid, successive environment requests (like Django's autoreload) can cause instability in the sandboxed environment.

Future work will focus on scaling the executor to support broader repository contexts, optimizing search termination criteria to save compute, and incorporating learned reward models to stabilize scoring.

Summary updated

BibTeX
@misc{lalan2025multi,
  author = {Arshika Lalan and Rajat Ghosh and Aditya Kolsur and Debojyoti Dutta},
  title = {{A Multi-Agent Framework for Stateful Inference-Time Search}},
  year = {2025},
  eprint = {2510.07147},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.07147},
}
Figure