Table of Contents
LangGraph builds on LangChain and ReAct frameworks, enabling complex, stateful AI applications. It excels at maintaining context, making dynamic decisions, and handling intricate logic. LangGraph implements workflows as directed graphs, allowing for sophisticated reasoning, adaptability, and multi-agent collaboration in LLM-powered systems.
Before diving into LangGraph, let’s understand the foundational concepts that led to its development.
What is ReAct?
ReAct (Reasoning and Acting) is a framework that combines reasoning and acting in AI systems. The basic idea is that AI should:
- Reason about what it needs to do
- Plan the steps it will take
- Act on those plans
- Observe the results
- Reflect and adjust its approach
Think of it like a chef who:
- Reasons about what dish to make
- Plans the cooking steps
- Acts by following the recipe
- Observes how each step turns out
- Reflects and adjusts if something isn’t working
What is LangChain?
LangChain is a framework designed to develop applications powered by language models. Think of it as a toolkit that helps you build complex applications using large language models (LLMs) like GPT-4 or Claude. LangChain provides the building blocks to create chains of operations, where each step can involve tasks like:
- Interacting with an LLM
- Processing the output
- Making decisions based on the results
- Accessing external tools or data sources
For example, you could build a chain that takes a user question, searches a database, formats the relevant information, and generates a response using an LLM.
Enter LangGraph
LangGraph is a newer library built on top of LangChain that makes it easier to create complex, stateful applications using the ReAct framework. While LangChain is great for creating linear chains of operations, LangGraph excels at building workflows that:
- Maintain state across interactions
- Make dynamic decisions about what to do next
- Handle complex loops and conditional logic
- Manage multiple agents working together
LangGraph implements these workflows as directed graphs, where each node represents a step in the process, and the edges represent the possible paths between steps.
The key difference between LangChain’s chains and LangGraph’s workflows is that LangGraph maintains state and can make dynamic decisions about which path to take based on that state. This makes it particularly well-suited for:
- Multi-step reasoning tasks
- Interactive agents that need to remember context
- Complex decision-making processes
- Workflows that might need to loop or backtrack
In essence, LangGraph brings the power of state machines and graph-based workflows to LLM applications, making it easier to build more sophisticated AI systems that can reason, act, and adapt based on their interactions.
Visualize LangGraph And Explain
Here is the default LangGraph structure. Let’s break down this workflow graph step by step:

1. Starting Point
- The process begins at `__start__`, which represents the initial entry point
- This is where a user query or task is first received by the system
2. Model Interaction (`call_model`)
- The first major step is `call_model`, where the agent engages with the language model
- Here, the model performs three crucial functions:
- Analyzes the current situation
- Reasons about potential actions
- Makes decisions about whether to use tools or provide a final answer
3. Decision Points
- From `call_model`, there are two possible paths (shown as dotted lines):
- Path to `__end__`: Chosen when the model has sufficient information
- Path to `tools`: Selected when external tools are needed
4. Tool Execution (`tools`)
- When tools are needed, the system can perform various operations:
- Conduct web searches
- Query databases
- Perform calculations
- Make API calls
- After tool execution, results flow back to `call_model` (shown as a solid curved arrow)
5. Feedback Loop
- The solid curved arrow from `tools` to `call_model` represents a crucial feedback mechanism
- This creates an iterative cycle where the agent:
- Processes tool results
- Re-evaluates the situation
- Decides on next steps
6. Completion (`__end__`)
- The process concludes at `__end__` when the agent has gathered enough information
- This represents the final answer or solution to the original query
This workflow embodies the ReAct (Reasoning and Acting) pattern:
- Think: The `call_model` step represents reasoning
- Act: The `tools` step represents taking action
- Observe: The feedback loop represents observing results
The graph’s design uses dotted lines for conditional flows and solid lines for guaranteed transitions, creating a flexible yet structured problem-solving system that can handle complex tasks through iterative reasoning and action.
A Simple Example of LangGraph And ReAct Framework
from langchain_core.tools import tool
from langchain_google_vertexai import ChatVertexAI
from langgraph.prebuilt import create_react_agent
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
@tool
def add_two(input: int) -> int:
"""Adds two to an input."""
return input + 2
@tool
def power_two(input: int) -> int:
"""Powers two to an input."""
return input ** 2
tools = [add_two, power_two]
# You can change the model as you want
model = ChatVertexAI(model='gemini-1.5-flash-001')
langgraph_agent_executor = create_react_agent(model, tools)
prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful assistant"),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
]
)
agent = create_tool_calling_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
query = "what is the value of adding two to 3?"
agent_executor.invoke({"input": query})
# {'input': 'what is the value of adding two to 3?',
# 'output': 'The value is 5. \n'}
query = "what is the value of power two to 3?"
agent_executor.invoke({"input": query})
# {'input': 'what is the value of power two to 3?',
# 'output': 'The value is 9. \n'}
query = "what is the value of adding 5 to 3?"
agent_executor.invoke({"input": query})
# {'input': 'what is the value of adding 5 to 3?',
# 'output': 'The value is 7. \n'}
# The add_two tool cannot handle this input, so it returns 7
query = "what is the value of power two to 5, then adding 2 to it?"
agent_executor.invoke({"input": query})
# {'input': 'what is the value of power two to 5, then adding 2 to it?',
# 'output': 'The value is 27. \n'}
LangGraph Official Templates
If you want to build an application with LangGraph or ReAct framework, I strongly recommend starting with the LangChain official templates. LangChain provides five templates:
- New LangGraph Project
- ReAct Agent
- Memory Agent
- Retrieval Agent
- Data-Enrichment Agent
You can start the first tough step with them and customize it to your needs.






Moving from linear chains to graph-based state machines in LangGraph is a huge step forward for building resilient LLM applications. The code example perfectly illustrates how the feedback loop between call_model and tools allows agents to dynamically retry or adjust execution when a tool returns unexpected output—something that was notoriously cumbersome to handle cleanly with standard LangChain AgentExecutors.