AI Hints
Home›LangGraph Tutorial›Streaming
LangGraph · Lesson 49 of 120

Streaming Values

The whole state.

⏱ 2 min read▶ Video at 51:59🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

Invoke waits for the whole run, then returns the end result. Stream gives you results as the graph runs. It has several modes. The first, values, gives you the whole state after every step.

Streaming Values
From the video: Streaming Values
  • invoke waits
  • stream as it runs
  • values: whole state

Watching the state grow

We stream the order pipeline, with stream mode values. Each item is the full state, after a step. We print the keys that are filled in so far. Run it. First the input, then the state after clean, after price, and after receipt. The keys fill in as each step adds its part.

stream_values.pypython
from order_graph import graph

config = {"configurable": {"thread_id": "s1"}}
for state in graph.stream({"title": "dune", "quantity": 2}, config, stream_mode="values"):
    print(sorted(state.keys()), "| total:", state.get("total"))
Output
['quantity', 'title'] | total: None
['quantity', 'title'] | total: None
['quantity', 'title', 'total'] | total: 19.98
['quantity', 'receipt', 'title', 'total'] | total: 19.98
Also uses order_graph.py
from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START, END

PRICES = {"Dune": 9.99, "Circe": 10.99}

class Order(TypedDict):
    title: str
    quantity: int
    total: float
    receipt: str

def clean(s):
    return {"title": s["title"].strip().title()}
def price(s):
    return {"total": round(PRICES[s["title"]] * s["quantity"], 2)}
def receipt(s):
    return {"receipt": f"{s['quantity']} x {s['title']} = £{s['total']}"}

b = StateGraph(Order)
b.add_sequence([clean, price, receipt])
b.add_edge(START, "clean"); b.add_edge("receipt", END)
graph = b.compile(checkpointer=InMemorySaver())

When to use values

Values mode is simple. You always have the complete picture. It's handy when your app just shows the latest state, like a progress page, or a chat window showing every message.

keyvalue
Each itemthe full state
Afterevery step
Simplecomplete picture
Biggerthan updates

Summary

Stream mode values yields the full state after every step. Next, streaming only what changed.

Key takeaways
  • graph.stream(...)
  • stream_mode='values'
  • Full state each step
Next up: Streaming Updates — what changed