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

推荐订阅源

博客园 - 三生石上(FineUI控件)
D
Docker
GbyAI
GbyAI
宝玉的分享
宝玉的分享
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Vercel News
Vercel News
博客园_首页
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
V
V2EX
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

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