Pranav Soni

Entrepreneur | Software Engineer | Learner

Introduction to LangGraph

Published on 2025-02-20
aillmlang-graphagentroutermemory

Aim 🥅

Understand basic of LangGraph

TL;DR 🩳

  1. LangGraph to orchestrate agents
  2. Router: LLM powered decision maker which decides what to do next
  3. Agent: Router which can call itself again #ReAct
  4. Tool: anything that llm uses to do something, like scraper, (can also be llm thing like image generator tool)
  5. Use thread id to store memory

What's on the plate 🍽?

  • LangGraph is an orchestration framework for #agent
  • Normally the flow of #llm project has a control flow to work
    • Chain: fixed linear control flows defined by devs
    • Graphs: LLM choice to pick their own control flow
    • Agent = control flow defined by an LLM
    • #router is a bit less than an agent (with very less control)
    • LG helps make agentic apps more reliable
      • balance reliability with control
  • Chain is linear flow of thoughts
  • Graph is non linear and involves LLM based decision making using Agents or Routers
  • Node:
    • Each node has a state
    • Node can be an LLM call or a tool call
  • Tools:
    • Non-llm based things like scraper, sql data fetching etc
    • Some tool (like hammer) which our llms (as a mason) can use
  • Router: LLM based decision maker
    • if user asks for last year's financial data get to that node
    • if user asks for HR data go there etc
    • Router does not redirect to itself, it's just aaya aur gaya to any of the out nodes, while agent can come again to itself
  • Agent: A router which can RETHINK with #ReAct or some other framework.
  • Memory: To add memory to agents we can use in memory key value stores like MemorySave from LG.
    • It uses checkpoint to store each state, and a series of checkpoints for a thread
    • thread id is sent in configs to identify historical context of chat
  • Reducers: To append next messages to the current messages state, we can use reducers like this
from typing import Annotated

from langgraph.graph.message import add_messages



class MessagesState(TypedDict):

    messages: Annotated[list[AnyMessage], add_messages]

Rest it's quite simple, just get your hands dirty