AIOps Peach

Agents · Module 01

LangGraph Foundations & State Management

From linear chains to stateful graphs: LangGraph state, nodes and edges, reducers for messages, checkpointers, and a first graph with conditional routing.

Học tương tác →

Học xong bạn làm được

Bài học

  1. What is LangGraph?

    LangGraph is an orchestration framework for LLMs, built on LangChain by the LangChain team, that runs workflows as a graph over a typed state whose core is a messages list. It handles what linear chains cannot - complex and cyclic flows, human-in-the-loop, stateful conversations and multi-agent systems - and every workflow starts from a StateGraph.

  2. State: the messages-centric pattern

    LangGraph state is a TypedDict in which the messages field carries all input and output between nodes, merged by the add_messages reducer, and every other field is context - configuration, metadata, tracking and non-conversational data. Messages are typed as SystemMessage, HumanMessage, AIMessage and ToolMessage.

  3. Nodes, edges and state design

    A node is a function that reads messages from the state, processes them with an LLM or a tool, and returns new messages. Normal edges always lead to the same node; conditional edges route on the last message and context counters. Good state design keeps all conversational I/O in messages, injects context in the initial state, and tags each agent's messages with a name.

  4. Checkpointer: state persistence and memory

    A checkpointer persists and restores graph state between executions, so a graph can remember conversations, resume after failures, replay earlier steps and expose intermediate states. Without one every invocation is stateless. It works best with messages-first design. InMemorySaver, the built-in one, keeps state in memory and loses it on restart.

  5. Building the first graph

    A complete chat agent in eight steps - define the state, initialise the LLM, write the node, create the StateGraph, add the node, connect START and END, compile with an InMemorySaver, and run two turns in one thread. The second call sends only the new question, and the result holds the whole conversation.

  6. Conditional routing with messages

    The tool-calling pattern binds a tool to the LLM, lets an agent node decide whether to call it, runs each requested call in a tool node that answers with ToolMessages, and routes on the last message - tool_calls go to the tools node, which loops back to the agent, and anything else ends the run. The practice is to re-implement this agent.

  7. Best practices, common patterns and debugging

    Five best practices - messages for all I/O, separate concerns in the state, typed and tagged message roles, managed message history, and context injection through a factory - plus two common patterns (agent with tools, multi-agent collaboration), the human-in-the-loop guide, and two debugging aids - a node that prints the history and drawing the graph.

  8. LangGraph in 2026: what's new

    LangGraph reached a stable v1.0 in late 2025 and is widely used in production. Production needs a durable checkpointer - AsyncPostgresSaver for most setups, Redis for very low latency - with encryption and TTL. The Store interface shares memory across threads, and LangGraph Platform, renamed LangSmith Deployment, deploys agents in cloud, hybrid or self-hosted mode.

  9. Assignment: LangGraph Foundations & State Management

    LangGraph Foundations & State Management