Back to feed
Renewal·마흔의 생활코딩

LangGraph | Agentic RAG with LangChain

NS
normalstory
cover image
YouTube 영상 미리보기YouTube
external media
YouTube 영상 미리보기YouTube
external media
YouTube 영상 미리보기YouTube
external media

Video summaries

  1. No summary yet.

  2. No summary yet.

  3. No summary yet.

*Reference video 2. LangGraph Crash Course with code examples

 

 

*Note

LangGraph is

LangGraph is built on top of LangChain and is fully interoperable with the LangChain ecosystem.
LangGraph is built on top of LangChain and completely interoperable with the LangChain ecosystem.

Summary: LangGraph is a module built on top of LangChain to better create cyclical graphs, which are often needed in agent runtimes.
TL;DR: LangGraph is module built on top of LangChain to better enable creation of cyclical graphs, often needed for agent runtimes.

Its main use is to add cycles to LLM applications. Crucially, this is not a DAG framework. If you want to build a DAG, you should use LangChain Expression Language.
The main use is for adding cycles to your LLM application. Crucially, this is NOT a DAG framework. If you want to build a DAG, you should use just use LangChain Expression Language.

Cycles are important for agent-like behavior, where an LLM is called repeatedly in a loop and asked what action to take next.
Cycles are important for agent-like behaviors, where you call an LLM in a loop, asking it what action to take next.

Basically, a node is the place where decisions can be made about which node to move to next.
This is basically where nodes can make decisions about which node they can go to next

You can think about this another way and say that the graph is basically one giant state machine that makes decisions.
So another way of thinking about this is it's like a giant state machine that you're building, where the graph is basically the state machine that decides

A table showing our current mental model of cognitive architectures.

Which state do you move to in order to run a specific chain or a specific tool, and then how do you come back? And how do you know when to complete the graph, end it, or end the sequence?
What state will you go to run a particular chain or to run a particular tool, et cetera? and then, how do you get back? And then also things like, how do you know when to complete or end the graph or end the sequence, in here? 

So LangGraph was built on these ideas: making it easier to build custom agents with 'LangChain' and to build things beyond simple chains.
So LangGraph is built on these ideas of trying to make it easier for you to build, custom agents and to build, things that are more than just simple chains with 'LangChain'. 

 

Key Idea

So there are a few key parts here. So there are a number of key parts to this.

StateGraph

There is the idea of StateGraph. It is where state is persisted in some way across the entire lifecycle of an agent.
You've got this idea of a StateGraph. So this is where your state is being persisted in some way throughout the agent's life cycle.

StateGraph is a class that represents the graph.
StateGraph is a class that represents the graph. 

You initialize this class by passing in a state definition. That state definition represents a central state object that is updated over time.
You initialize this class by passing in a state definition. This state definition represents a central state object that is updated over time. 

This state is updated by nodes in the graph, and those nodes return operations on the attributes of this state in the form of a key-value store.
This state is updated by nodes in the graph, which return operations to attributes of this state (in the form of a key-value store).

- The attributes of this state can be updated in two ways. 

First, an attribute can be completely overridden.
This method is useful when you want a node to return a new value for an attribute.
First, an attribute could be overridden completely. 
This is useful if you want to nodes to return the new value of an attribute. 

Second, an attribute can be updated by adding to its value.
This is useful when the attribute is a list of actions taken, or something similar, and you want a node to return newly taken actions and have them automatically appended to that attribute.
Second, an attribute could be updated by adding to its value. 
This is useful if an attribute is a list of actions taken (or something similar) and you want nodes to return new actions taken (and have those automatically added to the attribute).

- Define the agent state

The main graph type in LangGraph is StatefulGraph. This graph is parameterized by the state object that it passes around to each node. Each node then returns operations to update that state.
The main type of graph in LangGraph is the StatefulGraph. This graph is parameterized by a state object that it passes around to each node. Each node then returns operations to update that state. 

Those operations can either set specific attributes on the state, for example by overwriting existing values, or add to existing attributes. Whether an attribute should be set or added is indicated by annotations on the state object used to construct the graph.
These operations can either SET specific attributes on the state (e.g. overwrite the existing values) or ADD to the existing attribute. Whether to set or add is denoted by annotating the state object you construct the graph with.

Nodes

The next essential piece here is the overall concept of nodes. When building a graph, you add nodes to that graph.
The next part, which is key to this, is the whole idea of nodes. As you build the graph, you want to add nodes to the graph.

 

 

 

 

 

 

 

*Reference video 1. Agentic RAG with LangChain

Overview
This video takes a close look at the concept of Agentic RAG, a reasoning-action loop, by discussing in detail patterns of reasoning and action inside language models. The speaker explains the details of Agentic RAG while emphasizing how it can be applied to build complex AI systems that can reason and act effectively across a variety of contexts.

Section 1.
Agents are a pattern, not a specific thing. This is important for understanding how to build complex AI systems. The speaker explains how Agentic RAG includes dense vector retrieval, the use of in-context learning, and augmentation. Through this, agents can be used inside a RAG system to retrieve context, augment prompts, and generate responses.

Section 2
This video also covers function calling, where an agent connects a large language model (LLM) to external tools so that the LLM can choose which tool to use to answer a query. For example, an agent can decide whether to use private data for search, archived documents, or DuckDuckGo.

Key point
This video offers insight into the concept of Agentic RAG behavior and how it can be applied when building complex AI systems capable of effective reasoning and action in different situations.

 

*Note 

> Agent 
First, Agent = Agent + Like = Agentic is how the lecture frames it. It begins by emphasizing that 'an agent is not some special thing, but a pattern.' Here, pattern refers to the 'Reasoning-Action pattern.' 

 

> Main role of RAG
Its purpose is to prevent HALLUCINATIONS (Confident responses that are false). To do that, its main functions are broadly composed of retrieval (finding references in documents), augmentation (adding references into the prompt), and generation (improving the answer to the question), which is why RAG = Retrieval + Augmented + Generation
Ultimately, RAG = dense vector retrieval + in-context learning.

 

> LangGraph
If Product can diagram it, Engineering can create it exactly.If I’m a builder... more intuitive, more modular. If Product can diagram it Engineering can create it exactly.(INTUITIVE)
LangGraph uses a simple graph approach. LangGraph uses a simple graph approach. It creates cyclic graphs out of graphs, which are collections of connected entities, nodes, and edges. Because it is built on top of LangChain, it lets us create cyclical graphs with LangChain. That is useful because it allows us to add cycles to applications built on LangChain. LangChain originally began from the abstraction of chains, and LangGraph is what makes this possible. 

LangGraph is a way to create state machines by specifying them as graphs. LangGraph is a way to create  state machines by specifying them as graphs.
More specifically, what LangGraph does is create a kind of state machine that tracks state by defining the state of each node through the graph.

 

 

COGNITIVE ARCHITECTURES 
1. LLM call
2. Chain of LLM calls
3. LLM as Router
4. State Machines
5. Agents

https://docs.google.com/presentation/d/1rPYL_Q8WF1-jqN0iLkwcW0UijEJbAYhoRzYhWBb3gWo/edit#slide=id.g2d249469c2a_0_64 

https://blog.langchain.dev/openais-bet-on-a-cognitive-architecture/

 

OpenAI's Bet on a Cognitive Architecture

Three weeks ago OpenAI held a highly anticipated developer day. They released a myriad of new features. The two most interesting to me were the Assistants API and GPTs. To me, these represent the same bet – on a particular, agent-like, closed cognitive architecture.

blog.langchain.dev

 

 

LangGraph

Nodes 
Function (e.g., an external tool) 
LCEL Runnable executable (e.g., a RAG chain) 

Edges 
“paths to take,” the routes to move along 
“where to pass our state object next,” the place to hand the state object off to next
*the agent scratch Pad
: what that is really tracking is the state

 

 

LangChain v0.1.0

Enabling LLM applications that leverage context and reasoning. Enabling LLM applications that leverage context and reasoning.

RAG

 

1. MODELS I/O : “Chat-Style” ::  Fine-tuned for chat Often instruction-tuned

2. PROMPTS

3. CREATE A VECTOR STORE
1) Load Docs
2) Split Text
3) Embed
4) Store Vectors

overview- 1

 

 

METARAG FLOW
1. Search ArXiv for top papers on RAG 
2. Papers --> embeddings -> Vector Store (FAISS)
3. Query RAG app about RAG!
4. Return answers to questions with sources

 

DATA

You can use LangChain's archive loader to fetch documents from the archive based on your question and build out this vector store. we can use LangChain's archive loader to get papers from archive based on our question and build out this Vector store.

 

 

MODELS
Embedding Model : text-3-embedding-small 
Chat Model (e.g., LLM) : GPT-3.5-Turbo

 

overview- 2. ClassicMetaRAG 

code

 

 

overview- 3. RAG/Function Calling Build + Final Assembly

 

A graph only allows flow in one direction. Here you can see it flowing to the next item, then the next, and then the next. LangGraph gives you the flexibility to define nodes, units, or states that act on state and edges, or units that tell you where the state should go next. Because you can control these components concretely, the core idea of LangGraph is to shepherd state and perform work around it. 

code 

 

 

 

CONCLUSION

Agents, RAG, Agentic RAG
These are all patterns, not things
They are all simply patterns, not objects in themselves.
Agent = Reasoning-Action pattern!

Classic (Meta)RAG via LCEL
Classic (Meta)RAG through LCEL
A single node in LangGraph
A single node in LangGraph

LangGraph 
Shepherding state around, doing stuff
Doing things while shepherding state around it

 

 

 

 

https://colab.research.google.com/drive/1cUj-jWDDpyHjDKqfIRAijXUWLSnxuy9W#scrollTo=R83jwrx8xKVf

 

Google Colab Notebook

Run, share, and edit Python notebooks

colab.research.google.com

 

 

https://www.youtube.com/watch?v=pBBe1pk8hf4

https://www.ted.com/talks/harrison_chase_the_magical_ai_assistants_of_the_future_and_the_engineering_behind_them

 

The magical AI assistants of the future — and the engineering behind them

What is it going to take to build the AI assistants of the future? Tech entrepreneur Harrison Chase details why large language models like ChatGPT are only one piece of the puzzle for creating tech capable of reasoning and understanding context, sharing fo

www.ted.com

https://medium.com/@szabokb/from-chat-bots-to-killer-bots-e71a20be2e2a

 

From Chat-bots to Killer-bots?

How memory, reasoning, and action-based learning transform AI agents from language processors to practical collaborators.

medium.com

https://www.agentx.so/post/what-is-ai-agent-2

 

AgentX - What is AI Agent ??

What is AI Agent ??

www.agentx.so

 

 

This English version was translated by Codex.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min