Build Agentic RAG Systems
An archived LangGraph example implementing Agentic RAG - an agent that decides whether to retrieve.
Why it matters
Implement an agentic Retrieval Augmented Generation (RAG) system using LangGraph. This asset enables LLMs to decide when to retrieve information from an index, enhancing their decision-making capabilities for complex queries.
Outcomes
What it gets done
Index external documents for retrieval.
Create a retriever tool for LLM access.
Define a graph state to manage messages.
Orchestrate agent decisions and tool calls.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/lg-langgraphagenticrag | bash Overview
Agentic RAG
An archived LangGraph example implementing Agentic RAG - an agent that decides whether to call a retriever tool. Use it as a reference pattern for a retrieval agent that only retrieves when it decides it's necessary.
What it does
An archived LangGraph example (no longer maintained - see LangChain's consolidated documentation for current guidance) implementing an Agentic RAG pattern: a retrieval agent that decides for itself whether to call a retriever tool, rather than always retrieving on every query. Three blog posts are indexed and wrapped as a retriever tool; the agent (call_model) can choose to call that tool (action), gets the tool output appended to its message state, and is called again with that new context.
When to use - and when NOT to
Use this as a reference pattern for building a retrieval agent that decides on its own whether retrieval is even necessary for a given question, instead of a fixed retrieve-then-generate pipeline. It is explicitly archived and no longer updated, so treat it as a study reference rather than a production dependency - check LangChain's current consolidated documentation for up-to-date APIs and patterns.
Inputs and outputs
State: a list of messages, appended to by each node as the graph runs. Nodes: call_model (the agent, which decides whether to call the retriever tool) and action (executes the retriever tool call). Conditional edges route from the agent to either the tool-calling action or onward, based on whether the agent decided to call a function. Output: the final message state after the agent has optionally retrieved and incorporated context.
Integrations
Built with LangGraph and LangChain, and integrates with LangSmith for tracing, debugging, and monitoring the graph during development.
Who it's for
Developers building an agent that should retrieve from an index only when it decides retrieval is actually useful for the question at hand, rather than retrieving unconditionally on every turn.
Source README
This directory is retained purely for archival purposes and is no longer updated. Please see the newly consolidated LangChain documentation for the most current information and resources.
Agentic RAG
Retrieval Agents are useful when we want to make decisions about whether to retrieve from an index.
To implement a retrieval agent, we simple need to give an LLM access to a retriever tool.
We can incorporate this into LangGraph.
Setup
First, let's download the required packages and set our API keys:
Set up LangSmith for LangGraph development
Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph - read more about how to get started here.
Retriever
First, we index 3 blog posts.
Then we create a retriever tool.
Agent State
We will define a graph.
A state object that it passes around to each node.
Our state will be a list of messages.
Each node in our graph will append to it.
Nodes and Edges
We can lay out an agentic RAG graph like this:
- The state is a set of messages
- Each node will update (append to) state
- Conditional edges decide which node to visit next
Graph
- Start with an agent,
call_model - Agent make a decision to call a function
- If so, then
actionto call tool (retriever) - Then call agent with the tool output added to messages (
state)
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.