Streams a LangGraph run to an external client while the workflow is still running, using Temporal's durable, offset-addressed WorkflowStream. The graph writes a short story about a topic and emits both fine-grained tokens and node-completion progress on separate topics.
- Node token streaming — the
write_storynode calls LangGraph'sget_stream_writer()to emit tokens. The plugin'sstreaming_topic="tokens"routes those writes onto the"tokens"topic. - Workflow-side
astreampublish — the workflow drives the graph withapp.astream(...)and publishes each node-completion chunk onto a"progress"topic it owns. - A single client subscribing to all topics and demultiplexing on
item.topic. - Waiting for the client to acknowledge (via signal) before completing, since the stream disappears when the workflow ends.
- Idempotent consumption — each token chunk carries a monotonic sequence id so the client can dedupe, because streaming is at-least-once per activity attempt (a retried node re-runs and re-publishes its writes).
Prerequisites: uv sync --group langgraph and a running Temporal dev server (temporal server start-dev).
# Terminal 1
uv run langgraph_plugin/graph_api/streaming/run_worker.py
# Terminal 2
uv run langgraph_plugin/graph_api/streaming/run_workflow.py| File | Description |
|---|---|
workflow.py |
Graph node functions, graph definition, and StreamingWorkflow that publishes to the stream |
run_worker.py |
Registers graph with LangGraphPlugin (streaming_topic="tokens"), starts worker |
run_workflow.py |
Starts the workflow, subscribes to the stream, prints tokens and progress, then acks |