TL;DR
Current LLM-based code agents treat complex software repositories as flat, unstructured text, making code modifications brittle and token-expensive. CODESTRUCT solves this by reframing the codebase as a structured action space of Abstract Syntax Tree (AST) nodes, allowing agents to read and edit named program entities (like functions and classes) directly. This simple shift improves coding accuracy by up to 20.8% while slashing token costs by up to 38%.
What Problem Does This Paper Address?
When human developers modify code, they think in terms of semantic structures: "I need to delete this method" or "I need to change this function's parameters." However, state-of-the-art LLM code agents interact with repositories through a fundamental abstraction mismatch: they treat code as raw text spans.
To find a function, an agent must grep for strings or read massive chunks of a file. To edit it, the agent typically relies on line numbers or string-replacement blocks. This text-centric paradigm suffers from severe limitations:
- Irrelevant Context: Reading entire files floods the LLM's context window with distracting information, degrading reasoning.
- Fragility: Minor formatting drifts (like an extra space or indentation change) cause string-matching tools to throw "no occurrence" errors.
- Wasteful Regeneration: To change a single line, agents often have to rewrite dozens of lines of surrounding code verbatim.
Methods
CODESTRUCT replaces unstructured text manipulation with a structured action space grounded in the repository's Abstract Syntax Tree (AST). Instead of targeting line ranges, agents reference code via unambiguous identifiers (e.g., file.py::ClassName::method).
The framework introduces two core, structure-aware primitives:
readCode: Rather than dumping a whole file, this tool selectively retrieves complete syntactic units (functions/classes) or generates a compact structural summary of top-level signatures. It supports deterministic fuzzy matching to help agents locate symbols quickly.editCode: This tool executes atomic AST-level transformations: insertion, replacement, or removal. The agent only needs to specify the target node selector and the new content. Crucially, CODESTRUCT automatically handles indentation and runs a syntax validation check before committing, rejecting any edits that would break the code.
To ensure broad compatibility, CODESTRUCT is implemented using the Model Context Protocol (MCP), meaning it can be plugged directly into existing agent frameworks (like SWE-Agent or OpenHands) without altering their underlying planning logic.
Datasets
The authors evaluated CODESTRUCT across six different LLMs using two prominent benchmarks:
- SWE-Bench Verified: A subset of 500 real-world software engineering problems from Python GitHub repositories, complete with unit tests to verify the final patches.
- CodeAssistBench Verified: A dataset containing 135 multi-turn, interactive programming assistance tasks spanning 7 different programming languages, focusing on conversational problem-solving rather than just single-shot patch generation.
Key Insights and Ideas
- Redistributing Failure Modes: One of the most fascinating findings involves smaller models like GPT-5-nano. Under text-based interfaces, these models frequently suffer from "empty-patch failures"—they simply give up and terminate early because text editing is too frustrating. CODESTRUCT's structured navigation gives them a reliable foothold, reducing empty patches from 233 to 36. Even though they make more tool-level errors due to limited capacity, the ability to sustain exploration leads to a massive accuracy boost.
- The Complementary Nature of Read vs. Write: Through ablation studies, the authors discovered that
readCodeandeditCodetackle distinct bottlenecks.readCodeminimizes exploration costs by preventing agents from getting lost in massive files, whileeditCodeminimizes transformation costs by eliminating the need to regenerate unchanged code. - Negligible Overhead: Parsing files into ASTs on the fly sounds computationally expensive, but using
tree-sitterlocally takes only 146–212ms. Compared to LLM inference latencies (which range from 4–12 seconds per call), the AST parsing overhead accounts for less than 0.8% of total runtime, making it incredibly practical.
Key Results
Integrating CODESTRUCT yielded substantial improvements in both accuracy and efficiency:
- SWE-Bench Verified:
- Frontier models (like GPT-5 and Qwen3-Coder) saw Pass@1 accuracy gains of 1.2% to 5.0%.
- The lightweight GPT-5-nano achieved a staggering 20.8% absolute accuracy improvement.
- Most models achieved these gains while reducing token consumption by 12% to 38% and cutting total inference costs by up to 33%.
- CodeAssistBench: Accuracy consistently improved across all models by 0.8% to 4.4%, proving that structured action spaces generalize well beyond Python and patch-generation tasks into multi-turn, multi-language interactions.
Limitations and Future Work
- File-Level AST Scope: CODESTRUCT currently parses ASTs on a per-file basis. It does not explicitly map out cross-file dependencies, such as class inheritance hierarchies or inter-module call graphs. While text-based baselines share this limitation, incorporating a global repository index is a clear next step.
- Syntax Validity Dependency: Because it relies on AST parsing, CODESTRUCT requires the source files to be syntactically valid before the agent interacts with them. If a repository contains pre-existing syntax errors, the structure-aware tools cannot initialize properly.
- Task Coverage: The evaluation focused primarily on bug fixing and interactive assistance. Future work will explore how structured action spaces perform in other domains like automated code review and test generation.
Summary updated