Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: pub@towardsai.net
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab VeloxTrend Ultrarix Capital Partners Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Our 15 AI experts built the most comprehensive, practical, 90+ lesson courses to master AI Engineering - we have pathways for any experience at Towards AI Academy. Cohorts still open - use COHORT10 for 10% off.

Publication

LangGraph Beginner to Advance: Part 2: Hello World Graph in LangGraph
Latest   Machine Learning

LangGraph Beginner to Advance: Part 2: Hello World Graph in LangGraph

Last Updated on September 29, 2025 by Editorial Team

Author(s): Talib

Originally published on Towards AI.

Awesome. So, now this is quite exciting. We’re actually about to start coding in LangGraph for the very first time. Now that we’ve covered all the theory, admittedly the boring section, we’re now actually going to code up some graphs. And we’re about to code up our very first graph in this sub section.

LangGraph Beginner to Advance: Part 2: Hello World Graph in LangGraph

But for this overall section, I have a slight confession to make, which is we’re not going to be building any AI agents in this section. Why? because I thought that one we haven’t really even seen uh how to actually code in Langraph and combining all of these LLMs APIs and tools and all of that stuff which comes with it combining them together would be quite messy and it could be quite confusing at times especially the fact that we have never coded in Langraph before again like I said at the beginning of the course this course is supposed to be beginner friendly detailed and comprehensive and we’re going to go in steps like little by little so hopefully understand but don’t worry we will be coding AI agents soon we’re just going to be building a couple of graphs right now uh understand lang graph better the syntax better and how to actually code up graphs and get confident with it and then we will actually build AI agents.

What We Will Build

Okay cool so what is the graph which we’re going to be building together in this section I call it the uh hello world graph mainly because it’s the most basic form of graph we can actually code in lang graph so the objectives are these.

So we’re going to be understanding and defining the agent state structure and don’t worry you’ll understand what that is in a few minutes and we’re going to be creating simple node functions nodes like we discussed in the previous section uh and we’re going to be processing them and updating the state. We’re going to be building the first ever basic langraph structure and we will understand how to compile it, invoke it, process it, everything. And really the main goal of this section is to really understand how data flows through a single node in langraph.

Now just to give you a bit of a heads up as to what we’ll actually be covering uh what we’re going to be building I should say is this graph. Again like I said this is the most basic form of graph you can build in langraph. It has a start point and an end point and this node sandwiched in between them.

Step 1: Imports

from typing import TypedDict
from langgraph.graph import StateGraph

Here we import two essential components:

  • TypedDict allows us to define structured dictionaries with explicit data types.
  • StateGraph is the LangGraph framework class that we use to design, connect, and run our workflow of nodes.

Step 2: Create the Agent State

class AgentState(TypedDict):
message: str

The agent state is like the memory of your graph. It stores and carries data as it flows through the nodes. In this case, the state has a single field message, which will hold a string.

Step 3: Define a Node

def greeting_node(state: AgentState) -> AgentState:
"""
Simple node that adds a greeting message to the state.
"
""
state["message"] = "Hey " + state["message"] + ", how is your day going?"
return state

A node is just a function. It takes the state as input, modifies it, and returns the updated state. Here, the node adds a friendly greeting to the message. Notice the use of a docstring – in LangGraph, this is important for documenting node behaviour.

Step 4: Build the Graph

graph = StateGraph(AgentState)
graph.add_node("greeter", greeting_node)
graph.set_entry_point("greeter")
graph.set_finish_point("greeter")
  • We initialise the graph with the schema AgentState.
  • Add the greeter node to the graph.
  • Define the entry point (where the graph starts) and finish point (where it ends) and link them both to the greeternode.

Step 5: Compile the Graph

app = graph.compile()

Compilation transforms the design into an executable graph. It checks structure but does not guarantee logic correctness.

Step 6: Visualise the Graph

from IPython.display import Image, display
display(graph.get_graph().draw_mermaid_png())

This renders a visual diagram of the graph so you can confirm the structure looks as intended.

Output rendering of the graph visualisation.

Step 7: Run the Graph

result = app.invoke({"message": "Bob"})
print(result["message"])

Output:

Hey Bob, how's your day going?

We run the graph by invoking it with an initial state. The message “Bob” is processed by the greeter node, which outputs the final result with the greeting.

Exercise

So time for your very first exercise. The exercise for this graph is quite similar to what we just did, but I want you to create a personalized compliment agent.

You should pass in your name as like something like Bob or something and then output something like:

Bob, you're doing an amazing job learning LangGraph.

The exercise reinforces your understanding of nodes and state updates. Focus on concatenating new content to the existing state instead of replacing it.

You have now built your first Hello World Graph in LangGraph. You learned how to:

  • Import and set up the environment.
  • Define an agent state.
  • Create and document a node.
  • Build, compile, and run a graph.

This was a foundational step. In the next part, we will extend this learning to handle multiple inputs and outputs, preparing the ground for building more advanced and useful applications.

Catch the whole LangGraph Series here: LangGraph Reading List

Code is available here: LangGraph Github

Thank you for reading!

Let’s connect on LinkedIn!

LangGraph Beginner to Advance: Part 3: Multi-Entries Inputs for State in LangGraph

So now we’re about to build our second graph as you can see here. And it’s again quite similar to the first graph we…

pub.towardsai.net

Subscribe to my FREE AI NEWSLETTER | Mohammed Talib | Substack

I like to break down complex topics in simple words

substack.com

You might be interested in Reading!

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI


Take our 90+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Towards AI has published Building LLMs for Production—our 470+ page guide to mastering LLMs with practical projects and expert insights!


Discover Your Dream AI Career at Towards AI Jobs

Towards AI has built a jobs board tailored specifically to Machine Learning and Data Science Jobs and Skills. Our software searches for live AI jobs each hour, labels and categorises them and makes them easily searchable. Explore over 40,000 live jobs today with Towards AI Jobs!

Note: Content contains the views of the contributing authors and not Towards AI.