Abstract
As Large Language Models (LLMs) transition from text generators to autonomous agents, their ability to interact with external tools via APIs becomes critical. However, existing benchmarks often focus on isolated calls, failing to capture the complexity of real-world software development. This paper introduces StateGen, an automated framework for generating multi-step coding tasks, and StateEval, a benchmark of 120 verified cases. Our evaluation reveals that even state-of-the-art models like GPT-4.1 struggle with state management and interdependent tool use, achieving only a 56% success rate.
Introduction: The Challenge of Sequential API Calls
In real-world applications, software development involves sequential dependencies: the output of one API call (e.g., a session ID or a processed tensor) becomes the required input for the next. This requires the LLM to maintain a coherent "program state" throughout the execution.
Current benchmarks often rely on simple string matching to verify correctness, which overlooks how LLMs reason through interdependent operations or manage control flows like if-else logic. When a model miscalculates a state early in a sequence, the entire task typically fails, highlighting a significant gap in current evaluation methodologies.
Methodology: The StateGen Framework
To move away from manual test curation toward a more rigorous, "fuzzer-like" generation process, the authors developed StateGen. This pipeline ensures that generated tasks are both diverse and mathematically valid.
The framework consists of four main stages:
- Trace Generation: Using a state-machine-based engine, StateGen tracks available variables and their types to ensure every sequence is logically valid. It uses "energy-based sampling" to prioritize rare API combinations, ensuring high diversity.
- Program Generation: To increase realism, the framework injects control-flow structures. It selects local variables and creates
if-elseconditions around them, forcing the LLM to reason about different execution paths. - Instruction Translation: A multi-agent LLM system (comprising a Generator and an Evaluator) translates raw code into natural language prompts. This ensures instructions are human-like while remaining unambiguous.
- Oracle Construction: Unlike benchmarks that check text, StateGen executes the generated code in a local environment to record the "ground truth" final state and side effects. This allows for a deterministic, rigorous evaluation of correctness.
The StateEval Benchmark
The researchers introduced StateEval, a benchmark consisting of 120 manually verified test cases across three distinct scenarios:
- Session Service: Managing web user sessions via RESTful APIs and MongoDB.
- PyTorch Tensor Operation: Complex mathematical manipulations requiring strict adherence to tensor shapes and dimensions.
- ElevenLabs MCP: A modern scenario involving text-to-speech, audio isolation, and phone call orchestration.
StateEval is significantly more "dense" than existing benchmarks like HumanEval, featuring nearly double the average number of function calls per task and much higher "binding counts" (shared variables between calls).
Key Results and Insights
The evaluation of five prominent models, including GPT-4.1, Gemini-2.5-Flash, and Llama-4-Scout, yielded several critical findings:
- Performance Gap: Closed-source models significantly outperformed open-source ones. GPT-4.1 led with a 56% pass@1 rate, followed by Gemini-2.5-Flash at 45%.
- Logic Over Syntax: Most failures were not due to bad Python syntax but were "Execution Errors" (bad parameters) or "Result Errors" (logical failure to achieve the user's goal).
- Complexity Sensitivity: As the "Path Depth" (the length of the data-dependency chain) increased, model performance dropped sharply.
- Familiarity Bias: Models performed better on PyTorch tasks than on niche RESTful services, suggesting that training data prevalence plays a major role in tool-calling proficiency.
Conclusion
The primary challenge for LLMs in tool-calling is not just knowing which API to call, but managing the data flow between them. StateGen provides a rigorous framework for evaluating these capabilities, highlighting that syntax is largely solved, but complex logic and state management remain significant hurdles. Future work will focus on using LLMs to automatically parse API documentation into structured state models to reduce the engineering effort required for new domains.
Summary updated