LangGraph: Stateful, Multi-Step Agent Workflows
AgentExecutor works well for a simple "call tools until done" loop, but real workflows often need more control: conditional branches, loops that revisit earlier steps, or multiple cooperating steps that each need to see and update a shared state. LangGraph (from the LangChain team) models an application as an explicit graph of steps (nodes) and transitions (edges) over a shared state object, instead of an implicit loop.
State: the shared object every node reads and updates
Every node in a LangGraph graph receives the current state and returns a dictionary of updates to merge into it, this is what makes multi-step workflows explicit and inspectable: at any point, state is a plain, printable object describing exactly where the workflow is.
Defining nodes
Each node is a plain Python function, search_node would call a real search tool and a model call would live in answer_node, kept as placeholders here since both need real API access, the graph structure around them is what this lesson is actually teaching.
Wiring the graph
add_edge('search', 'answer') is a fixed transition, always go from search to answer. add_edge('answer', END) marks answer as a terminal step, END is a special LangGraph constant meaning "the graph is finished."
Conditional edges: branching based on state
add_conditional_edges routes to a different next node depending on a function of the current state, here, looping back to search again if the results look too thin, this is the core capability AgentExecutor's simple loop doesn't give you directly: an explicit, inspectable decision about what happens next, rather than an implicit "keep calling tools until the model stops."
TIP
Think of AgentExecutor as one specific, common pattern (loop until no more tool calls), and LangGraph as the general-purpose tool for building that pattern, and any other control flow (branches, loops, multiple cooperating agents) your workflow actually needs.