Skip to main content
In this tutorial, you’ll build a simple agent that can respond to messages and maintain state. This is the foundation for understanding how LangGraph works.

What you’ll build

A basic agent that:
  • Processes user input
  • Maintains conversation state
  • Returns responses
  • Uses LangGraph’s state management

Prerequisites

Install LangGraph:

Tutorial

1

Define the state

First, define the state structure for your agent. The state holds all the information that flows through your graph.
The AgentState will track:
  • text: The current message text
  • count: Number of times the agent has processed messages
2

Create node functions

Nodes are functions that process the state. Each node receives the current state and returns updates.
Each function:
  • Takes state as input
  • Returns a dictionary with state updates
  • Can access any field from the state
3

Build the graph

Now create the graph by adding nodes and defining edges between them.
The graph flow:
  1. START → process: Begin with processing
  2. process → respond: Generate response
  3. respond → END: Finish execution
4

Run the agent

Execute your agent with different inputs.
Each invocation:
  • Starts with fresh state
  • Flows through all nodes
  • Returns final state
5

Complete example

Here’s the full working code:
Save this as simple_agent.py and run:

Expected output

When you run the complete example, you should see:

Key concepts

  • State: A TypedDict that holds all data flowing through the graph
  • Nodes: Functions that process state and return updates
  • Edges: Connections that define execution flow
  • Graph: The compiled workflow that orchestrates everything

Next steps

Build a Chatbot

Add conversation memory and message handling

Tool Calling

Give your agent the ability to use tools
This simple agent demonstrates the core concepts of LangGraph. All more complex agents build on these same principles.