LangGraph
A framework from LangChain for building stateful, multi-step AI agent workflows as directed graphs β giving developers precise control over how agents plan, act, and recover from errors.
LangGraph is a framework from the LangChain team for building AI agent workflows as directed graphs. It gives developers precise, explicit control over how an agent moves through steps, manages state, handles errors, and makes decisions β making it particularly suited for production-grade agent systems.
How LangGraph works
LangGraph models every workflow as a graph with three core components:
- Nodes: Individual steps in the workflow. A node might call an LLM, run a tool, validate data, or make a decision. Each node is a Python function that receives the current state and returns an updated state.
- Edges: The connections between nodes that define the flow. Edges can be unconditional (always go from A to B) or conditional (go to B if the result is good, go to C if it needs revision).
- State: A shared data structure that flows through the graph. Every node can read from and write to the state, building up context as the workflow progresses.
A practical example
Consider an agent that answers customer questions using your company's knowledge base:
- Classify node: Determines the type of question (product, billing, technical).
- Retrieve node: Searches the relevant knowledge base for information.
- Evaluate node: Checks whether the retrieved information is sufficient to answer the question.
- Conditional edge: If sufficient, go to the Answer node. If not, go to the Escalate node.
- Answer node: Generates a response using the retrieved information.
- Escalate node: Flags the question for human review.
In LangGraph, this entire flow is explicit in code. You can see every possible path, every decision point, and every state transition. There is no hidden logic.
Key features
- Explicit control flow: Unlike frameworks where the LLM decides what to do next, LangGraph lets you define the exact paths an agent can take. The LLM makes decisions within nodes, but the overall flow is determined by your graph.
- Persistent state: State can be saved to a database between runs, enabling long-running workflows, conversation memory, and recovery from failures.
- Human-in-the-loop: The graph can pause at any node and wait for human input before continuing. This is essential for high-stakes workflows where certain steps require approval.
- Streaming: Nodes can stream their output in real time, giving users visibility into what the agent is doing as it works.
- Subgraphs: Complex workflows can be broken into modular subgraphs that compose together, keeping the code manageable as systems grow.
LangGraph vs CrewAI
The core difference is philosophy. CrewAI provides high-level abstractions (roles, crews, tasks) that make it fast to build but harder to customise. LangGraph provides lower-level primitives (nodes, edges, state) that require more code but give complete control.
Choose CrewAI when you want a prototype quickly and the workflow fits a team-of-specialists pattern. Choose LangGraph when you need precise control over agent behaviour, complex conditional logic, robust error recovery, or when the workflow does not fit neatly into a roles-and-tasks metaphor.
Production considerations
LangGraph's explicit architecture makes it particularly suited for production deployment. Because every path through the graph is visible and testable, you can write tests for specific scenarios, add monitoring at specific nodes, and debug failures by tracing the exact path the agent took. The persistent state feature means agents can recover from crashes without losing progress.
However, LangGraph has a steeper learning curve than CrewAI. Building a LangGraph workflow requires thinking in terms of graphs, state machines, and conditional routing β concepts that may be unfamiliar to developers who have not worked with workflow orchestration before.
Why This Matters
LangGraph represents the production-grade end of the agent framework spectrum. For organisations moving AI agents from experiments to business-critical systems, LangGraph's explicit control flow, testability, and observability address the reliability concerns that prevent many agent projects from reaching production. Understanding LangGraph helps technical leaders evaluate whether their agent use cases require this level of control or whether a simpler framework will suffice.
Related Terms
Continue learning in Expert
This topic is covered in our lesson: Agentic AI Frameworks: CrewAI, LangGraph, and Beyond