My 10-Node Agentic RAG Architecture: Combining LangGraph, Cohere, Pinecone & MCP for Dense Legal Parsing
Hey All, I recently finished building the **Agentic Financial Parser*\ * โ an autonomous AI agent designed to ingest, parse, query, and reason over extremely dense Indian financial and legal documents (like Budgets and Constitutions). Due to hardware constraints (512MB RAM limits on Render), I had to architect and deploy this in three separate logical components across different repositories: Core RAG (V1), Hybrid Reranking (V2), and an isolated MCP Tool Server. But conceptually, they form one unified Agentic Workspace. Here is a breakdown of the unified architecture and how I used LangGraph to glue it all together. ๐ง The Core Engine: 10-Node LangGraph StateMachine Instead of a linear retrieval chain, I built a `StateGraph` that handles conditional routing and cyclic flows. Pre-Processing Nodes: Intent classifier categorizes queries (`abusive`, `greeting`, `vague`, `rag_query`). Greetings bypass the DB entirely (zero cost), while abusive queries hit a hard Reject node. CrossQuestioner (HITL): If a query is vague, the graph routes to a clarification node (max 2 rounds) befo0re attempting retrieval. Hallucination Guard: Post-generation, the response is verified against the retrieved context. If it fails, it triggers a ReAct Fallback Prompt. 6 ๐ The Memory: Jina MRL + Cohere Neural Reranker Parsing 20+ Government Acts and Financial Frameworks resulted in 15,408 chunks. * Vector DB (Pinecone): I used **Jina v3 with Matryoshka Representation Learning (MRL)*\ . By truncating vectors from 1024 to 256 dimensions, I saved * **75% on Pinecone storage**** without losing semantic quality. * Hybrid RAG (V2): The retriever sweeps Pinecone for broad candidate chunks and passes them through a Cohere Neural Reranker (`cohere-rerank-v3`) to distill them down to the Top 10 Golden Chunks. * Semantic Caching: Upstash Redis sits in front, providing+ <100ms cache hits for repeated queries. ๐ The Action Layer: Anthropic Model Context Protocol (MCP) To prevent my LangGraph agent from becoming bloated with hardcoded API logic, I fully decoupled tool execution using the newly released MCP Protocol . I built a stateless `FastMCP` Server running over JSON-RPC/SSE. The LangGraph `tools` node dynamically orchestrates 12+ tools through this isolated layer: * Financial Data: RapidAPI (Yahoo Finance) for live market data. * GitHub Analytics: Reading repos, PRs, and commit history. * Gmail (SMTP/IMAP): Reading threads and drafting semantic replies. * HITL Email Guard: Any sensitive action (like sending an email) triggers a Generative UI component in the React frontend, pausing the LangGraph state until explicit human approval is received. ๐ง Security & Reliability * 7-Layer Upload Security: Handles user document uploads securely (Magic Byte Verify, SHA-256 Dedup, MongoDB TTL auto-cleanup). * Dynamic OpenRouter Ensemble: Generation routes primarily through `nvidia/nemotron-3-super-120b-a12b:free`, with a Pybreaker circuit-breaker that automatically fails over to `gemini-3.5-f...