LLM-based code agents treat repositories as unstructured text, applying edits through brittle string matching that frequently fails due to formatting drift or ambiguous patterns. We propose reframing the codebase as a structured action space where agents operate on named AST entities rather than text spans. Our framework, CODESTRUCT, provides readCode for retrieving complete syntactic units and editCode for applying syntax-validated transformations to semantic program elements. Evaluated on SWE-Bench Verified across six LLMs, CODESTRUCT improves Pass@1 accuracy by 1.2-5.0% while reducing token consumption by 12-38% for most models. Models that frequently fail to produce valid patches under text-based interfaces benefit most: GPT-5-nano improves by 20.8% as empty-patch failures drop from 46.6% to 7.2%. On CodeAssistBench, we observe consistent accuracy gains (+0.8-4.4%) with cost reductions up to 33%. Our results show that structure-aware interfaces offer a more reliable foundation for code agents.
Figures & tables
Figure 1: Contrasting action spaces for code agents. Text-based agents (left) read ~300 lines to locate a function and regenerate ~44 lines verbatim for removal, making edits brittle to formatting changes. CodeStruct (right) reads only the target symbol (~50 lines) and specifies removal in ~2 lines via a symbol-scoped edit.
Figure 2: Overview of CodeStruct . Code agents interact with repositories through a structured AST action space. Source code is parsed into an AST, exposing addressable nodes. The readCode and editCode tools operate directly on these nodes, enabling structure-aware code navigation and modification without string matching, line numbers, or brittle edits.
Model
Interface
Pass@1 (%) ↑
Input Tokens
Output Tokens
LLM Calls ↓
Cost ()\downarrow$
GPT-5
Baseline
66.0
452.7M
0.81M
16,436
574.0
CodeStruct
67.2 (+1.2)
366.3M (-19.1%)
0.44M (-45.7%)
16,307 (-0.8%)
462.2 (-19.5%)
GPT-5-mini
Baseline
60.4
593.7M
1.27M
18,560
151.0
CodeStruct
62.0 (+1.6)
404.5M (-31.9%)
0.35M (-72.4%)
14,811 (-20.2%)
101.8 (-32.6%)
GPT-5-nano
Baseline
19.6
808.0M
0.86M
24,037
40.7
CodeStruct
40.4 (+20.8)
1,137.4M (+40.8%)
0.95M (+10.5%)
27,278 (+13.5%)
57.3 (+40.8%)
Table 1: Main results on SWE-Bench Verified. Agents follow SWE-Agent-style workflows—iterative loops that alternate between reading repository files and applying code edits via tool calls. We compare text-based interaction ( Baseline ) against CodeStruct . Inline percentages indicate relative change compared to Baseline (percentage points for Pass@1; relative % for tokens, calls, and cost). Green denotes improvement; red denotes regression.
Model
Interface
Accuracy (%) ↑
Input Tokens
Output Tokens
LLM Calls ↓
Cost ()\downarrow$
GPT-5
Baseline
53.3
143.9M
1.27M
566
$19.57
CodeStruct
54.1 (+0.8)
122.1M (-15.1%)
1.18M (-7.0%)
550 (-2.8%)
$16.74 (-14.5%)
GPT-5-mini
Baseline
51.1
125.3M
1.26M
648
$3.45
CodeStruct
51.9 (+0.8)
83.1M (-33.7%)
0.89M (-28.7%)
630 (-2.8%)
$2.30 (-33.3%)
GPT-5-nano
Baseline
46.7
56.0M
1.25M
742
$0.34
CodeStruct
48.1 (+1.4)
52.8M (-5.7%)
1.05M (-15.6%)
652 (-12.1%)
$0.32 (-5.9%)
Table 2: CodeAssistBench results comparing text-based interaction ( Baseline ) against CodeStruct . Inline values show relative change over Baseline (percentage points for Accuracy; relative % for tokens, calls, and cost).
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 3: Comparison of CodeStruct (AST-based) vs. text-based code editing approaches. CodeStruct completes in 24 steps vs. 54 steps for text-based—a 55.6% reduction.
Metric
CodeStruct
Text-Based
Total Steps
24
54
Steps to Locate Target
2
21
Edit Success on First Try
Yes
Yes
Final Outcome
Success
Success
Appendix
Table 3: Comparison on django__django-11211
Qwen3-32B
GPT-5-mini
Configuration
Pass@1 (%)
Input (M)
Output (M)
Calls
Cost ($)
Pass@1 (%)
Input (M)
Output (M)
Calls
Cost ($)
Baseline
14.8
366.0
1.23
25,543
55.64
60.4
593.7
1.27
18,560
150.97
CodeStruct
16.0
302.1
1.03
24,653
45.93
62.0
404.5
0.35
14,811
101.83
w/o editCode
12.8
291.6
0.85
24,535
44.25
60.6
562.1
0.35
15,757
141.22
w/o readCode
8.2
423.4
1.78
35,670
64.58
56.8
435.2
0.33
15,715
109.46
Appendix
Table 4: Ablation results with cost analysis on SWE-Bench Verified. Removing either readCode or editCode degrades performance, with readCode causing the largest accuracy drop while editCode removal causes the largest cost penalty relative to performance. Input/Output tokens shown in millions. Cost is computed using per-model API pricing, consistent with Table 1 .
Model
Approach
Total Errors
Errors/Instance
Reduction
GPT-5
Text-based
426
0.845
-
GPT-5
CodeStruct
52
0.103
-87.8%
GPT-5-mini
Text-based
568
1.125
-
GPT-5-mini
CodeStruct
127
0.252
-77.6%
GPT-5-nano
Text-based
459
0.911
-
GPT-5-nano
CodeStruct
551
1.093
+20.0%
Appendix
Table 5: Error rates across models and interfaces. CodeStruct dramatically reduces errors for capable models but increases them for GPT-5-nano, identifying a capability threshold.
Can LLM agents explore codebases and reason about code semantics without executing the code? We study this capability, which we call agentic code reasoning, and introduce semi-formal reasoning: a structured prompting methodology that requires agents to construct explicit premises, trace execution paths, and derive formal conclusions. Unlike unstructured chain-of-thought, semi-formal reasoning acts as a certificate: the agent cannot skip cases or make unsupported claims. We evaluate across three tasks (patch equivalence verification, fault localization, and code question answering) and show that semi-formal reasoning consistently improves accuracy on all of them. For patch equivalence, accuracy improves from 78% to 88% on curated examples and reaches 93% on real-world agent-generated patches, approaching the reliability needed for execution-free RL reward signals. For code question answering on RubberDuckBench Mohammad et al. (2026), semi-formal reasoning achieves 87% accuracy. For fault localization on Defects4J Just et al. (2014), semi-formal reasoning improves Top-5 accuracy by 5 percentage points over standard reasoning. These results demonstrate that structured agentic reasoning enables meaningful semantic code analysis without execution, opening practical applications in RL training pipelines, code review, and static program analysis.
Large language model (LLM) coding agents increasingly operate at the repository level, motivating benchmarks that evaluate their ability to optimize entire codebases under realistic constraints. Existing code benchmarks largely rely on synthetic tasks, binary correctness signals, or single-objective evaluation, limiting their ability to assess holistic optimization behavior. We introduce FormulaCode, a benchmark for evaluating agentic optimization on large, real-world codebases with fine-grained, multi-objective performance metrics. FormulaCode comprises 957 performance bottlenecks mined from scientific Python repositories on GitHub, each paired with expert-authored patches and, on average, 264.6 community-maintained performance workloads per task, enabling the holistic ability of LLM agents to optimize codebases under realistic correctness and performance constraints. Our evaluations reveal that repository-scale, multi-objective optimization remains a major challenge for frontier LLM agents. Project website at: https://formula-code.github.io
Atharva Sehgal, James Hou, Akanksha Sarkar +4
The University of Texas at Austin · California Institute of Technology · Cornell University
Coding agents now interleave LLMs with retrieval over the working repository, and retrieval implementations vary widely across deployed harnesses. Inside a fixed coding-agent harness on a fixed model, does adding a structural codebase index actually change cost or resolve? We ran three arms (the harness with the index, the same harness without it, and an agentic-grep comparator) on SWE-PolyBench Verified and SWE-bench Pro with Claude Opus 4.7 held fixed throughout, across three seeds, inside a leak-audited per-task sandbox. The within-harness ablation produces a large localization gain and a statistically separated resolve gain, with no cost penalty per cell and lower cost per solve. The cross-harness check shows that the index does not regress against an agentic-grep baseline on resolve or localization, again at no cost penalty. We release the per-cell exclusion ledger, the leak-audit script, the localization extractor, and the results database. The deployment question for a structural codebase index is thus not whether it is too expensive to run (across seeds, the index lands at a lower $/solved than agentic grep) but whether the workload includes multi-file changes where structural ranking pays off.