Skip to content
Get App

LangGraph Template: Multi-Agent RAG Research

Introduction to LangGraph's Multi-Agent RAG Research template for efficient document retrieval and query answering in LangChain.

Key Takeaways

  • Multi-agent architecture enhances modularity and efficiency in research and retrieval tasks.
  • Subgraphs enable hierarchical graph structures facilitating complex workflows.
  • State management is crucial for communication between parent and child agents.
  • LangGraph's template structure promotes clean code organization and scalability.
  • The approach supports breaking down complex queries into manageable research steps.

What the video covers

  • Introduction of the Rag Research Agent template for LangGraph Studio, inspired by LangChain documentation Q&A service.
  • Demonstration of query analysis to determine relevance and need for additional user info.
  • Breakdown of user questions into multiple research steps and queries.
  • Use of a multi-agent architecture with a parent agent and a child researcher agent.
  • Parent agent handles query analysis, routing, research plan creation, and user response.
  • Researcher agent conducts document retrieval from a vector store based on the research plan.
  • Explanation of subgraphs in LangGraph, where subgraphs act as nodes within parent graphs.
  • Code organization includes separate modules for each graph with graph.py and state.py files.
  • State schema defines communication between parent and child graphs, including message passing and query routing.
  • The system exemplifies a custom multi-agent workflow with predefined agent call order.

Answers

Questions about this video

What is the Rag Research Agent template introduced in the video?

It is a new template for LangGraph Studio designed to help users answer questions by breaking down queries into research steps and retrieving relevant documents using a multi-agent architecture.

How does the multi-agent system work in this template?

The system uses a parent agent for query analysis, routing, and planning, and a child researcher agent that retrieves documents based on the research plan, with communication managed via subgraphs.

What role do subgraphs play in LangGraph's multi-agent architecture?

Subgraphs act as nodes within a parent graph, allowing modular workflows where complex tasks like conducting research are broken down into smaller nodes such as generating queries and retrieving documents.

Full Transcript — Download SRT & Markdown

00:01
Speaker A
Hi everyone, this is Faim from L Chain. Today, I'd like to introduce a new template we're releasing for Langra Studio: the Rag Research Agent template. It was motivated by our work on the Chat L Chain service we have for helping users answer questions about L Chain documentation.
00:14
Speaker A
answer questions about L chain documentation let's dive in going to ask a simple question about L chain documentation what are the runnables in L chain how me walk you through what's happening here first we're going to analyze the query and decide is it about
00:29
Speaker A
Let's dive in. We're going to ask a simple question about L Chain documentation: What are the runnables in L Chain? Let me walk you through what's happening here. First, we're going to analyze the query and decide: is it about L Chain? Do we need more information from the user, or is it completely unrelated? In our case, it is related to L Chain.
00:43
Speaker A
multiple research steps for each of those steps we're going to call the conduct research node and we're going to further do two additional steps one calling conduct research we're going to first take the question from the research step and break it down into
01:00
Speaker A
Then, we're going to create a research plan or effectively break down the original user's question into multiple research steps. For each of those steps, we're going to call the Conduct Research node, and we're going to further do two additional steps. One, calling Conduct Research, we're going to first take the question from the research step and break it down into individual queries.
01:14
Speaker A
end we're going to pass combine documents to the parent graph to respond to the user with the context of the retrieve documents this system is an example of a multi-agent architecture for more information on MTI multi- aent architectures check out Harrison's
01:32
Speaker A
For each of those queries, we're going to retrieve documents from our vector store. We're going to run that for each step in the research plan until we have all of the documents for each step. Then, at the end, we're going to pass combined documents to the parent graph to respond to the user with the context of the retrieved documents.
01:50
Speaker A
routing creating research plan and then responding to the user as well as the researcher agent that is actually conducting research or ring the documents based on the research plan there're two agents and what enables adding the child researcher agent in
02:09
Speaker A
This system is an example of a multi-agent architecture. For more information on multi-agent architectures, check out Harrison's conceptual video. Specifically, in our case, it's a custom multi-agent workflow where the order in which the agents are called is defined ahead of time.
02:25
Speaker A
generate queries and retrieve documents and now i' like to talk about the code organization and some key Concepts when working with multi-agents and subgraphs in L graph so for the template we're going to have separate modules for each graph in the source
02:42
Speaker A
The agents in our system are the parent agent that is doing query analysis and routing, creating the research plan, and then responding to the user, as well as the researcher agent that is actually conducting research or retrieving the documents based on the research plan. There are two agents, and what enables adding the child researcher agent in this case is Lang Graph's ability to add subgraphs.
02:56
Speaker A
and graph Pi file with the definition of graph nodes and edges as well as state.
03:01
Speaker A
Subgraphs are simply graphs that are added to another graph as nodes. So, in our case, Conduct Research is a node that calls a subgraph, and that subgraph contains two additional nodes: Generate Queries and Retrieve Documents.
03:14
Speaker A
each other let's take a closer look at the state for each of the graphs the parent graph is going to have the messages fied in the state that is the field that we use to invoke the graph for example we pass the human message
03:29
Speaker A
Now, I'd like to talk about the code organization and some key concepts when working with multi-agents and subgraphs in Lang Graph. For the template, we're going to have separate modules for each graph in the source code. So, in this case, we're going to have the Retrieval Graph directory here, as well as the Researcher Graph subdirectory here for the subgraph.
03:44
Speaker A
state are going to be the router that's going to contain information about the type of the query after we analyze it for example General query more information or L chain and we're going to have additional logic there for why
03:58
Speaker A
They're both going to have a similar structure in that they're going to have a graph.py file with the definition of graph nodes and edges, as well as state.py, which is going to contain the state schema definition for each graph.
04:11
Speaker A
also has documents fied that's what we're going to populate when retrieving the documents and we're going to pass this to the parent graph we're also going to receive the question which is effectively just one of the steps from
04:23
Speaker A
The state schema for working with parent and subgraphs is one of the most important concepts because it defines how the parent and child graph communicate with each other. Let's take a closer look at the state for each of the graphs.
04:38
Speaker A
inside the parent graph if we look at the conduct research node you'll see that we're directly invoking the researcher graph or subgraph inside that node function and when we're invoking it we're using question key which is only available in the state of the subgraph
04:54
Speaker A
The parent graph is going to have the messages field in the state. That is the field that we use to invoke the graph. For example, we pass the human message with the user query to start executing the graph. Then, at the end, once we get the response back from the graph, it's going to be a message or AI message with the final response.
05:06
Speaker A
only needs to know current step it needs to retrieve the documents for and so that's what we're doing here we pass a single step from the research plan as question and we get the list of retriev documents back from the researcher graph
05:21
Speaker A
The other keys in the parent state are going to be the router, which is going to contain information about the type of the query after we analyze it. For example, general query, more information, or L Chain. We're going to have additional logic there for why we analyze this.
05:33
Speaker A
conceptual videos and guides on multi-agent architectures and subgraphs we're excited to see what you do with this template and the applications you build on top of that catch you next time
Topics:LangGraphLangChainMulti-Agent ArchitectureRAGResearch AgentSubgraphsDocument RetrievalVector StoreQuery AnalysisCode Organization

Get More with the SozAI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries and speaker detection. 30 minutes free.

Or transcribe another YouTube video here →