{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# How to create a sequence of steps\n",
"\n",
"!!! info \"Prerequisites\"\n",
" This guide assumes familiarity with the following:\n",
"\n",
" - [How to define and update graph state](../../how-tos/state-reducers)\n",
"\n",
"This guide demonstrates how to construct a simple sequence of steps. We will demonstrate:\n",
"\n",
"1. How to build a sequential graph\n",
"2. Built-in short-hand for constructing similar graphs.\n",
"\n",
"\n",
"# Summary\n",
"\n",
"To add a sequence of nodes, we use the `.add_node` and `.add_edge` methods of our [graph](../../concepts/low_level/#stategraph):\n",
"```python\n",
"from langgraph.graph import START, StateGraph\n",
"\n",
"graph_builder = StateGraph(State)\n",
"\n",
"# Add nodes\n",
"graph_builder.add_node(step_1)\n",
"graph_builder.add_node(step_2)\n",
"graph_builder.add_node(step_3)\n",
"\n",
"# Add edges\n",
"graph_builder.add_edge(START, \"step_1\")\n",
"graph_builder.add_edge(\"step_1\", \"step_2\")\n",
"graph_builder.add_edge(\"step_2\", \"step_3\")\n",
"```\n",
"\n",
"We can also use the built-in shorthand `.add_sequence`:\n",
"```python\n",
"graph_builder = StateGraph(State).add_sequence([step_1, step_2, step_3])\n",
"graph_builder.add_edge(START, \"step_1\")\n",
"```\n",
"\n",
"\n",
"Why split application steps into a sequence with LangGraph?
\n",
"\n",
"LangGraph makes it easy to add an underlying persistence layer to your application.\n",
"This allows state to be checkpointed in between the execution of nodes, so your LangGraph nodes govern:\n",
"\n",
"\n",
"
\n",
"\n",
"They also determine how execution steps are [streamed](../../concepts/streaming/), and how your application is visualized\n",
"and debugged using [LangGraph Studio](../../concepts/langgraph_studio/).\n",
"\n",
"
Set up LangSmith for better debugging
\n", "\n", " Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM aps built with LangGraph — read more about how to get started in the docs. \n", "
\n", "