Mhonn YbañezSRE, DevOps, AI Engineer
 Today I Learned
Read the full page

What is LangGraph?

Posted
Tags
ai, llm, agents

LangGraph is a framework for building AI agents as graphs: shared state, steps as nodes, and edges that decide what runs next, including loops. To me it's the skeleton of a harness, the agent loop written as code I can see and change. I liked it enough to start a small project to learn it.

I'm getting really interested in AI engineering, the role where regular software engineering gets to work with AI. The more I read about it, the more two names kept coming up: LangChain and LangGraph. So today I finally looked into them.

The question I had

What are LangChain and LangGraph, how do they relate, and why do they keep showing up next to AI engineering?

What I found

AI engineering, my working definition

My idea of AI engineering is integrating AI features into software products. That lines up with how the term is usually used: building products on top of models that already exist, instead of training new ones. Training models is closer to machine learning engineering. AI engineering is more about the app around the model: what it sees, what tools it can use, and what happens with its answer.

LangChain: the building blocks

LangChain is an open source framework with ready-made pieces for working with models. It has one interface for talking to many model providers, a standard way to define tools, prompt templates, and a long list of integrations. It's the part that saves me from writing the same plumbing for every model and service.

LangGraph: the orchestration

LangGraph comes from the same team, and it sits one level lower. It's for building agents as a graph:

  • State: a shared object that every step reads from and writes to.
  • Nodes: the steps. Each one is a plain function. Some call a model, some run a tool, some just move data around.
  • Edges: what runs next. A conditional edge picks the next node based on the state, which is how the agent decides whether to call a tool or finish.
  • Cycles: edges can point back to an earlier node, so the graph can loop until the work is done.

A tiny agent looks something like this (simplified):

from typing import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    question: str
    notes: list[str]
    done: bool

def think(state: State) -> dict:
    # call the model, decide if more info is needed
    ...

def use_tool(state: State) -> dict:
    # run the tool the model asked for, add the result to notes
    ...

def route(state: State) -> str:
    return "finish" if state["done"] else "use_tool"

graph = StateGraph(State)
graph.add_node("think", think)
graph.add_node("use_tool", use_tool)
graph.add_edge(START, "think")
graph.add_conditional_edges("think", route, {"use_tool": "use_tool", "finish": END})
graph.add_edge("use_tool", "think")  # the cycle

app = graph.compile()

I could write that loop myself with a while loop. What LangGraph adds is everything around it: saving the state after each step so a run can pick up where it left off, pausing so a human can approve something before the agent goes on, and streaming each step as it happens. LangChain's own prebuilt agent runs on LangGraph under the hood.

Where my epiphany came in

Reading through the concepts, it clicked: this is the loop from my harness engineering post. The model thinks, asks for a tool, the app runs it, sends the result back, and repeats until the model is done. LangGraph is that loop, written as a graph I can see and change.

It isn't the whole harness, though. Claude Code isn't built on LangGraph, and LangGraph doesn't come with the tools, prompts, context handling, or permissions. I still have to build those. What it gives me is the skeleton: the state, the steps, and the routing between them, the same kind of foundation a harness like Claude Code is built around.

My mini project

I was so into it that I started a small project to learn it by doing: LangGraph Detective, a LangGraph agent that solves a detective mystery. The goal is to keep its context window as small as possible while it works, instead of letting it fill up with every message and clue like a normal chat. More on it in a future post.

Takeaway

LangChain gives me the pieces, and LangGraph gives me the loop that puts them together. For the kind of AI engineering I want to do, adding AI features to real products, that loop is where most of the design decisions live.