Custom Stream Data
Progress messages.
Sometimes one node does a lot of work, like checking twenty books. You want to tell the customer how it's going, from inside the node. The stream writer sends any data you like, to the stream.

- One node, lots of work
- Report progress
- get_stream_writer
Progress from a node
Get stream writer gives the node a writer function. Inside the loop, the node writes a small progress dictionary for every book. We stream with mode custom, to receive only those. Run it. A progress line arrives for each book, while the node is still working.
from typing import TypedDict
from langgraph.config import get_stream_writer
from langgraph.graph import StateGraph, START
STOCK = {"Dune": 3, "Circe": 0, "Emma": 5}
class State(TypedDict):
report: dict
def check_all(s):
write = get_stream_writer()
for i, title in enumerate(STOCK, 1):
write({"progress": f"checked {title} ({i}/{len(STOCK)})"})
return {"report": dict(STOCK)}
b = StateGraph(State); b.add_node(check_all); b.add_edge(START, "check_all")
for data in b.compile().stream({}, stream_mode="custom"):
print(data["progress"])checked Dune (1/3) checked Circe (2/3) checked Emma (3/3)
Ideas for custom data
Custom data is anything you choose. Progress counts. Status messages, like searching policies. Partial results, like each book found. Or timing information for debugging.
| key | value |
|---|---|
| Progress | 3 of 20 |
| Status | searching... |
| Partial results | as found |
| Timing | for debugging |
Summary
Get stream writer lets a node send its own data to the stream. Receive it with stream mode custom. Next, several stream modes at once.
Key takeaways- get_stream_writer()
- write({...})
- stream_mode='custom'