Skip to main content
In this section, we will build a sequential graph where data flows through multiple nodes, and each node updates a specific part of the shared state.

Objectives

  1. Create multiple nodes that sequentially process and update different parts of the state.
  2. Connect nodes together using normal edges.
  3. Invoke the graph and see how the state is transformed step-by-step.

Graph III: Sequential Graph

Goal

Build a sequential graph where data flows through multiple nodes, and each node updates a specific part of the shared state.

Sample Input

Sample Output

Plan

  1. Define the state schema (AgentState) with name, age, and final variables.
  2. Define two node functions: first_node (to set greeting) and second_node (to append age description).
  3. Build, connect sequentially using normal edges, and compile the graph.
  4. Invoke the graph and view the final result.

Code Implementation

1. Define the State Schema

We define the state structure. Notice that final will be used as a combined output accumulator:

2. Define the Nodes

We define two nodes. The first node sets the greeting using the name, and the second node appends the age explanation:

3. Create and Compile the Graph

We add both nodes, connect them using add_edge, and compile the graph:

4. Invoke the Graph

Pass the name and age to retrieve the final compiled string:

Exercise: Three-Node Sequential Agent 💪

Goal

Connect three nodes sequentially to customize a greeting, display the user’s age, and format a list of their skills.

Sample Input

Sample Output

Plan

  1. Define an AgentState containing name (str), age (int), skills (list of strings), and result (str) fields.
  2. Create greeting_node (to greet), age_node (to append age description), and skills_node (to join skills with commas and ‘and’, appending them to the result).
  3. Build the graph, register all three nodes, connect them in order (greeting -> age -> skills), set entry/finish points, compile and run.

Practice & Exercises

To reinforce what you’ve learned in this section (sequential node execution and data transformation), practice with the interactive notebook:

Practice & Exercises

Practice defining multiple sequential nodes, linking them with edges, and building a sequential agent.💻 VS Code | 🚀 Colab | 📥 Download