AI agents often suffer from high token consumption and reduced correctness due to inefficient code navigation. Traditional text-based search methods fail by introducing noise through irrelevant matches, silence by missing structural relationships like interface implementations, and ambiguity through name shadowing. To mitigate these issues, the article proposes moving from text-based searching to semantic code navigation using a code graph. This graph-based approach models the codebase as a structured map of classes, methods, interfaces, and inheritance chains, allowing agents to programmatically query exact file and line locations rather than approximating structure through text. Benchmarking these methods against real-world tasks from merged commits reveals significant cost reductions: Java interface changes became 36% cheaper, package renames dropped by 20%, Python compiler changes decreased by 20%, and return-type or argument-order modifications saw 15-20% reductions. While TypeScript changes saw a more modest 5% decrease due to localized relationships, the overall data confirms that semantic navigation prevents agents from wasting tokens on irrelevant files. Ultimately, using a code graph ensures higher completeness and correctness by explicitly enumerating all structurally connected locations, thereby reducing both unpredictable token expenditures and the risk of shipping bugs caused by missed connections.

Read original