|
| 1 | +# LangGraph Plugin Samples |
| 2 | + |
| 3 | +These samples demonstrate the [Temporal LangGraph plugin](https://github.com/temporalio/sdk-python/tree/main/temporalio/contrib/langgraph), which runs LangGraph workflows as durable Temporal workflows. Each LangGraph graph node (Graph API) or `@task` (Functional API) executes as a Temporal activity with automatic retries, timeouts, and crash recovery. |
| 4 | + |
| 5 | +Samples are organized by API style: |
| 6 | + |
| 7 | +- **Graph API** (`graph_api/`) -- Define workflows as `StateGraph` with nodes and edges. |
| 8 | +- **Functional API** (`functional_api/`) -- Define workflows with `@task` and `@entrypoint` decorators for an imperative programming style. |
| 9 | + |
| 10 | +## Samples |
| 11 | + |
| 12 | +| Sample | Graph API | Functional API | Description | |
| 13 | +|--------|:---------:|:--------------:|-------------| |
| 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. | |
| 15 | +| **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. | |
| 16 | +| **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. | |
| 17 | +| **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. | |
| 18 | +| **Control Flow** | -- | [functional_api/control_flow](functional_api/control_flow) | Demonstrates parallel task execution, `for` loops, and `if/else` branching -- patterns that are natural in the Functional API. | |
| 19 | +| **LangSmith Tracing** | [graph_api/langsmith_tracing](graph_api/langsmith_tracing) | [functional_api/langsmith_tracing](functional_api/langsmith_tracing) | Combines `LangGraphPlugin` with Temporal's `LangSmithPlugin` for durable execution + full observability of LLM calls. Requires API keys. | |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +1. Install dependencies: |
| 24 | + |
| 25 | + ```bash |
| 26 | + uv sync --group langgraph |
| 27 | + ``` |
| 28 | + |
| 29 | +2. Start a [Temporal dev server](https://docs.temporal.io/cli#start-dev-server): |
| 30 | + |
| 31 | + ```bash |
| 32 | + temporal server start-dev |
| 33 | + ``` |
| 34 | + |
| 35 | +## Running a Sample |
| 36 | + |
| 37 | +Most samples have two scripts -- start the Worker first, then the Workflow starter in a separate terminal. |
| 38 | + |
| 39 | +```bash |
| 40 | +# Terminal 1: start the Worker |
| 41 | +uv run langgraph_plugin/<api>/<sample>/run_worker.py |
| 42 | + |
| 43 | +# Terminal 2: start the Workflow |
| 44 | +uv run langgraph_plugin/<api>/<sample>/run_workflow.py |
| 45 | +``` |
| 46 | + |
| 47 | +For example, to run the Graph API human-in-the-loop chatbot: |
| 48 | + |
| 49 | +```bash |
| 50 | +# Terminal 1 |
| 51 | +uv run langgraph_plugin/graph_api/human_in_the_loop/run_worker.py |
| 52 | + |
| 53 | +# Terminal 2 |
| 54 | +uv run langgraph_plugin/graph_api/human_in_the_loop/run_workflow.py |
| 55 | +``` |
| 56 | + |
| 57 | +The LangSmith Tracing samples bundle the Worker and Workflow execution into a single `main.py`: |
| 58 | + |
| 59 | +```bash |
| 60 | +uv run langgraph_plugin/<api>/langsmith_tracing/main.py |
| 61 | +``` |
| 62 | + |
| 63 | +## Key Features Demonstrated |
| 64 | + |
| 65 | +- **Durable execution** -- Every graph node / `@task` runs as a Temporal activity with configurable timeouts and retry policies. |
| 66 | +- **Human-in-the-loop** -- LangGraph's `interrupt()` pauses the graph; Temporal signals deliver human input; queries expose pending state to UIs. |
| 67 | +- **Continue-as-new with caching** -- `cache()` captures completed task results; passing the cache to the next execution avoids re-running them. |
| 68 | +- **Conditional routing** -- Graph API's `add_conditional_edges` and Functional API's native `if/else`/`while` for agent loops. |
| 69 | +- **Parallel execution** -- Functional API launches multiple tasks concurrently by creating futures before awaiting them. |
| 70 | + |
| 71 | +## Related |
| 72 | + |
| 73 | +- [Temporal LangGraph plugin docs](https://github.com/temporalio/sdk-python/tree/main/temporalio/contrib/langgraph) |
0 commit comments