{"slug": "beyond-rag-building-an-ai-coding-agent-with-planning-tool-execution-and-react", "title": "Beyond RAG: Building an AI Coding Agent with Planning, Tool Execution, and ReAct Reasoning", "summary": "A developer built an AI coding agent that uses planning, tool execution, and ReAct reasoning to analyze codebases step-by-step, moving beyond simple RAG-based retrieval. The agent, which works directly against a repository, selects tools like search_code, read_file, and analyze_file to investigate questions such as 'Where is authentication implemented?' The developer addressed challenges in tool selection reliability, avoiding repeated actions, and distinguishing implementation from references.", "body_md": "In my previous article, I explored how I wrapped a RAG agent inside an MCP server to make enterprise knowledge accessible through standardized tools.\n\nHowever, while RAG improves retrieval, software engineering tasks require something more.\n\nA developer assistant should not only retrieve information. It should investigate.\n\nFor example:\n\n\"Where is authentication implemented?\"\n\nA useful coding assistant should be able to:\n\nThis led me to build an AI coding agent that can reason, select tools, and analyze a codebase step-by-step. This one doesn't use RAG yet — it works directly against the repository — but that's a deliberate next step, more on that at the end.\n\nA traditional chatbot follows a simple pattern:\n\n```\nUser Question\n       |\n       v\n      LLM\n       |\n       v\n    Response\n```\n\nThis works well for general questions, but software repositories contain thousands of files and relationships.\n\nA coding assistant needs additional capabilities:\n\nAn agent introduces a decision-making layer:\n\n```\nUser Question\n      |\n      v\n    Planner\n      |\n      v\n Choose Tool\n      |\n      v\n Execute Tool\n      |\n      v\n Observe Result\n      |\n      v\n Generate Answer\n```\n\nThe agent consists of several components.\n\nThe planner decides the next action. It tries a rule-based plan first (keyword matching on the question), and falls back to an LLM (via Ollama's `tinyllama`\n\n) for JSON-structured tool selection when no rule matches.\n\nExample:\n\nUser question:\n\n```\nWhere is authentication implemented?\n```\n\nPlanner response:\n\n```\n{\n \"tool\": \"search_code\",\n \"input\": \"authentication\"\n}\n```\n\nThe planner does not execute the action. It only decides what should happen next.\n\nThe agent exposes capabilities through tools. Currently:\n\n`search_code`\n\n`read_file`\n\n`analyze_file`\n\nEach tool has a specific responsibility.\n\n**Search Tool** — finds files containing a keyword.\n\nInput: `authentication`\n\nOutput: `auth.py`\n\n, `app.py`\n\n**Read File Tool** — retrieves source code.\n\nInput: `auth.py`\n\nOutput:\n\n``` python\nclass AuthenticationService:\n    def login(self, username, password):\n        if self.authenticate(username, password):\n            return \"Login successful\"\n```\n\n**Analyze Tool** — understands code structure using Python's `ast`\n\nmodule.\n\nOutput:\n\n```\n{\n \"classes\": [\"AuthenticationService\"],\n \"functions\": [\"login\", \"authenticate\"]\n}\n```\n\nThe core of the system is the agent loop, following a ReAct-style pattern:\n\n```\nReason\n  ↓\nAction\n  ↓\nObservation\n  ↓\nReason Again\n```\n\n**Step 1** — The agent determines it needs to locate authentication code.\n\nAction: `search_code(\"authentication\")`\n\nObservation: `auth.py`\n\n, `app.py`\n\n**Step 2** — The agent identifies that `auth.py`\n\nis likely the implementation.\n\nAction: `read_file(\"auth.py\")`\n\nObservation: `AuthenticationService`\n\nclass found\n\n**Step 3** — The agent needs more understanding.\n\nAction: `analyze_file()`\n\nObservation:\n\n```\nClass: AuthenticationService\nFunctions: login(), authenticate()\n```\n\nThe agent now has enough information to answer.\n\nBuilding the agent introduced several interesting engineering challenges.\n\n**Challenge 1: Reliable tool selection.** Initially, the LLM sometimes selected incorrect tools or returned invalid responses. To improve reliability, I restricted tool choices, added JSON validation, and enforced structured outputs.\n\n**Challenge 2: Avoiding repeated actions.** An early version of the agent could repeat `search_code`\n\nindefinitely, because every decision was independent. The fix was maintaining previous observations as context, so the planner can see \"auth.py contains authentication\" and move to reading the file instead of searching again.\n\n**Challenge 3: Separating implementation from references.** A search result may return both `auth.py`\n\n(which defines `AuthenticationService`\n\n) and `app.py`\n\n(which just imports it). The agent needs code analysis, not simple keyword matching, to tell the two apart.\n\nFor this specific demo question, the agent produces:\n\n```\n{\n \"answer\": \"Authentication is implemented in auth.py\",\n \"classes\": [\"AuthenticationService\"],\n \"functions\": [\"login\", \"authenticate\"]\n}\n```\n\nI want to be upfront about where this stands today: the search, read, and analyze steps are genuinely general-purpose — they work against any Python codebase. The final answer-generation step, however, is currently scoped to authentication-style questions specifically; it doesn't yet generalize its explanation to arbitrary questions the way the reasoning steps before it do. Making that synthesis step question-agnostic is next on my list.\n\nSome areas I want to explore next:\n\nBuilding an AI coding agent showed me that the biggest difference between a chatbot and an agent is not the language model itself.\n\nThe difference is the ability to:\n\nRAG helps an AI find information. Agents help an AI perform tasks. The next generation of developer assistants will combine both — and connecting this agent to real enterprise knowledge retrieval is exactly where I'm headed next.", "url": "https://wpnews.pro/news/beyond-rag-building-an-ai-coding-agent-with-planning-tool-execution-and-react", "canonical_source": "https://dev.to/sri_d_6dfd4d31319a6389eaa/beyond-rag-building-an-ai-coding-agent-with-planning-tool-execution-and-react-reasoning-53ko", "published_at": "2026-08-05 02:23:22+00:00", "updated_at": "2026-08-05 02:41:42.423200+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-agents", "developer-tools", "large-language-models"], "entities": ["Ollama", "tinyllama"], "alternates": {"html": "https://wpnews.pro/news/beyond-rag-building-an-ai-coding-agent-with-planning-tool-execution-and-react", "markdown": "https://wpnews.pro/news/beyond-rag-building-an-ai-coding-agent-with-planning-tool-execution-and-react.md", "text": "https://wpnews.pro/news/beyond-rag-building-an-ai-coding-agent-with-planning-tool-execution-and-react.txt", "jsonld": "https://wpnews.pro/news/beyond-rag-building-an-ai-coding-agent-with-planning-tool-execution-and-react.jsonld"}}