langgraph-fundamentals
langchain-ai/langchain-skills
Master LangGraph's directed graph workflows for building stateful, multi-step agent applications.
What is langgraph-fundamentals?
LangGraph models agent workflows as directed graphs with nodes, edges, and shared state. Use it when you need fine-grained control over orchestration, complex branching/loops, or human-in-the-loop capabilities—otherwise prefer simpler LangChain alternatives.
- Design and build stateful graphs with StateGraph, nodes, and edges
- Route execution dynamically using conditional edges and Command for combined state updates + routing
- Fan-out to parallel workers with Send API and reducers for accumulated state
- Stream graph execution in multiple modes (values, updates, messages, custom) for real-time feedback
- Handle transient errors with RetryPolicy, LLM-recoverable errors via ToolNode, and user-fixable errors via interrupts
How to install langgraph-fundamentals
npx skills add https://github.com/langchain-ai/langchain-skills --skill langgraph-fundamentals- LangGraph library installed (Python or TypeScript)
- Basic understanding of LangChain concepts (optional but helpful)
- Familiarity with your project's language (Python or TypeScript) to read applicable implementation reference
How to use langgraph-fundamentals
- 1.Map out your workflow as discrete steps and sketch a flowchart
- 2.Identify each step's type (LLM, data, action, user input) and determine its inputs, context, and outputs
- 3.Design your state schema to hold shared memory across all nodes
- 4.Implement each node as a function that takes state and returns partial updates
- 5.Wire nodes together with edges (static add_edge, conditional add_conditional_edges, or Command for combined updates + routing)
- 6.Compile the graph with a checkpointer if persistence is needed
- 7.Call graph.invoke(input, config) for single execution or graph.stream(input, config, mode=...) for real-time feedback
Use cases
- Multi-step agent workflows with branching logic and loops (e.g., research agent with search → analyze → decide loop)
- Human-in-the-loop systems that pause for user input and resume with new data
- Parallel task execution where one node spawns multiple workers and aggregates results
- Complex state management where different nodes append to lists, overwrite counters, or apply custom merge logic
- Real-time streaming of agent progress to chat UIs or monitoring dashboards
- AI engineers building production agent systems
- Developers needing fine-grained control over LLM orchestration
- Teams implementing human-in-the-loop or approval workflows
- Anyone moving beyond simple LangChain chains to complex, stateful applications
langgraph-fundamentals FAQ
Use LangGraph for fine-grained control, complex branching/loops, or human-in-the-loop workflows. Use LangChain agents for quick prototyping. Use LangChain direct for simple stateless workflows.
Use reducers (operator.add for lists, custom functions for complex logic) on fields that accumulate. Fields without reducers use last-write-wins semantics.
Conditional edges route based on state; Command combines state updates and routing in a single return value. Warning: static edges still execute even if Command routes elsewhere.
Return [Send('worker_node', {...})] from a conditional edge to spawn parallel workers. Requires a reducer on the results field to aggregate outputs.
Use 'values' to monitor complete state, 'updates' for incremental changes, 'messages' for chat UIs with LLM tokens, or 'custom' for progress indicators.
Full instructions (SKILL.md)
Source of truth, from langchain-ai/langchain-skills.
name: langgraph-fundamentals description: "INVOKE THIS SKILL when writing ANY LangGraph code. Covers StateGraph, state schemas, nodes, edges, Command, Send, invoke, streaming, and error handling."
<overview> LangGraph models agent workflows as **directed graphs**:- StateGraph: Main class for building stateful graphs
- Nodes: Functions that perform work and update state
- Edges: Define execution order (static or conditional)
- START/END: Special nodes marking entry and exit points
- State with Reducers: Control how state updates are merged
Graphs must be compile()d before execution.
</overview>
Designing a LangGraph application
Follow these 5 steps when building a new graph:
- Map out discrete steps — sketch a flowchart of your workflow. Each step becomes a node.
- Identify what each step does — categorize nodes: LLM step, data step, action step, or user input step. For each, determine static context (prompt), dynamic context (from state), retry strategy, and desired outcome.
- Design your state — state is shared memory for all nodes. Store raw data, format prompts on-demand inside nodes.
- Build your nodes — implement each step as a function that takes state and returns partial updates.
- Wire it together — connect nodes with edges, add conditional routing, compile with a checkpointer if needed.
| Use LangGraph When | Use Alternatives When |
|---|---|
| Need fine-grained control over agent orchestration | Quick prototyping → LangChain agents |
| Building complex workflows with branching/loops | Simple stateless workflows → LangChain direct |
| Require human-in-the-loop, persistence | Batteries-included features → Deep Agents |
State Management
<state-update-strategies>| Need | Solution | Example |
|---|---|---|
| Overwrite value | No reducer (default) | Simple fields like counters |
| Append to list | Reducer (operator.add / concat) | Message history, logs |
| Custom logic | Custom reducer function | Complex merging |
Nodes
<node-function-signatures>Node functions return partial state updates. Signatures for configuration and runtime access differ by language; use the applicable implementation reference.
</node-function-signatures>Edges
<edge-type-selection>| Need | Edge Type | When to Use |
|---|---|---|
| Always go to same node | add_edge() | Fixed, deterministic flow |
| Route based on state | add_conditional_edges() | Dynamic branching |
| Update state AND route | Command | Combine logic in single node |
| Fan-out to multiple nodes | Send | Parallel processing with dynamic inputs |
Command
Command combines state updates and routing in a single return value. Fields:
update: State updates to apply (like returning a dict from a node)goto: Node name(s) to navigate to nextresume: Value to resume afterinterrupt()— see human-in-the-loop skill
Python: Use Command[Literal["node_a", "node_b"]] as the return type annotation to declare valid goto destinations.
TypeScript: Pass { ends: ["node_a", "node_b"] } as the third argument to addNode to declare valid goto destinations.
Warning: Command only adds dynamic edges — static edges defined with add_edge / addEdge still execute. If node_a returns Command(goto="node_c") and you also have graph.add_edge("node_a", "node_b"), both node_b and node_c will run.
Send API
Fan-out with Send: return [Send("worker", {...})] from a conditional edge to spawn parallel workers. Requires a reducer on the results field.
Running Graphs: Invoke and Stream
<invoke-basics>Call graph.invoke(input, config) to run a graph to completion and return the final state.
| Mode | What it Streams | Use Case |
|---|---|---|
values | Full state after each step | Monitor complete state |
updates | State deltas | Track incremental updates |
messages | LLM tokens + metadata | Chat UIs |
custom | User-defined data | Progress indicators |
Error Handling
Match the error type to the right handler:
<error-handling-table>| Error Type | Who Fixes | Strategy | Example |
|---|---|---|---|
| Transient (network, rate limits) | System | RetryPolicy(max_attempts=3) | add_node(..., retry_policy=...) |
| LLM-recoverable (tool failures) | LLM | ToolNode(tools, handle_tool_errors=True) | Error returned as ToolMessage |
| User-fixable (missing info) | Human | interrupt({"message": ...}) | Collect missing data (see HITL skill) |
| Unexpected | Developer | Let bubble up | raise |
Core boundaries
- Return partial state updates from nodes instead of mutating state directly.
- Route loops through a named node;
STARTis entry-only. - Define reducers for accumulated list fields; otherwise, the last write wins.
- Account for static edges when using
Commandwithgoto, because both routes execute.
Implementation references
If writing, modifying, or debugging LangGraph code, determine the project's language from its existing files, then read the applicable reference before implementing:
- For Python, read references/python.md.
- For TypeScript, read references/typescript.md.
Read both only when the task covers both languages. For conceptual questions that require no code, do not load either reference.
Related skills
More from langchain-ai/langchain-skills and the wider catalog.

langgraph-human-in-the-loop
Pause LangGraph execution for human approval, validation, or input—then resume with their decision.

langgraph-persistence
Persist LangGraph state with checkpointers, thread IDs, and time travel for durable multi-turn conversations.

langgraph-python-quickstart
Scaffold a minimal LangGraph agent in Python following the official quickstart.

langgraph-typescript-quickstart
Scaffold a minimal LangGraph agent in TypeScript from the official quickstart.

langsmith-online-eval-engineering
Iteratively build and test LangSmith online evaluators by inspecting traces and interviewing users.

managed-deep-agents
Build, test, and deploy Managed Deep Agents in LangSmith with the mda CLI.