AI Agents are bad at discovering code patterns, so I built a Semantic graph to improve the outcomes

Reddit r/artificial / 4/14/2026

💬 OpinionDeveloper Stack & InfrastructureIdeas & Deep AnalysisTools & Practical Usage

Key Points

  • The author argues that current AI agents struggle to infer relationships between code blocks and therefore produce suboptimal plans when refactoring or fixing real codebases.
  • They cite a concrete example from a Log4j 1 to 2 migration where an agent identified only 9 of 54 call sites that required updating.
  • To address this, the author built a semantic code graph that AI agents can query using Cypher to gain a more precise understanding of code structure and patterns.
  • By integrating the semantic graph into an AI agent (via skills or exposing it over MCP), they report much higher precision—detecting all 54 call sites and reducing effort by finding that 30 call sites share a common base class.
  • A reference implementation for Java is provided via a GitHub repository, inviting feedback from the community.

During my day to day job, I have seen how bad AI agents are when it comes to fixing code bases. AI agents treat majority of the code as raw text and barely try to infer any relation between the different code blocks.

This leads to the AI agents coming up with suboptimal plans for fixing a codebase. For example, while performing a log4j1 to v2 migration, the AI agents came up with 9 callsites which needed updating, while the total number was 54.

To solve for this, I built up a semantic code graph for AI agents which they can query using Cypher language and get precise understanding of the codebase. This graph when embedded to an AI agent through the usage of skills or exposed over MCP, enabled the AI agent to reach a significantly higher precision on the migration task, enabling the discovery of all 54 call sites and also optimizing on the effort by determining that 30 out of 54 call sites inherit from the same base class, so just modifying the base class is enough.

I have put up the reference implementation for Java:

Github: https://www.github.com/neuvem/java2graph

Please do let me know what you think and do share your thoughts, opinions or feedbacks

submitted by /u/_h4xr
[link] [comments]