Beyond RAG: Building an AI Coding Agent with Planning, Tool Execution, and ReAct Reasoning
In my previous article, I explored how I wrapped a RAG agent inside an MCP server to make enterprise knowledge accessible through standardized tools. However, while RAG improves retrieval, software engineering tasks require something more. A developer assistant should not only retrieve information. It should investigate. For example: "Where is authentication implemented?" A useful coding…
In a previous article, the author demonstrated how to integrate a RAG agent into an MCP server to provide enterprise knowledge through standardized tools. However, the author noted that software engineering tasks demand more than just information retrieval. A coding assistant should be capable of investigating tasks such as finding the location of authentication implementation in a codebase.
The author then proceeded to build an AI coding agent that can reason, select tools, and analyze codebases step-by-step. This agent does not yet utilize RAG; instead, it operates directly against the repository. The author plans to incorporate RAG as the next step in development.
Traditional chatbots follow a simple pattern: User Question | LLM | Response. While this works well for general questions, software repositories contain thousands of files and relationships. A coding assistant requires additional capabilities such as repository awareness, search functionality, code understanding, and multi-step reasoning.
The author's agent introduces a decision-making layer with the following components: the Planner, Tool Registry, and the Agent Execution Loop, which follows a ReAct-style pattern. The Planner decides the next action based on a rule-based approach first, and resorts to an LLM for JSON-structured tool selection when no rule matches.
The Tool Registry exposes capabilities through specific tools like search_code, read_file, and analyze_file. The Agent Execution Loop follows a sequence of Reasoning, Action, Observation, and Reasoning again.
During the implementation, the author faced several challenges. Firstly, ensuring reliable tool selection was crucial, which was addressed by restricting tool choices, adding JSON validation, and enforcing structured outputs. Secondly, an early version of the agent could repeat search_code indefinitely due to independent decision-making at each step.
Maintaining previous observations as context resolved this issue. Thirdly, distinguishing between implementation files and references proved challenging, necessitating code analysis using Python's ast module instead of simple keyword matching.
As a result, the agent successfully generates an answer along with relevant classes and functions. For the specified demo question, the agent outputs: { "answer" : "Authentication is implemented in auth.py" , "classes" : [ "AuthenticationService" ], "functions" : [ "login" , "authenticate" ] }. However, it is important to note that the answer generation step is currently scoped for authentication-style questions and does not generalize to arbitrary queries. The author plans to enhance this step to provide more generalized explanations.
Looking towards the future, the author intends to explore generalizing the answer-generation step beyond specific authentication-related questions. Integrating direct Git repository connections, generating dependency graphs, understanding application architecture, connecting Jira and documentation systems, conducting automated pull request reviews, and developing code migration assistants are other areas of improvement that the author aims to address.
Ultimately, the author envisions combining agents with real enterprise knowledge retrieval to create the next generation of developer assistants.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.