<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kyle Zarifsadr on Medium]]></title>
        <description><![CDATA[Stories by Kyle Zarifsadr on Medium]]></description>
        <link>https://medium.com/@kyle.zarif?source=rss-da4b7947b517------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rDZEhounjOXgY7__LbHgmg.jpeg</url>
            <title>Stories by Kyle Zarifsadr on Medium</title>
            <link>https://medium.com/@kyle.zarif?source=rss-da4b7947b517------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 06:03:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kyle.zarif/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Vendor-neutral design doctrine for AI, RAG, classical ML, LLMs, and agentic systems]]></title>
            <link>https://medium.com/@kyle.zarif/vendor-neutral-design-doctrine-for-ai-rag-classical-ml-llms-and-agentic-systems-85f6569d8e0e?source=rss-da4b7947b517------2</link>
            <guid isPermaLink="false">https://medium.com/p/85f6569d8e0e</guid>
            <category><![CDATA[ai-agent-development]]></category>
            <category><![CDATA[agentic-ai-architecture]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[ai-system-design]]></category>
            <dc:creator><![CDATA[Kyle Zarifsadr]]></dc:creator>
            <pubDate>Sun, 13 Sep 2026 13:52:32 GMT</pubDate>
            <atom:updated>2026-09-13T14:00:45.671Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Applicable across AWS AgentCore, Google Vertex AI / Agent Engine, Microsoft Foundry, Kubernetes, and custom cloud stacks</em></p><p><strong>Core thesis</strong></p><p><strong>Every AI architecture is a chain of questions. Put each question in the place where the simplest sufficiently reliable mechanism can answer it and validate every boundary before uncertainty becomes authority or action.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cn2Qu4Kfyg82PAkvPLxklQ.png" /></figure><h3>1. Executive design doctrine</h3><p>Do not start with “Which model or agent framework should we use?” Start with “What exact questions must the system answer, what evidence is required, and what is allowed to happen if the answer is wrong?”</p><p>This doctrine treats an AI system as a typed decision pipeline rather than a monolithic “LLM app.” Each stage has a narrow responsibility: classify, retrieve, score, infer, plan, validate, act, or observe. The architectural objective is to minimize uncertainty at each stage and prevent a probabilistic component from silently becoming the system of record, policy engine, or transaction authority.</p><h3>The six governing principles</h3><p><strong>1. Ask before you generate: </strong>Translate the user goal into explicit questions and decision boundaries before selecting technology.</p><p><strong>2. Use the least-complex sufficient mechanism: </strong>Prefer deterministic code, database queries, search, or classical ML when they can answer the question. Use an LLM only for semantic uncertainty; use an agent only for dynamic sequencing.</p><p><strong>3. Retrieve evidence, not “knowledge theater”: </strong>RAG belongs only where the answer depends on external, mutable, private, long-tail, or attributable facts. Retrieval must be designed as an evidence pipeline, not as a vector database checkbox.</p><p><strong>4. Separate prediction from authority: </strong>A score, classification, or generated recommendation can influence a decision, but business policy, entitlements, and irreversible actions should live in deterministic systems or explicit approval gates.</p><p><strong>5. Validate at boundaries: </strong>Validate inputs before inference, evidence before generation, generated structures before tool use, authorization before action, and outcomes after action.</p><p><strong>6. Make agent autonomy proportional to uncertainty and reversibility: </strong>Predetermined workflows should remain workflows. Give an agent freedom only where the next step genuinely cannot be known in advance, and constrain tools, budgets, state, and permissions.</p><h3>2. Reference architecture: question → mechanism → gate</h3><p>Figure 1. The core design loop. The mechanism ladder is intentionally ordered from deterministic to increasingly autonomous.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*62qPe0typP3I658zTkq-7w.png" /><figcaption>Figure 1. The core design loop. The mechanism ladder is intentionally ordered from deterministic to increasingly autonomous.</figcaption></figure><h3>3. The questions AI designers should ask — in order</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*pGkRGWG56HkLdXDj2dy9ug.png" /></figure><h3>4. The mechanism ladder: where each technology belongs</h3><p>Design rule: if a cheaper, more deterministic mechanism can answer the question to the required quality, the more generative mechanism is architecturally unjustified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*oR-c7x84jrB_mw0Q0IISbg.png" /></figure><h3>5. Where logistic regression and XGBoost fit</h3><p>Classical ML should be treated as a specialized scoring service. It is often the right answer when the input is structured or featurizable and the output is a calibrated probability, ranking score, or classification. The model may sit before, between, or after LLM stages — but its role should remain explicit and typed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*QTQxgwAoi3RqyqL13NFUGA.png" /></figure><p>Important: a post-LLM classifier is not automatically a “truth checker.” It can detect learned patterns, categories, risk, or quality proxies. Factual correctness still requires evidence validation against authoritative sources or deterministic computation.</p><h3>6. RAG in the right place</h3><p>RAG is not the default companion to every LLM call. It belongs at a boundary where the generation depends on information outside the model parameters — especially private enterprise data, rapidly changing facts, long-tail material, or claims that require attribution.</p><h3>RAG admission questions</h3><p>· Does the answer depend on facts that are private, mutable, domain-specific, too detailed to trust from model memory, or must be cited?</p><p>· Can the relevant evidence be identified and permission-filtered before generation?</p><p>· What is the unit of retrieval: document, passage, row, event, entity, graph neighborhood, or API result?</p><p>· What should happen when evidence is missing, conflicting, stale, or low-confidence?</p><p>· How will retrieval quality be evaluated separately from generation quality?</p><h3>A robust retrieval chain</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*hIV-QKkH2sPtpwhHCMj6UA.png" /></figure><h3>7. When to use an LLM, and when to use an agent</h3><p>An LLM answers a semantic question. An agent owns a control loop.</p><p>If the application already knows the sequence of steps, keep orchestration in application/workflow code and call the LLM at the specific semantic steps. An agent becomes justified when the correct next tool or step depends on intermediate observations that cannot be enumerated economically in advance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*2Nrviux8C7vHuVXpPezG9w.png" /></figure><h3>Agentic admission test</h3><p>· Can the next step be fully specified as a workflow? If yes, do that instead of an agent.</p><p>· Does the model need to choose among tools based on observations produced during execution?</p><p>· Are tool contracts typed and narrow enough that a bad plan cannot become an unrestricted action?</p><p>· What is the maximum number of steps, model calls, tool calls, spend, and wall-clock time?</p><p>· What state can the agent read, write, or remember? What must expire?</p><p>· What actions are reversible? Which require deterministic authorization or human approval?</p><p>· How does the system detect loops, repeated failures, missing evidence, or plan drift?</p><p>· Can every tool call and decision be traced and replayed for evaluation?</p><h3>8. Validation architecture: never let one probabilistic stage validate itself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*vAl9aRxAYUh0Z3SW7xS2kQ.png" /></figure><p>The strongest architecture uses orthogonal validators: source-system checks, schemas, rules, independent models, or human review. “Ask the same LLM if its answer is correct” can be a heuristic, but it is not an independent control.</p><h3>9. State and memory: separate four things that are often conflated</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*1jg6Ak_J-XSHefWVN9tNCw.png" /></figure><h3>10. Cloud/deployment pattern: keep the doctrine above the vendor</h3><p>AWS, Google Cloud, and Microsoft now provide managed agent runtimes, tools/gateways, state or memory capabilities, identity, and observability. These are implementation substrates, not architecture principles. The application should preserve the same logical boundaries even when a vendor collapses several of them into one managed service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*qkuXSmsW7s-Usol-O1Qwpg.png" /></figure><h3>Current managed-platform mapping (illustrative, not prescriptive)</h3><p>As of September 2026, official platform documentation describes broadly similar building blocks: AWS Bedrock AgentCore provides runtime, memory, gateway, identity, code execution/browser, and observability; Google Vertex AI Agent Engine / Agent Platform provides managed runtime, sessions, memory, IAM/security controls, and observability; Microsoft Foundry Agent Service provides managed agent runtime, toolboxes, model access, identity/security, publishing, and observability. The names differ; the design questions do not.</p><h3>11. Three concrete reference patterns</h3><h3>Pattern A — Enterprise Q&amp;A / copilot</h3><p>1. Input gate authenticates user and determines tenant/permissions.</p><p>2. Router classifies domain and decides whether retrieval is required.</p><p>3. RAG retrieves permission-filtered evidence from search/SQL/APIs and reranks it.</p><p>4. Answerability gate checks evidence coverage.</p><p>5. LLM synthesizes a cited answer in a structured contract.</p><p>6. Post-generation validator checks citations/schema/policy; no agent is needed unless the user requests an action.</p><h3>Pattern B — Transactional assistant</h3><p>7. LLM interprets natural-language intent and extracts candidate parameters.</p><p>8. Deterministic validator normalizes and verifies required parameters.</p><p>9. Classical ML can add fraud/risk/priority scores where trained signal exists.</p><p>10. Policy engine checks permissions and business rules.</p><p>11. Agent or workflow invokes typed tools. High-impact actions require explicit confirmation/approval.</p><p>12. Outcome is verified from the system of record and reported back to the user.</p><h3>Pattern C — Investigation / research agent</h3><p>13. Router recognizes an open-ended task where next steps depend on findings.</p><p>14. Planner creates a bounded plan and selects tools.</p><p>15. Agent retrieves/searches/calculates in a step-limited loop.</p><p>16. Each observation carries provenance; contradictions trigger targeted retrieval rather than free-form speculation.</p><p>17. Final synthesis is validated against collected evidence and separated from unresolved hypotheses.</p><p>18. Telemetry captures the plan, calls, evidence, latency, cost, and outcome for replay evaluation.</p><h3>12. Architectural anti-patterns to reject</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*EHK2oRStRS7eUFefU3e9ow.png" /></figure><h3>13. One-page architecture decision matrix</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*L54Xh5wk36zM-0700fuKsw.png" /></figure><h3>14. The canonical design review checklist</h3><p><strong>Question decomposition</strong></p><p>· ☐ Can every model/tool call be written as a single explicit question?</p><p>· ☐ Is each output typed and consumed by a known next stage?</p><p>· ☐ Are “unknown / insufficient evidence / abstain” states explicit?</p><p><strong>Mechanism fit</strong></p><p>· ☐ Did we try deterministic logic, retrieval, or classical ML before an LLM?</p><p>· ☐ Is an agent used only because sequencing is genuinely dynamic?</p><p>· ☐ Is model tier selected by required capability rather than prestige?</p><p><strong>Evidence &amp; RAG</strong></p><p>· ☐ Is the authoritative source defined?</p><p>· ☐ Are permissions applied before model exposure?</p><p>· ☐ Are freshness, provenance, and answerability measured?</p><p><strong>Control &amp; safety</strong></p><p>· ☐ Can probabilistic output directly mutate important systems? If yes, why?</p><p>· ☐ Are tool arguments schema-validated and permissions least-privilege?</p><p>· ☐ Are high-impact actions reversible or approval-gated?</p><p><strong>State</strong></p><p>· ☐ Is session state separated from durable memory and systems of record?</p><p>· ☐ Does every durable memory have provenance, scope, TTL/correction policy?</p><p><strong>Evaluation</strong></p><p>· ☐ Do routing, retrieval, generation, tool execution, and outcome each have metrics?</p><p>· ☐ Can failed traces be replayed?</p><p>· ☐ Are cost and latency budgets tested along with quality?</p><h3>15. The core principle in one formula</h3><p>For each question q: choose the mechanism m that minimizes complexity + cost + operational risk, subject to required quality, latency, security, auditability, and reversibility. Then place an independent validation gate before m’s output gains more authority.</p><p>In plain language: route uncertainty to the right engine, and never let uncertainty silently accumulate into authority. Classical ML reduces statistical uncertainty; retrieval reduces informational uncertainty; LLMs reduce semantic uncertainty; agents reduce procedural uncertainty. Deterministic policy and human governance control authorization uncertainty. These are different problems and should remain different architectural components.</p><h3>16. Platform references (official documentation)</h3><p><strong>AWS — Amazon Bedrock AgentCore overview</strong> — Runtime, Memory, Gateway, Identity, Code Interpreter/Browser, Observability.<br> <a href="https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/what-is-bedrock-agentcore.html">https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/what-is-bedrock-agentcore.html</a></p><p><strong>AWS — AgentCore Gateway core concepts</strong> — Secure standardized access to tools, agents, and models.<br> <a href="https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-core-concepts.html">https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-core-concepts.html</a></p><p><strong>Google Cloud — Vertex AI Agent Engine overview</strong> — Managed runtime, context management, evaluation, observability and security controls.<br> <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/overview">https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/overview</a></p><p><strong>Google Cloud — Agent Engine Memory Bank setup</strong> — Session and durable-memory integration patterns.<br> <a href="https://docs.cloud.google.com/vertex-ai/generative-ai/docs/agent-engine/memory-bank/set-up">https://docs.cloud.google.com/vertex-ai/generative-ai/docs/agent-engine/memory-bank/set-up</a></p><p><strong>Microsoft — Foundry Agent Service overview</strong> — Managed agent runtime, toolboxes, model access, identity/security and observability.<br> <a href="https://learn.microsoft.com/en-us/azure/foundry/agents/overview">https://learn.microsoft.com/en-us/azure/foundry/agents/overview</a></p><p><strong>Microsoft — Basic Foundry chat reference architecture</strong> — Example of agent orchestration with grounding/retrieval and enterprise controls.<br> <a href="https://learn.microsoft.com/azure/architecture/ai-ml/architecture/basic-microsoft-foundry-chat">https://learn.microsoft.com/azure/architecture/ai-ml/architecture/basic-microsoft-foundry-chat</a></p><p>Prepared September 2026. Vendor capabilities evolve; the logical design principles in this document are intentionally vendor-neutral.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85f6569d8e0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LangGraph Deep Agents for Invoking MCP Servers in Finance]]></title>
            <link>https://medium.com/@kyle.zarif/langgraph-deep-agents-for-invoking-mcp-servers-in-finance-f90b2b819701?source=rss-da4b7947b517------2</link>
            <guid isPermaLink="false">https://medium.com/p/f90b2b819701</guid>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[deep-agent]]></category>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[agent-skills]]></category>
            <category><![CDATA[mcp-client]]></category>
            <dc:creator><![CDATA[Kyle Zarifsadr]]></dc:creator>
            <pubDate>Mon, 05 Jan 2026 03:12:10 GMT</pubDate>
            <atom:updated>2026-01-05T03:12:10.847Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FP1adop2-1Li8dLsvn7QEA.png" /><figcaption>MCP Workspace Overview</figcaption></figure><p>Modern LLM applications often start simple — chatting with a model and calling a few tools — but quickly run into complexity as workflows grow more structured and multi-step. This project explores that progression using <strong>Model Context Protocol (MCP)</strong> servers and three increasingly capable client styles, all operating over the same set of finance-focused tools.</p><p>The result is a small but practical workspace that demonstrates how <strong>classic</strong>, <strong>agentic</strong>, and <strong>deep agent</strong> architectures can orchestrate the same MCP servers — each trading simplicity for structure, transparency, and control.</p><p>All source code is open on GitHub at <a href="https://github.com/kylezarif/mcp">https://github.com/kylezarif/mcp</a> Clone it, follow the README to install and configure the MCP clients and servers, and run the examples on your end to explore how each architecture works with real finance data.</p><h3>The Big Idea</h3><p>All three clients talk to the <strong>same MCP servers</strong>, discovered from ~/.mcp/config.json. What changes is <strong>how much structure the client adds</strong> around planning, tool invocation, and intermediate state.</p><p>Think of it as a spectrum:</p><ul><li><strong>Classic MCP client</strong> → fast, minimal, direct</li><li><strong>LangGraph agentic client</strong> → safer, normalized, more robust</li><li><strong>LangGraph deep agent</strong> → planned, auditable, multi-step</li></ul><p>This makes it easy to start simple and layer in sophistication only when you need it.</p><h3>MCP Servers: A Shared Tooling Layer</h3><p>At the bottom of the stack are <strong>MCP servers</strong>, each exposing a small set of tools over stdio. In this workspace, they live under mcp/mcp-servers/ and rely exclusively on <strong>free / keyless finance data sources</strong>:</p><ul><li><strong>sec-filings</strong> — SEC EDGAR submissions and company facts</li><li><strong>gdelt-news</strong> — News search and topic trends via GDELT</li><li><strong>macro-data</strong> — Treasury Fiscal Data, World Bank indicators, ECB series</li><li><strong>stooq-prices</strong> — Historical OHLCV market data</li><li><strong>fhfa-hpi</strong> — FHFA house price index datasets</li></ul><p>Servers are launched with uv and discovered automatically via:</p><pre>~/.mcp/config.json</pre><p>From the clients’ perspective, these servers simply advertise tools — nothing about the servers changes as we move from classic to deep agents.</p><h3>Client #1: Classic MCP Client</h3><p>The <strong>classic MCP client</strong> (mcp/mcp-client) is intentionally minimal.</p><p>It’s a single chat loop:</p><ul><li>OpenAI model</li><li>tools advertised as server__tool</li><li>rolling in-memory message history</li><li>direct routing of tool calls</li></ul><p>There’s no planning, no graph, and no persistent state. This is the fastest way to poke at MCP servers from a CLI and verify that tools work as expected.</p><p><strong>Use it when</strong> you want:</p><ul><li>minimal dependencies</li><li>fast iteration</li><li>straightforward “ask → call tool → print result” workflows</li></ul><h3>Client #2: Agentic MCP Client (LangGraph)</h3><p>The <strong>agentic client</strong> (mcp/mcp-agentic) wraps the same loop inside a <strong>LangGraph state machine</strong>:</p><p>This adds a few important improvements:</p><ul><li>explicit state handling</li><li>normalized tool names and outputs</li><li>heuristics for missing arguments (tickers, CIKs, dates, topics)</li><li>more consistent formatting across turns</li></ul><p>It still feels lightweight, but it’s noticeably more resilient than the classic loop — especially when tools return empty results or partial errors.</p><p><strong>Use it when</strong> you want:</p><ul><li>better reliability without much added complexity</li><li>safer multi-turn sessions</li><li>clearer separation between reasoning and tool execution</li></ul><h3>Client #3: Deep MCP Agent (LangGraph + Planning)</h3><p>The <strong>deep agent</strong> (mcp/mcp-deep-agents) is where things get interesting.</p><p>This client introduces:</p><ul><li><strong>explicit planning (TODOs)</strong></li><li>a <strong>persistent scratchpad</strong> at runs/&lt;timestamp&gt;/</li><li>structured artifacts:</li><li>plan.json – what the agent intends to do</li><li>run.log – tool calls and results</li><li>saved outputs (CSV, JSON, text)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Hw4uqqhCDZLydAgX7E20Q.png" /><figcaption>Deep MCP Agent Architecture (Planning, Execution, and Persistent Context)</figcaption></figure><p>Instead of treating every request as a single opaque loop, the deep agent makes its reasoning <em>inspectable</em>. You can see what it planned, which tools it called, and what data it produced.</p><p>This is especially useful for <strong>multi-step finance workflows</strong>, where trust and traceability matter.</p><p><strong>Use it when</strong> you want:</p><ul><li>transparent decision-making</li><li>revisitable intermediate results</li><li>multi-step analysis you can audit or extend</li></ul><h3>Why Three Clients?</h3><p>Because <strong>architecture should scale with intent</strong>:</p><ul><li><strong>Classic</strong>: fastest way to explore tools</li><li><strong>Agentic</strong>: safer, cleaner, more forgiving</li><li><strong>Deep Agent</strong>: planned, persistent, and auditable</li></ul><p>You don’t need deep agents for everything — but when tasks span multiple steps, data sources, or transformations, the added structure pays for itself quickly.</p><h3>Example Prompts to Try</h3><ul><li><em>“List recent filings for CIK 0000320193.”</em></li><li><em>“Search news about Tesla stock in the last week.”</em></li><li><em>“Get recent Treasury yields and describe the 2s/10s curve shape over the past month.”</em></li><li><em>“Pull World Bank CPI indicator FP.CPI.TOTL for USA from 2015–2024 and summarize the trend.”</em></li><li><em>“Fetch daily OHLCV for AAPL.US in Jan 2024, compute 20/50 SMAs, and report whether 20 &gt; 50.”</em></li></ul><p>For the deep agent, inspect the runs/ directory after each session—it’s the clearest way to understand what the agent <em>actually did</em>.</p><h3>Closing Thoughts</h3><p>This workspace isn’t about building a single “best” agent. It’s about showing how <strong>MCP stays constant while orchestration evolves</strong> — from direct calls, to agentic loops, to fully planned workflows.</p><p>Start simple. Add structure only when you need it. And keep your tools decoupled from your reasoning layer.</p><p>If you build something interesting on top of this, I’d love to see it.</p><h3>References</h3><p>LangChain. (n.d.). <em>DeepAgents quickstart</em>. Retrieved January 5, 2026, from <a href="https://docs.langchain.com/oss/python/deepagents/quickstart">https://docs.langchain.com/oss/python/deepagents/quickstart</a></p><p>Model Context Protocol. (n.d.). <em>Build a server</em>. Retrieved January 5, 2026, from <a href="https://modelcontextprotocol.io/docs/develop/build-server">https://modelcontextprotocol.io/docs/develop/build-server</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f90b2b819701" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing RAG Systems: Patterns, Tradeoffs, and Code Examples]]></title>
            <link>https://medium.com/@kyle.zarif/designing-rag-systems-patterns-tradeoffs-and-code-examples-95c33a8b2df7?source=rss-da4b7947b517------2</link>
            <guid isPermaLink="false">https://medium.com/p/95c33a8b2df7</guid>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[agentic-rag]]></category>
            <category><![CDATA[ai-engineering]]></category>
            <category><![CDATA[gi̇thub]]></category>
            <dc:creator><![CDATA[Kyle Zarifsadr]]></dc:creator>
            <pubDate>Sun, 04 Jan 2026 02:07:56 GMT</pubDate>
            <atom:updated>2026-01-04T02:24:10.837Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0vTITOk9E2OFijzAQPGr3w.png" /></figure><p>Retrieval-Augmented Generation (RAG) is no longer a single pattern — it’s a design space.</p><p>From simple single-turn question answering to fully agentic systems that plan, reason, and call tools, RAG architectures exist on a spectrum of complexity. Choosing the <em>right</em> approach is less about novelty and more about understanding tradeoffs: latency vs. reliability, simplicity vs. capability, cost vs. coverage.</p><p>This article is a practical deep dive into RAG system design, grounded in <strong>five progressively richer implementations</strong> from this repository:</p><p><a href="https://github.com/kylezarif/rag">https://github.com/kylezarif/rag</a></p><p>Rather than presenting RAG as a monolith, we’ll examine how and <em>why</em> each pattern exists, what problems it solves, and when it’s the right tool for the job.</p><h3>The Five RAG Variants in This Workspace</h3><p>Each project in the repo represents a snapshot along the RAG maturity curve:</p><ul><li><strong>rag-base</strong> — Minimal, single-turn RAG</li><li><strong>rag-conversational</strong> — RAG with short-term conversational memory</li><li><strong>rag-corrective</strong> — Corrective RAG (CRAG) with retrieval grading and external fallback</li><li><strong>rag-adoptive</strong> — Adaptive routing between direct, RAG, and agent paths</li><li><strong>rag-agentic</strong> — Fully agentic RAG using LangGraph and tool orchestration</li></ul><p>Across these variants, the goal is not feature accumulation — it’s architectural clarity. Each step adds <em>only</em> what’s needed to solve a new class of problems.</p><h3>1. What Makes a RAG System?</h3><p>At its core, RAG couples <strong>retrieval</strong> with <strong>generation</strong>:</p><ol><li>Embed the user query</li><li>Retrieve relevant chunks from a vector store</li><li>Assemble a prompt with retrieved context</li><li>Generate a grounded response</li></ol><p>Around this loop, additional components emerge as needs grow:</p><ul><li>Chunking strategies for long documents</li><li>Vector databases for similarity search</li><li>Prompt composition logic</li><li>Conversational memory</li><li>External tools and APIs</li><li>Routing and decision gates</li><li>Agentic control loops</li></ul><p>The projects in this repo show how these components can be layered incrementally — without overengineering early.</p><h3>2. Shared Dataset and Core Building Blocks</h3><p>All variants operate over the same synthetic <strong>travel corpus</strong> (12 documents covering planning, budgeting, safety, weather, food allergies, remote work, and more).</p><p>Each project:</p><ul><li>Uses OpenAI embeddings (text-embedding-3-small)</li><li>Stores vectors in PostgreSQL with pgvector</li><li>Chunks documents with overlap for better recall</li><li>Runs deterministic generation (temperature=0) for grounded outputs</li></ul><p>Key shared modules include:</p><ul><li>config.py — models, table names, chunk sizes</li><li>data_loader.py — chunking and ingestion</li><li>db.py — pgvector schema and similarity search</li><li>embeddings.py — embedding calls</li><li>conversation.py — rolling history buffers</li><li>external_search.py — weather tool with LLM-based location correction</li></ul><p>Each variant composes these primitives differently — but no variant rewrites them from scratch.</p><h3>3. Architecture by Variant</h3><h3>3.1 Minimal RAG (rag-base)</h3><p><strong>Pipeline:</strong> Retrieve → Prompt → Answer</p><p>This is RAG at its simplest:</p><ul><li>Stateless</li><li>No memory</li><li>No external tools</li><li>Lowest latency and cost</li></ul><p><strong>Use it when:</strong><br> Your corpus is small and static, queries are independent, and speed matters more than conversational nuance.</p><h3>3.2 Conversational RAG (rag-conversational)</h3><p><strong>Pipeline:</strong> Retrieve → Prompt + recent history → Answer</p><p>Adds a rolling window of conversation (last five turns), enabling follow-ups and pronoun resolution.</p><p><strong>Use it when:</strong><br> Users ask contextual follow-ups, but tasks remain simple and deterministic.</p><h3>3.3 Corrective RAG (rag-corrective)</h3><p><strong>Pipeline:</strong><br> Retrieve → Grade retrieval → External fallback (if needed) → Answer</p><p>This pattern introduces a <strong>decision gate</strong>. An LLM evaluates whether retrieved context is:</p><ul><li>Correct</li><li>Ambiguous</li><li>Incorrect</li></ul><p>If retrieval is weak — or the query implies live data (e.g., weather) — the system invokes an external tool.</p><p><strong>Use it when:</strong><br> Hallucinations are costly and corpus coverage is uneven.</p><h3>3.4 Adaptive RAG (rag-adoptive)</h3><p><strong>Pipeline:</strong><br> Classifier → Direct | RAG | Agent → Answer</p><p>Instead of forcing all queries through the same pipeline, a lightweight classifier chooses the cheapest sufficient path:</p><ul><li><strong>Direct:</strong> greetings, chit-chat, known facts</li><li><strong>RAG:</strong> internal knowledge + optional tools</li><li><strong>Agent:</strong> multi-step reasoning and comparison</li></ul><p><strong>Use it when:</strong><br> Traffic is mixed and you want to control latency and cost without sacrificing capability.</p><h3>3.5 Agentic RAG (rag-agentic)</h3><p><strong>Pipeline:</strong><br> LangGraph loop: LLM ↔ Tools → Final Answer</p><p>This is full agentic RAG:</p><ul><li>Explicit planning</li><li>Iterative tool calls</li><li>Stateful execution graph</li><li>Vector search and weather tools bound directly to the model</li></ul><p><strong>Use it when:</strong><br> Tasks require decomposition, live data, and iterative reasoning — accepting higher overhead in exchange for flexibility.</p><h3>4. Design Implications by Component</h3><h3>Chunking &amp; Retrieval</h3><ul><li>Word-based chunks with overlap balance recall and precision</li><li>Separate tables per variant simplify experimentation</li><li>pgvector keeps vector search close to application logic</li></ul><p><strong>Tip:</strong> Tune chunk size to your query shape, not arbitrarily.</p><h3>Prompting &amp; Determinism</h3><p>All grounded generation uses temperature=0. Prompts explicitly instruct the model to <strong>admit insufficient context</strong>.</p><p><strong>Tip:</strong> Make uncertainty a feature, not a failure mode.</p><h3>Memory</h3><ul><li>No memory for base</li><li>Rolling windows for conversational, corrective, adoptive, and agentic</li></ul><p><strong>Tip:</strong> For long sessions, summarize or vectorize history — don’t blindly append it.</p><h3>Routing &amp; Gating</h3><ul><li>CRAG uses grading</li><li>Adaptive uses classification</li><li>Agentic defers decisions to the graph</li></ul><p><strong>Tip:</strong> Log routing decisions. You can’t tune what you can’t see.</p><h3>External Tools</h3><p>Weather (via Open-Meteo) demonstrates:</p><ul><li>LLM-corrected inputs</li><li>Multi-city extraction</li><li>Tool reuse across patterns</li></ul><p><strong>Tip:</strong> Add tools sparingly. Reliability matters more than breadth.</p><h3>5. Choosing the Right Pattern</h3><p>Use CaseRecommended PatternStatic FAQrag-baseShort conversationsrag-conversationalGuardrails + live datarag-correctiveMixed trafficrag-adoptiveComplex planningrag-agentic</p><p>There is no universal “best” RAG — only the best fit for your constraints.</p><h3>6. Beyond This Repository</h3><p>The repo focuses on clarity, not exhaustiveness. Natural extensions include:</p><ul><li><strong>GraphRAG</strong> for relational knowledge</li><li><strong>Multi-stage retrieval + reranking</strong></li><li><strong>Domain-specific indexes</strong></li><li><strong>Verification and self-consistency loops</strong></li><li><strong>Hybrid long-term memory systems</strong></li><li><strong>Policy and safety layers</strong></li></ul><p>Each can be layered onto the existing designs without rewriting the core.</p><h3>Final Thoughts</h3><p>RAG is not a checkbox — it’s an architectural choice.</p><p>The five implementations in this repository form a ladder:</p><ul><li>Start simple</li><li>Add guardrails when necessary</li><li>Route intelligently when traffic grows</li><li>Go agentic only when the problem truly demands it</li></ul><p>A lean RAG system that answers quickly and honestly will always beat an over-engineered agent that solves problems you don’t have.</p><p>If you’re designing RAG systems in production, the most important skill isn’t knowing <em>how</em> to build every pattern — it’s knowing <strong>when not to</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95c33a8b2df7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>