• About Us
  • Contact Us
  • Terms & Conditions
  • Privacy Policy
Technology Hive
  • Home
  • Technology
  • Artificial Intelligence (AI)
  • Cyber Security
  • Machine Learning
  • More
    • Deep Learning
    • AI in Healthcare
    • AI Regulations & Policies
    • Business
    • Cloud Computing
    • Ethics & Society
No Result
View All Result
  • Home
  • Technology
  • Artificial Intelligence (AI)
  • Cyber Security
  • Machine Learning
  • More
    • Deep Learning
    • AI in Healthcare
    • AI Regulations & Policies
    • Business
    • Cloud Computing
    • Ethics & Society
No Result
View All Result
Technology Hive
No Result
View All Result
Home Technology

Sequential Graph for Beginners and Advanced Learners

Linda Torries – Tech Writer & Digital Trends Analyst by Linda Torries – Tech Writer & Digital Trends Analyst
October 1, 2025
in Technology
0
Sequential Graph for Beginners and Advanced Learners
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter

Introduction to Sequential Graphs

Okay, welcome to your third graph. What are we going to do this time? Well, enough processing multiple values and everything. Let’s actually get the graph more complicated. That’s why we’re going to be building a sequential graph. All it all that basically means is we’re going to be creating and handling multiple nodes that can sequentially process and update different parts of the state.

Step 1: Imports and Type Dictionary

Cool. So now we’re about to code up the third graph. And we’re making quite fast progress. Well done on that. Again, the imports are the same. State graph and type dictionary. Perfect.

from typing_extensions import TypedDict 
from langgraph.graph import StateGraph

Step 2: Agent State (Typed Dictionary)

And like we’ve done in the previous two graphs, we’re going to be coding the the state schema or the agent state first. Let’s have class agent state. And again, it needs to be in the form of a typed dictionary, right? And in this case, let’s have the three attributes as all strings because we’ve already we already know how to handle multiple data types, right? Let’s keep it simple. Name string, age string, and final string.

class AgentState(TypedDict):
    name: str
    age: str
    final: str

Step 3: Node Functions (Actions)

Okay. Now, here’s what we’re going to build. Now, we’re about to build our two node functions, which are again the actions. Okay. Again you simply write first well I’ll name it first node in this case and like I mentioned before we pass in the state and we return the updated state. This is the first node of our sequence. Okay. And what do we want to do in this specific node? Well, I really just want to manipulate the final part. So, let’s say something like state final is equal to state or let’s have an f string f state name. Let’s say something like hi that. And we’ll just return the state. Perfect.

def first_node(state: AgentState) -> AgentState:
    """This is the first node of our sequence."""
    state["final"] = "hi " + state["name"]
    return state

And now again we create a new node and state agent state. Return that. Perfect. And I’m just going to copy this doc string and just change it. This is the second nerf. Perfect. Okay. To speed things up. And in this case I also want to have state final is equal to you are state age years old. Again quite a simple example easy to follow. That’s why I’ve kept it as quite a basic graph.

def second_node(state: AgentState) -> AgentState:
    """This is the second node."""
    state["final"] = "you are " + state["age"] + " years old"
    return state

There is one logical error which I’ve put deliberately here. I want you to try to identify it.

Step 4: Fixing the Logical Error

Okay. So the logical error in this case is the that once we’ve built our graph and everything what would have happened is we would have said hi to whoever we pass in let’s say Charlie or something. So, hi Charlie. And we store that in the final attribute in the state, which is what we want. But here’s where things get like start to be well logically incorrect.

def second_node(state: AgentState) -> AgentState:
    """This is the second node."""
    state["final"] = state["final"] + ", you are " + state["age"] + " years old"
    return state

Step 5: Building the Sequential Graph and Adding Edges

Okay. Now let’s get to the fun part. How do we actually build this graph? And really it’s quite similar to the previous two graphs except there is one new thing which you’re about to learn. Like always we use state graph to start the framework. Agent state and let’s store it in graph. Again I could have had this name the width variable into anything. I’ve just kept it graph because it makes intuitive sense.

graph = StateGraph(AgentState)
graph.add_node("first_node", first_node)
graph.add_node("second_node", second_node)
graph.set_entry_point("first_node")
graph.add_edge("first_node", "second_node") 
graph.set_finish_point("second_node")
app = graph.compile()

Step 6: Invoking the Sequential Graph

So now that we’ve built that, let’s again invoke this. I’ve got this code ready here. Let’s invoke it. Let’s pass the parameter as Charlie and let’s pass the age as 20. Cool. Print result.

result = app.invoke({
    "name": "Charlie",
    "age": "20",
    "final": ""
})
print(result)
print(result["final"]) 

Exercise: Building a Sequential Graph with Three Nodes

Awesome. So now we will move on to the exercise for this third graph. And what I want you to do is really build on top of what we just covered. Instead of two nodes, I want you to build three nodes. Again, in a sequence, don’t need to go too fancy yet. We will again three nodes in a sequence. And we will have you will need to accept the user’s name, their age, and a list of their skills.

Conclusion

In this article, we have learned how to build a sequential graph using the LangGraph library. We have created a graph with two nodes and added edges between them. We have also learned how to invoke the graph and print the result.

FAQs

Q: What is a sequential graph?
A: A sequential graph is a graph where nodes are connected in a sequence, and each node processes and updates the state before passing it to the next node.
Q: How do we add edges between nodes in a sequential graph?
A: We add edges between nodes using the add_edge method, specifying the start and end nodes.
Q: How do we invoke a sequential graph?
A: We invoke a sequential graph using the invoke method, passing in the input state.
Q: What is the purpose of the first_node and second_node functions?
A: The first_node and second_node functions are the actions that are performed on the state at each node. They update the state and return the updated state.

Previous Post

Amazon’s Alexa Relies on Sales of Pricier Devices for Survival

Next Post

EU struggles to keep pace with China on AI adoption due to regulatory challenges

Linda Torries – Tech Writer & Digital Trends Analyst

Linda Torries – Tech Writer & Digital Trends Analyst

Linda Torries is a skilled technology writer with a passion for exploring the latest innovations in the digital world. With years of experience in tech journalism, she has written insightful articles on topics such as artificial intelligence, cybersecurity, software development, and consumer electronics. Her writing style is clear, engaging, and informative, making complex tech concepts accessible to a wide audience. Linda stays ahead of industry trends, providing readers with up-to-date analysis and expert opinions on emerging technologies. When she's not writing, she enjoys testing new gadgets, reviewing apps, and sharing practical tech tips to help users navigate the fast-paced digital landscape.

Related Posts

Quantifying LLMs’ Sycophancy Problem
Technology

Quantifying LLMs’ Sycophancy Problem

by Linda Torries – Tech Writer & Digital Trends Analyst
October 24, 2025
Microsoft’s Mico Exacerbates Risks of Parasocial LLM Relationships
Technology

Microsoft’s Mico Exacerbates Risks of Parasocial LLM Relationships

by Linda Torries – Tech Writer & Digital Trends Analyst
October 24, 2025
Lightricks Releases Open-Source AI Video Tool with 4K and Enhanced Rendering
Technology

Lightricks Releases Open-Source AI Video Tool with 4K and Enhanced Rendering

by Linda Torries – Tech Writer & Digital Trends Analyst
October 24, 2025
OpenAI Unlocks Enterprise Knowledge with ChatGPT Integration
Technology

OpenAI Unlocks Enterprise Knowledge with ChatGPT Integration

by Linda Torries – Tech Writer & Digital Trends Analyst
October 24, 2025
Training on “junk data” can lead to LLM “brain rot”
Technology

Training on “junk data” can lead to LLM “brain rot”

by Linda Torries – Tech Writer & Digital Trends Analyst
October 24, 2025
Next Post
EU struggles to keep pace with China on AI adoption due to regulatory challenges

EU struggles to keep pace with China on AI adoption due to regulatory challenges

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest Articles

We Need to Protect the Protocol That Runs BlueSky

We Need to Protect the Protocol That Runs BlueSky

March 5, 2025
Understanding Generative, Agentic, and Agent AI

Understanding Generative, Agentic, and Agent AI

May 11, 2025
Cutting Through AI Noise

Cutting Through AI Noise

September 20, 2025

Browse by Category

  • AI in Healthcare
  • AI Regulations & Policies
  • Artificial Intelligence (AI)
  • Business
  • Cloud Computing
  • Cyber Security
  • Deep Learning
  • Ethics & Society
  • Machine Learning
  • Technology
Technology Hive

Welcome to Technology Hive, your go-to source for the latest insights, trends, and innovations in technology and artificial intelligence. We are a dynamic digital magazine dedicated to exploring the ever-evolving landscape of AI, emerging technologies, and their impact on industries and everyday life.

Categories

  • AI in Healthcare
  • AI Regulations & Policies
  • Artificial Intelligence (AI)
  • Business
  • Cloud Computing
  • Cyber Security
  • Deep Learning
  • Ethics & Society
  • Machine Learning
  • Technology

Recent Posts

  • Quantifying LLMs’ Sycophancy Problem
  • Microsoft’s Mico Exacerbates Risks of Parasocial LLM Relationships
  • Lightricks Releases Open-Source AI Video Tool with 4K and Enhanced Rendering
  • OpenAI Unlocks Enterprise Knowledge with ChatGPT Integration
  • Anthropic Expands AI Infrastructure with Billion-Dollar TPU Investment

Our Newsletter

Subscribe Us To Receive Our Latest News Directly In Your Inbox!

We don’t spam! Read our privacy policy for more info.

Check your inbox or spam folder to confirm your subscription.

© Copyright 2025. All Right Reserved By Technology Hive.

No Result
View All Result
  • Home
  • Technology
  • Artificial Intelligence (AI)
  • Cyber Security
  • Machine Learning
  • AI in Healthcare
  • AI Regulations & Policies
  • Business
  • Cloud Computing
  • Ethics & Society
  • Deep Learning

© Copyright 2025. All Right Reserved By Technology Hive.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?