LangGraph #1 | Overview


Introduction

  • Overview
    • StateGraph - Components
      • State : is the shared memory or context that persists and updates as the graph runs
      • Node : are the units of work (like agents, tools, or logic steps).
      • Edge : define how data or control flows between nodes
    • Functional Mechanism
      • Reducer : helps control how the state is updated when multiple nodes modify it (default: overwrite)
      • Command : a special return value that a node can produce to tell the graph how to continue execution
      • Subgraph : lets you group logic into reusable workflows (can act like nodes themselves)
      • Checkpoint : Mechanism for saving and restoring state during long-running or interruptible workflows
      • Streaming : Langgraph supports real-time streaming of intermediate outputs from LLMs
      • Concurrency(Async, Parallel) : Some graphs can run multiple nodes in parallel if their dependencies don’t overlap

State

  • State : is the shared memory or context that persists and updates as the graph runs
  • Implementation: TypedDict or Pydantic BaseModel
from typing import Any, TypedDict

class State(TypedDict):
    messages : dict[str]

Node

  • Node : are the units of work (like agents, tools, or logic steps).
  • Implementation : python function
def add_message(state: State) → dict[str, Any]
    # return the fields to update
    return {"messages": "Message Added"}

Edge

  • Edge : define how data or control flows between nodes
  • Types
    • Start Edge
    • Normal Edge
    • Conditional Edge
    • End edge
# Define Graph by connecting edges
graph = StateGraph(state)
# Start Edge
graph.add_edge(START, first_node)
# Conditional Edge
graph.add_conditional_edges(
    "decision_node",
    routing_funtion,
    {"option_a": "node_a", "option_b", "node_b"}
)
# Normal Edge
graph.add_edge("node_a", "node_b")
# End Edg
graph.add_edge("node_b", END)

References