惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
Recent Announcements
Recent Announcements
B
Blog
D
Docker
V
V2EX
GbyAI
GbyAI
L
LangChain Blog
博客园 - Franky
U
Unit 42
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
博客园_首页
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客

Stories by HARSHA J S on Medium

Mastering LangChain 1.2: Part 12 — The Elephant’s Memory: Persistent AI Agents that Never Forget Mastering LangChain 1.2: Part 11 — Custom Middleware Hooks: Orchestrating the AI Lifecycle Mastering LangChain 1.2: Part 10 — Human-in-the-Loop: Adding an “Approval” Button to Your AI Agents Mastering LangChain 1.2: Part 9 — Structured Outputs: Turning Messy Chat into Clean Data Mastering LangChain 1.2: Mastering LangChain 1.2: Mastering LangChain 1.2: Part 6 — Dynamic Tool Security: The “Triple-Lock” Guardrail Mastering LangChain 1.2: Part 5 — Dynamic Model Routing: Escalating to Senior AI in Emergencies Mastering LangChain 1.2: Part 4 — Scaling with Middleware and Smart Summarization
Mastering LangChain 1.2: Part 13 — Agentic RAG: Why Your ...
HARSHA J S · 2026-03-30 · via Stories by HARSHA J S on Medium

HARSHA J S

Press enter or click to view image in full size

If you’ve been following the AI space, you’ve definitely heard of RAG (Retrieval-Augmented Generation). The idea is simple: since an LLM has a knowledge cutoff and a limited context window, you should fetch relevant documents from a database and “stuff” them into the prompt before the AI answers.

Traditional RAG (often called “2-Step RAG”) follows a rigid pipeline:

  1. Search the database for keywords in the user’s query.
  2. Pass everything found to the LLM to generate an answer.

But there’s a problem. What if the user asks: “How do I add two numbers in Python?” A standard RAG pipeline will still waste time searching your internal company runbooks for “Python math,” potentially retrieving irrelevant data and confusing the model.

Today, we are building Agentic RAG — giving the AI the power to decide if, when, and how to retrieve information.

1. The Mock Knowledge Base

In a production environment, you would use a Vector Database like Pinecone or ChromaDB. For this example, we’ll use a simple dictionary to simulate our company’s internal “Runbooks.”

MOCK_VECTOR_DB = {
"payment service": "RUNBOOK: To restart the payment service, use `kubectl rollout restart deployment/payment-v2`.",
"kafka lag": "RUNBOOK: Kafka lag usually means consumers are under-provisioned. Scale them up.",
}

2. Defining the Retrieval Tool

We wrap our database search in a LangChain @tool. The critical part is the docstring. It tells the AI exactly what is inside this database so it can decide if it needs to look there.

@tool
def search_internal_runbooks(query: str):
"""
Searches internal DevOps Knowledge Base for runbooks.
Use this only when you need specific company-specific procedures.
"""
# Logic to search MOCK_VECTOR_DB...
return results

3. The Power of “Toggling” RAG

When we create our agent and give it the

When we create our agent and give it the search_internal_runbooks tool, something magical happens. The agent becomes a “Thinking Gatekeeper.”

agent = create_agent(
model=model,
tools=[search_internal_runbooks],
)

Scenario A: The Internal Query

  • User: “How do I restart the payment service?”
  • Agent’s Thought: “I don’t know the specific command for this user’s company ‘payment service.’ Better check the internal runbooks.”
  • Action: Calls the tool, gets the kubectl command, and provides a precise answer.

Scenario B: The General Query

  • User: “Write a Python function to add two numbers.”
  • Agent’s Thought: “I already know Python perfectly well. Searching the DevOps runbooks for this would be a waste of time.”
  • Action: Skips the tool entirely and writes the code directly.

Why Agentic RAG is the Future

  1. Cost & Performance: You only pay for search and retrieval when it’s actually needed.
  2. Higher Accuracy: By not “stuffing” irrelevant documents into the prompt for general questions, you reduce the chance of the model getting distracted or hallucinating based on bad search results.
  3. Complex Reasoning: An agent can search once, realize the information is missing a specific detail, and then search again with a different query. A traditional pipeline can’t do that.

Conclusion: Selective Intelligence

Agentic RAG represents a shift from “Passive Retrieval” to “Active Reasoning.” Your AI is no longer just a box that receives data; it’s an assistant that knows the limits of its own knowledge. It knows when to rely on its training and when to reach for a book.

This marks the end of our deep dive into LangChain 1.2 agents. We’ve covered everything from Unified Interfaces to Dynamic Security and now Agentic RAG.

💬 What do you think?
Drop your thoughts, questions, or suggestions in the comments below!

Check out my YouTube channel for more exciting content! [YouTube Channel Link — Harsha Selvi]

Disclaimer: This text has been rephrased using AI tools, and some parts are derived from various sources to provide a comprehensive overview.

#AI #LangChain #RAG #MachineLearning #Python #AIEngineering #Search #NLP #DevelopmentTips