πŸš€
langraph
4. Sequential Graph

Sequential Graph ♾️

Objectives βœ…
  1. Create multiple Nodes that sequentially process and update different parts of the state.
  2. Connect Nodes together in a graph.
  3. Invoke the Graph and see how the state is transformed step-by-step.
from typing import TypedDict
from langgraph.graph import StateGraph
 
class AgentState(TypedDict):
    name: str
    age: str
    final: str
 
def first_node(state: AgentState) -> AgentState:
    """This is the first node of our sequence."""
    state['final'] = f'Hi, {state['name']}'
 
    return state
 
def second_node(state: AgentState) -> AgentState:
    """This is the second node of our sequence."""
    state['final'] += f'You are {state['age']} years old.'
 
    return state
graph = StateGraph(AgentState)
 
graph.add_node('first_node', first_node)
graph.add_node('second_node', second_node)
 
# START
graph.set_entry_point('first_node')
 
# EDGE
graph.add_edge('first_node', 'second_node')
 
# END
graph.set_finish_point('second_node')
 
app = graph.compile()
result = app.invoke({"name": "Alice", "age": "30"})
 
print(result['final'])

"sequential graph"

OUTPUT:
 
'Hi, AliceYou are 30 years old.'

Β© 2024 Driptanil Datta.All rights reserved

Made with Love ❀️

Last updated on Mon Oct 20 2025