LangGraphLangGraph 1.2 · Python 3.10+
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
37 small wins to finish your pathNext lesson

Run it as a server

Everything so far ran in a script. To put a graph behind a web page, something has to keep it running and answer requests, and LangGraph ships that something.

Why nothing runs here
There is no captured output on this page or the next one. Both need something running that is not here, a server on your machine and an account with a hosted service. The rule on this site is that output is only shown when it came from a real run. Everything below is real, and there are only two commands to type.

Put the graph in a file

Nothing about the graph changes. It only has to be reachable by name, so the last line assigns the compiled graph to a variable the server can find.

python
# assistant.py
builder = StateGraph(State)
builder.add_node("retrieve", retrieve)
builder.add_node("answer", answer)
builder.add_node("say_no", say_no)
builder.add_edge(START, "retrieve")
builder.add_conditional_edges("retrieve", did_we_find_anything, ["answer", "say_no"])

graph = builder.compile()

Tell the server where to look

One small file beside it, listing your graphs by name and where each one lives.

json
{
  "dependencies": ["."],
  "graphs": {
    "assistant": "./assistant.py:graph"
  },
  "env": ".env"
}

The value is the path to the file, a colon, and the name of the variable. That is why the last line of assistant.py had to be a plain assignment. Call this file langgraph.json.

Start it

bash
pip install "langgraph-cli[inmem]"
langgraph dev

That gives you a local server with your graph behind it. You get a URL to call from your own code, and a browser view where you can run the graph, watch each node as it goes, and read the state at every step.

What you get for free

Three things arrive without any work, and each one is something you built by hand earlier in this course.

WhatWhere you saw it
Threads, so conversations are kept apartthe checkpointer, lesson 20
Runs that pause and wait for an answerinterrupts, lesson 23
Streaming, step by step, to whatever calls itlesson 25

This is the payoff for learning those as ideas rather than as features. The server is not doing anything you have not already done. It is doing it over HTTP.

Calling it

From another program, the client library talks to that URL. The shape will look familiar, because it is the same invoke and the same config.

python
from langgraph_sdk import get_sync_client

client = get_sync_client(url="http://localhost:2024")
thread = client.threads.create()

for chunk in client.runs.stream(thread["thread_id"], "assistant",
                                input={"question": "How do I reset my password?"}):
    print(chunk.data)
This is the development server
langgraph dev keeps everything in memory and is for your machine only. Putting it somewhere real means a database behind the checkpointer and a host to run it on, which is a deployment question rather than a LangGraph one.
Try it yourself
  • Write the langgraph.json for the assistant you built and start the server.
  • Open the browser view and run a question that finds nothing, watching which node it takes.
  • Add a second graph to the file, such as the support agent from lesson 31.

Every expert started right here.