The Reasoning Disconnect in AI Agents
Current AI agents struggle with repository-level tasks—such as fixing bugs that span multiple files or comprehending massive libraries—because they lack a unified way to represent code. Existing methods typically rely on either API documentation, which captures intent but lacks structural mapping, or dependency graphs, which show connections but lack semantic depth. This "reasoning disconnect" forces models to either guess the architecture or get lost in a sea of raw code. Furthermore, keeping these representations up-to-date as code changes is computationally expensive and prone to semantic drift.
To address this, researchers introduce RPG-Encoder, a framework that bridges the gap between high-level architectural intent and low-level code implementation by creating a unified "Repository Planning Graph" (RPG).
The RPG-Encoder Framework
RPG-Encoder operates on a core philosophy: the symmetry of reasoning. Code generation (expanding intent into implementation) and code comprehension (compressing implementation into intent) are inverse processes within a unified cycle. A representation that works for one should seamlessly support the other.
The framework transforms a codebase into a hierarchical, dual-view graph through three primary phases:
- Semantic Lifting: Instead of processing raw text, the system uses an LLM to "lift" code into atomic semantic features. These are short "verb + object" phrases (e.g., "validate token" or "load config") that describe behavior rather than implementation details.
- Latent Architecture Recovery: The system reorganizes these features into a consistent three-level hierarchy (Functional Area > Category > Subcategory). This creates a logical, human-readable map that abstracts away the often messy physical folder structure of the disk.
- Artifact Grounding: Finally, it anchors these abstract functional nodes back to physical file paths and injects dependency edges (imports and function calls) via Abstract Syntax Tree (AST) analysis.
Incremental Evolution and Navigation
A major bottleneck in repository representation is the cost of maintenance. RPG-Encoder solves this via Incremental Evolution. Instead of rebuilding the entire graph for every commit, the system parses git diffs to update only the affected nodes. This decouples maintenance costs from the overall repository scale.
This unified graph also enables a highly effective "Search-then-Zoom" navigation pattern. Agents can switch between a Functional View (understanding what a feature does) and a Dependency View (seeing what code it calls), traversing the broad topology to build a global map before zooming in to fetch specific code snippets.
Key Results
RPG-Encoder was evaluated across several high-stakes benchmarks, including SWE-bench Verified, SWE-bench Live, and RepoCraft, using massive real-world repositories like Django, Pandas, and Scikit-Learn.
- State-of-the-Art Performance: The framework achieved 93.7% Acc@5 on SWE-bench Verified, significantly outperforming previous baselines.
- Superior Localization: On SWE-bench Live (testing recent GitHub issues to prevent data contamination), RPG-Encoder exceeded the best baseline by over 10%, proving its ability to find fine-grained details in complex codebases.
- High-Fidelity Reconstruction: In RepoCraft tasks—where an agent must rebuild a repository from scratch using only the RPG—it achieved 98.5% coverage. By contrast, documentation-only baselines recovered only ~17% of the code volume.
- Efficiency: The incremental update strategy reduced maintenance overhead by 95.7% compared to full graph rebuilding.
Limitations and Future Directions
While RPG-Encoder demonstrates massive gains, a few challenges remain. The incremental update system handles routine commits exceptionally well, but major architectural refactoring still requires a global reconstruction of the graph. Additionally, the current implementation is heavily focused on Python; extending this high-fidelity semantic lifting to polyglot environments is a key next step. Finally, even with a near-perfect map, agents still fail due to inherent LLM reasoning limits (accounting for ~27% of failures), suggesting that while the map has been perfected, the "navigator" still has room to improve.
Summary updated