DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Beyond n8n for Workflow Automation: Agent Graphs as Your Universal Agent Harness
  • AI Agents vs LLMs: Choosing the Right Tool for AI Tasks
  • Building Scalable Agentic Assistants: A Graph-Based Approach
  • Hybrid Vector Graph with AI Agents for Software Test Case Creation

Trending

  • Why Pass/Fail CI Pipelines Are Insufficient for Enterprise Release Decisions
  • Throughput vs Goodput: The Performance Metric You Are Probably Ignoring in LLM Testing
  • LLM Integration in Enterprise Applications: A Practical Guide
  • 11 Agentic Testing Tools to Know in 2026
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. LangGraph Beginner to Advanced: Part 2 — Hello World Graph in LangGraph

LangGraph Beginner to Advanced: Part 2 — Hello World Graph in LangGraph

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.

By 
Mohammed Talib user avatar
Mohammed Talib
·
Oct. 23, 25 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
2.3K Views

Join the DZone community and get the full member experience.

Join For Free

Awesome. 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 going to actually code up some graphs, and we’re about to code up our very first graph in this subsection.

But in this section, we’re not going to be building any AI agents. Why? Since we haven’t really learned how to code in LangGraph yet, or how to combine all these LLM APIs and tools, I thought it would get pretty messy to build one right now.

This course is supposed to be beginner-friendly, detailed, and comprehensive. We’re going to take it step by step, so hopefully you understand, but don’t worry, we will be coding AI agents soon. We’re just going to build a couple of graphs right now to better understand LangGraph, improve the syntax, and learn how to actually code up graphs to get confident with it. Then we will actually build AI agents.

What We Will Build

Okay, cool. So, the graph we’re going to build together in this section is what I call the "hello world graph," mainly because it’s the most basic form of graph we can actually code in lang graph. The objectives are these.

We’re going to define the agent state structure, and don’t worry, you’ll understand what that is in a few minutes. We’re also going to create simple node functions, like we discussed in the previous section, and we’ll be processing them and updating the state. We’re going to build the first-ever basic LangGraph structure and understand how to compile, invoke, and process it — everything. The main goal of this section is to understand how data flows through a single node in LangGraph.

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

Step 1: Imports

Python
 
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 we use to design, connect, and run our workflow of nodes.

Step 2: Create the Agent State

Python
 
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

Python
 
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 behavior.

Step 4: Build the Graph

Python
 
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 the finish point (where it ends), and link them both to the greeter node.

Step 5: Compile the Graph

Python
 
app = graph.compile()


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

Step 6: Visualize the Graph

Python
 
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

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


Output:

Plain Text
 
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, it's 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, and then output something like:

Plain Text
 
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. 

Thank you for reading!

Other Readings You Might Be Interested In

  • Where did multi-agent systems come from?
  • Summarising large documents with GPT-4o
  • How does LlamaIndex compare to LangChain in terms of ease of use for beginners
  • Pre-training vs. fine-tuning [with code implementation]
  • Costs of Hosting Open Source LLMs vs Closed-Sourced (OpenAI)
  • Embeddings: The Backbone of LLMs
  • How to Use a Fine-Tuned Language Model for Summarization
AI Language model Graph (Unix)

Opinions expressed by DZone contributors are their own.

Related

  • Beyond n8n for Workflow Automation: Agent Graphs as Your Universal Agent Harness
  • AI Agents vs LLMs: Choosing the Right Tool for AI Tasks
  • Building Scalable Agentic Assistants: A Graph-Based Approach
  • Hybrid Vector Graph with AI Agents for Software Test Case Creation

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook