Skip to content

Commit ee781cd

Browse files
committed
Add hello_world samples, per-sample READMEs, tests, __init__ docstrings, and configurable client
1 parent 0505fd1 commit ee781cd

53 files changed

Lines changed: 1495 additions & 295 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

langgraph_plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Samples are organized by API style:
1111

1212
| Sample | Graph API | Functional API | Description |
1313
|--------|:---------:|:--------------:|-------------|
14+
| **Hello World** | [graph_api/hello_world](graph_api/hello_world) | [functional_api/hello_world](functional_api/hello_world) | Minimal sample -- single node/task that processes a query string. Start here. |
1415
| **Human-in-the-loop** | [graph_api/human_in_the_loop](graph_api/human_in_the_loop) | [functional_api/human_in_the_loop](functional_api/human_in_the_loop) | Chatbot that uses `interrupt()` to pause for human approval, Temporal signals to receive feedback, and queries to expose the pending draft. |
1516
| **Continue-as-new** | [graph_api/continue_as_new](graph_api/continue_as_new) | [functional_api/continue_as_new](functional_api/continue_as_new) | Multi-stage data pipeline that uses `continue-as-new` with task result caching so previously-completed stages are not re-executed. |
1617
| **ReAct Agent** | [graph_api/react_agent](graph_api/react_agent) | [functional_api/react_agent](functional_api/react_agent) | Tool-calling agent loop. Graph API uses conditional edges; Functional API uses a `while` loop. |

langgraph_plugin/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Temporal LangGraph plugin samples."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""LangGraph Functional API samples using @task and @entrypoint."""
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Continue-as-New with Caching (Functional API)
2+
3+
Same pattern as the Graph API version, using `@task` and `@entrypoint` decorators.
4+
5+
## What This Sample Demonstrates
6+
7+
- Task result caching across continue-as-new boundaries with `get_cache()`
8+
- Restoring cached results with `entrypoint(name, cache=...)`
9+
- Each `@task` executes exactly once despite multiple workflow invocations
10+
11+
## How It Works
12+
13+
1. Three tasks run sequentially: `extract` (x2) -> `transform` (+50) -> `load` (x3).
14+
2. After the first invocation, the workflow continues-as-new with the cache.
15+
3. On subsequent invocations, all tasks return cached results instantly.
16+
4. Input 10 -> 20 -> 70 -> 210.
17+
18+
## Running the Sample
19+
20+
Prerequisites: `uv sync --group langgraph` and a running Temporal dev server.
21+
22+
```bash
23+
# Terminal 1
24+
uv run langgraph_plugin/functional_api/continue_as_new/run_worker.py
25+
26+
# Terminal 2
27+
uv run langgraph_plugin/functional_api/continue_as_new/run_workflow.py
28+
```
29+
30+
## Files
31+
32+
| File | Description |
33+
|------|-------------|
34+
| `workflow.py` | `@task` functions, `@entrypoint`, `PipelineInput`, and `PipelineFunctionalWorkflow` |
35+
| `run_worker.py` | Registers tasks and entrypoint with `LangGraphPlugin`, starts worker |
36+
| `run_workflow.py` | Executes the pipeline workflow and prints the result |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Continue-as-new pipeline with task result caching."""

langgraph_plugin/functional_api/continue_as_new/run_worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Worker for the continue-as-new pipeline (Functional API)."""
22

33
import asyncio
4+
import os
45

56
from temporalio.client import Client
67
from temporalio.contrib.langgraph import LangGraphPlugin
@@ -15,7 +16,7 @@
1516

1617

1718
async def main() -> None:
18-
client = await Client.connect("localhost:7233")
19+
client = await Client.connect(os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"))
1920
plugin = LangGraphPlugin(
2021
entrypoints={"pipeline": pipeline_entrypoint},
2122
tasks=all_tasks,

langgraph_plugin/functional_api/continue_as_new/run_workflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Start the continue-as-new pipeline workflow (Functional API)."""
22

33
import asyncio
4+
import os
45
from datetime import timedelta
56

67
from temporalio.client import Client
@@ -12,7 +13,7 @@
1213

1314

1415
async def main() -> None:
15-
client = await Client.connect("localhost:7233")
16+
client = await Client.connect(os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"))
1617

1718
result = await client.execute_workflow(
1819
PipelineFunctionalWorkflow.run,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Control Flow (Functional API)
2+
3+
Demonstrates the Functional API's strength for complex control flow: parallel execution, sequential loops, and conditional branching — all as natural Python code.
4+
5+
## What This Sample Demonstrates
6+
7+
- **Parallel execution**: launching multiple tasks concurrently by creating futures before awaiting
8+
- **For loops**: processing items sequentially with `for item in items`
9+
- **If/else branching**: routing items based on classification results
10+
- Why the Functional API is ideal for programmatic composition patterns
11+
12+
## How It Works
13+
14+
1. A batch of items is validated **in parallel** — all `validate_item` tasks launch concurrently.
15+
2. Valid items are processed **sequentially** in a for loop.
16+
3. Each item is classified, then routed via **if/else** to `process_urgent` or `process_normal`.
17+
4. Results are aggregated with a `summarize` task.
18+
19+
## Running the Sample
20+
21+
Prerequisites: `uv sync --group langgraph` and a running Temporal dev server.
22+
23+
```bash
24+
# Terminal 1
25+
uv run langgraph_plugin/functional_api/control_flow/run_worker.py
26+
27+
# Terminal 2
28+
uv run langgraph_plugin/functional_api/control_flow/run_workflow.py
29+
```
30+
31+
## Files
32+
33+
| File | Description |
34+
|------|-------------|
35+
| `workflow.py` | `@task` functions (validate, classify, process, summarize), `@entrypoint`, and `ControlFlowWorkflow` |
36+
| `run_worker.py` | Registers tasks and entrypoint with `LangGraphPlugin`, starts worker |
37+
| `run_workflow.py` | Sends a batch of items and prints processing results |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Control flow: parallel execution, for loops, and if/else branching."""

langgraph_plugin/functional_api/control_flow/run_worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Worker for the control flow pipeline (Functional API)."""
22

33
import asyncio
4+
import os
45

56
from temporalio.client import Client
67
from temporalio.contrib.langgraph import LangGraphPlugin
@@ -15,7 +16,7 @@
1516

1617

1718
async def main() -> None:
18-
client = await Client.connect("localhost:7233")
19+
client = await Client.connect(os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"))
1920
plugin = LangGraphPlugin(
2021
entrypoints={"control_flow": control_flow_pipeline},
2122
tasks=all_tasks,

0 commit comments

Comments
 (0)