Skip to content

AI-36: Add LangGraph plugin#1448

Open
brianstrauch wants to merge 55 commits intomainfrom
langgraph
Open

AI-36: Add LangGraph plugin#1448
brianstrauch wants to merge 55 commits intomainfrom
langgraph

Conversation

@brianstrauch
Copy link
Copy Markdown
Contributor

Summary

  • Add a new temporalio.contrib.langgraph plugin that runs LangGraph nodes and tasks as Temporal Activities, bringing durable execution, automatic retries, and timeouts to AI agent workflows
  • Supports both the LangGraph Graph API (wrapping StateGraph nodes) and Functional API (wrapping @entrypoint / @task functions)
  • Includes a task result cache for continue-as-new support, so previously completed nodes/tasks are not re-executed across workflow continuations
  • Handles GraphInterrupt propagation between Activities and Workflows for human-in-the-loop patterns
  • Automatically configures the Temporal sandbox to pass through LangGraph/LangChain modules

Details

New files:

  • langgraph_plugin.py — LangGraphPlugin (extends SimplePlugin) that registers graph nodes/tasks as Activities and configures the sandbox runner
  • activity.py — Activity wrappers that serialize/deserialize LangGraph config and handle GraphInterrupt
  • langgraph_config.py — Helpers to get/set LangGraph's internal RunnableConfig (checkpoint namespace, scratchpad) across the workflow-activity boundary
  • task_cache.py — Content-addressed cache keyed by (task_id, args, kwargs) hash for deduplicating work across continue-as-new
  • README.md — Usage documentation with examples for both Graph and Functional APIs

Tests cover: two-node graphs, subgraphs (as activities and workflows), interrupts, streaming, timeouts, continue-as-new (with and without caching), execute-in-workflow mode, and full end-to-end functional API workflows.

Test plan

  • uv run pytest tests/contrib/langgraph/ — all 12 test files pass

@brianstrauch brianstrauch requested a review from a team as a code owner April 14, 2026 21:55
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 14, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new temporalio.contrib.langgraph integration to run LangGraph Graph/Functional API nodes/tasks as Temporal Activities (with retries/timeouts), including continue-as-new caching and interrupt propagation, plus an accompanying test suite.

Changes:

  • Introduces LangGraphPlugin + activity/config/cache plumbing for executing LangGraph nodes/tasks via Temporal Activities and supporting interrupts + continue-as-new deduping.
  • Adds a new langgraph optional extra and locks required LangGraph/LangChain dependencies.
  • Adds an end-to-end test suite covering graphs, subgraphs, interrupts (v1/v2), streaming, timeouts, execute-in-workflow, and continue-as-new caching.

Reviewed changes

Copilot reviewed 22 out of 24 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
uv.lock Locks new LangGraph/LangChain-related dependencies and adds langgraph extra entries.
pyproject.toml Adds langgraph optional dependency and dev dependency.
temporalio/contrib/langgraph/init.py Exposes LangGraphPlugin, graph, entrypoint, and cache public API.
temporalio/contrib/langgraph/langgraph_plugin.py Implements the plugin: registers activities, sandbox passthrough, and graph/entrypoint accessors.
temporalio/contrib/langgraph/activity.py Activity wrappers for config propagation, interrupt handling, and cache-aware execution.
temporalio/contrib/langgraph/langgraph_config.py Serializes/deserializes LangGraph runnable config (checkpoint namespace/scratchpad) across workflow/activity boundary.
temporalio/contrib/langgraph/task_cache.py Implements a content-addressed task result cache for continue-as-new deduplication.
temporalio/contrib/langgraph/README.md Documents installation and usage for Graph/Functional APIs and activity options.
tests/contrib/langgraph/init.py Adds test package marker for the new test suite.
tests/contrib/langgraph/conftest.py Provides langgraph-specific Temporal test environment and client fixtures.
tests/contrib/langgraph/test_two_nodes.py Verifies basic two-node graph execution via activities.
tests/contrib/langgraph/test_timeout.py Verifies activity timeout behavior is enforced through node metadata.
tests/contrib/langgraph/test_subgraph_workflow.py Verifies subgraph execution with execute_in="workflow".
tests/contrib/langgraph/test_subgraph_activity.py Verifies subgraph execution inside an activity node.
tests/contrib/langgraph/test_streaming.py Verifies streaming (astream) behavior across activity-wrapped nodes.
tests/contrib/langgraph/test_interrupt.py Verifies v1 interrupt propagation and resume semantics.
tests/contrib/langgraph/test_interrupt_v2.py Verifies v2 interrupt semantics (GraphOutput.value/.interrupts) and resume.
tests/contrib/langgraph/test_execute_in_workflow.py Verifies execute_in="workflow" bypasses activity wrapping.
tests/contrib/langgraph/test_continue_as_new.py Verifies continue-as-new with LangGraph checkpointer state restoration.
tests/contrib/langgraph/test_continue_as_new_cached.py Verifies continue-as-new caching prevents re-execution across continuations.
tests/contrib/langgraph/test_e2e_functional.py End-to-end functional API workflows (including continue-as-new + partial execution scenarios).
tests/contrib/langgraph/test_e2e_functional_v2.py End-to-end functional API workflows using version="v2" GraphOutput.
tests/contrib/langgraph/e2e_functional_entrypoints.py Defines functional @task/@entrypoint implementations used by E2E tests.
tests/contrib/langgraph/e2e_functional_workflows.py Defines Temporal workflow wrappers used by functional API E2E tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread temporalio/contrib/langgraph/langgraph_plugin.py Outdated
Comment thread temporalio/contrib/langgraph/langgraph_plugin.py Outdated
Comment thread temporalio/contrib/langgraph/langgraph_plugin.py Outdated
Comment thread temporalio/contrib/langgraph/langgraph_plugin.py Outdated
Comment thread temporalio/contrib/langgraph/README.md Outdated
Comment thread tests/contrib/langgraph/conftest.py Outdated
DABH added a commit to DABH/samples-python that referenced this pull request Apr 14, 2026
Seven samples demonstrating the Temporal LangGraph plugin across both the
Graph API and Functional API:

- Human-in-the-loop: interrupt() + Temporal signals for chatbot approval
- Continue-as-new: task result caching across workflow boundaries
- ReAct agent: tool-calling loop with conditional edges / while loop
- Control flow (Functional API only): parallel, for-loop, if/else

Related SDK PR: temporalio/sdk-python#1448
DABH added a commit to temporalio/documentation that referenced this pull request Apr 16, 2026
Add a full integration guide for the new LangGraph plugin
(temporalio/sdk-python#1448) covering both Graph API and Functional API
usage, Activity options, checkpointer setup, human-in-the-loop,
continue-as-new with caching, and links to samples.

Also adds LangGraph to the Python integrations index, sidebar,
plugins guide, and encyclopedia.

import langsmith

# langsmith conditionally imports langchain_core when it is installed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this change is needed for langgraph?

Copy link
Copy Markdown
Contributor

@DABH DABH Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[edited for accuracy] The langgraph Python package directly depends on the langchain-core Python package, so in an environment where langgraph is installed, langchain-core is installed as well. This is just a env/venv-level thing. The CI pipeline is one such environment. But so in any environment where langchain-core is available, langsmith tries to import it - but fails if it's not passed through for langsmith. You can be running Python code that doesn't import LangGraph or anything, but as long as langchain-core is installed in the env, langsmith will try to import it. So for safety, for the case where a user may have langchain-core installed (e.g., when they are using LangSmith + LangGraph, which should be fairly common), we need to pass through langchain-core into the sandbox.

For this block specifically, my understanding is that this import helps bypass some restrictions on the sandbox and/or helps langsmith get the sandboxed version of langchain-core when it dynamically loads/imports it. Not 100% clarity without digging further into langsmith internals but can add a follow-up if we want to investigate more.

Comment thread tests/contrib/langsmith/test_integration.py Outdated
Comment thread temporalio/contrib/langgraph/plugin.py Outdated
Comment thread temporalio/contrib/langgraph/plugin.py Outdated
Comment thread temporalio/contrib/langgraph/README.md
Comment thread temporalio/contrib/langgraph/README.md Outdated
Comment thread temporalio/contrib/langgraph/README.md Outdated
Comment thread temporalio/contrib/langgraph/README.md Outdated
Comment thread temporalio/contrib/langgraph/README.md Outdated

```python
# Graph API
graph.add_node("my_node", my_node, metadata={"execute_in": "workflow"})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to call out, in other integrations, this is the default and activities are done explicitly. Do we want to maintain that discrepancy?

Comment thread temporalio/contrib/langgraph/README.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants