Skip to content

Commit 346b49f

Browse files
brianstrauchclaude
andcommitted
Add README for graph_api/streaming sample
Every other graph_api/ sample has a standalone README with run instructions and a "what this demonstrates" blurb; streaming was the only one without. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c4dc3e8 commit 346b49f

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • langgraph_plugin/graph_api/streaming
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Streaming (Graph API)
2+
3+
Streams a LangGraph run to an external client while the workflow is still running, using Temporal's durable, offset-addressed [`WorkflowStream`](https://docs.temporal.io/). The graph writes a short story about a topic and emits both fine-grained tokens and node-completion progress on separate topics.
4+
5+
## What This Sample Demonstrates
6+
7+
- **Node token streaming** — the `write_story` node calls LangGraph's `get_stream_writer()` to emit tokens. The plugin's `streaming_topic="tokens"` routes those writes onto the `"tokens"` topic.
8+
- **Workflow-side `astream` publish** — the workflow drives the graph with `app.astream(...)` and publishes each node-completion chunk onto a `"progress"` topic it owns.
9+
- A single client subscribing to all topics and demultiplexing on `item.topic`.
10+
- Waiting for the client to acknowledge (via signal) before completing, since the stream disappears when the workflow ends.
11+
- **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).
12+
13+
## Running the Sample
14+
15+
Prerequisites: `uv sync --group langgraph` and a running Temporal dev server (`temporal server start-dev`).
16+
17+
```bash
18+
# Terminal 1
19+
uv run langgraph_plugin/graph_api/streaming/run_worker.py
20+
21+
# Terminal 2
22+
uv run langgraph_plugin/graph_api/streaming/run_workflow.py
23+
```
24+
25+
## Files
26+
27+
| File | Description |
28+
|------|-------------|
29+
| `workflow.py` | Graph node functions, graph definition, and `StreamingWorkflow` that publishes to the stream |
30+
| `run_worker.py` | Registers graph with `LangGraphPlugin` (`streaming_topic="tokens"`), starts worker |
31+
| `run_workflow.py` | Starts the workflow, subscribes to the stream, prints tokens and progress, then acks |

0 commit comments

Comments
 (0)