TemporalGraph¶
The primary entry point for running LangGraph graphs on Temporal.
TemporalGraph
¶
TemporalGraph(
graph: Pregel,
client: Client,
*,
task_queue: str = "langgraph-default",
node_task_queues: dict[str, str] | None = None,
node_activity_options: dict[str, ActivityOptions]
| None = None,
workflow_execution_timeout: timedelta | None = None,
workflow_run_timeout: timedelta | None = None,
stream_backend: StreamBackend | None = None,
)
Wraps a compiled LangGraph graph for execution on Temporal.
This is the primary entry point for using LangGraph with Temporal.
It preserves the familiar invoke() / stream() API while executing
the graph as a Temporal Workflow with durable execution guarantees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Pregel
|
A compiled Pregel graph (output of |
required |
client
|
Client
|
A Temporal client instance. |
required |
task_queue
|
str
|
Default task queue for Activities. |
'langgraph-default'
|
node_task_queues
|
dict[str, str] | None
|
Per-node task queue overrides. |
None
|
node_activity_options
|
dict[str, ActivityOptions] | None
|
Per-node Activity configuration. |
None
|
workflow_execution_timeout
|
timedelta | None
|
Maximum time for the entire workflow execution including retries and continue-as-new. |
None
|
workflow_run_timeout
|
timedelta | None
|
Maximum time for a single workflow run. |
None
|
stream_backend
|
StreamBackend | None
|
Backend for streaming events. |
None
|
Source code in langgraph/temporal/graph.py
ainvoke
async
¶
ainvoke(
input: Any,
config: dict[str, Any] | None = None,
*,
interrupt_before: list[str] | None = None,
interrupt_after: list[str] | None = None,
**kwargs: Any,
) -> dict[str, Any]
Execute the graph as a Temporal Workflow and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Any
|
Input to the graph. |
required |
config
|
dict[str, Any] | None
|
RunnableConfig with thread_id and other settings. |
None
|
interrupt_before
|
list[str] | None
|
Node names to pause before executing. |
None
|
interrupt_after
|
list[str] | None
|
Node names to pause after executing. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The final channel state values. |
Source code in langgraph/temporal/graph.py
invoke
¶
invoke(
input: Any,
config: dict[str, Any] | None = None,
*,
interrupt_before: list[str] | None = None,
interrupt_after: list[str] | None = None,
**kwargs: Any,
) -> dict[str, Any]
Execute the graph as a Temporal Workflow and return the result.
Synchronous wrapper around ainvoke().
Source code in langgraph/temporal/graph.py
astream
async
¶
astream(
input: Any,
config: dict[str, Any] | None = None,
*,
stream_mode: str = "values",
**kwargs: Any,
) -> AsyncIterator[Any]
Stream graph execution events from a Temporal Workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Any
|
Input to the graph. |
required |
config
|
dict[str, Any] | None
|
RunnableConfig with thread_id and other settings. |
None
|
stream_mode
|
str
|
Stream mode (values, updates, custom, messages). |
'values'
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[Any]
|
Stream events matching the requested mode. |
Source code in langgraph/temporal/graph.py
stream
¶
stream(
input: Any,
config: dict[str, Any] | None = None,
*,
stream_mode: str = "values",
**kwargs: Any,
) -> Iterator[Any]
Stream graph execution events (synchronous).
Synchronous wrapper around astream().
Source code in langgraph/temporal/graph.py
astart
async
¶
astart(
input: Any,
config: dict[str, Any] | None = None,
*,
interrupt_before: list[str] | None = None,
interrupt_after: list[str] | None = None,
) -> WorkflowHandle
Start a Workflow without waiting for completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Any
|
Input to the graph. |
required |
config
|
dict[str, Any] | None
|
RunnableConfig with thread_id and other settings. |
None
|
Returns:
| Type | Description |
|---|---|
WorkflowHandle
|
A Temporal WorkflowHandle for querying/signaling the workflow. |
Source code in langgraph/temporal/graph.py
get_state
async
¶
Query the Workflow for current state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
RunnableConfig with thread_id. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The current state query result. |
Source code in langgraph/temporal/graph.py
get_state_history
async
¶
Retrieve state history from the Temporal Workflow.
Currently returns the current state only. In the future, this will traverse the continue-as-new chain for full history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
RunnableConfig with thread_id. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of state snapshots. |
Source code in langgraph/temporal/graph.py
update_state
async
¶
update_state(
config: dict[str, Any],
values: dict[str, Any],
*,
as_node: str | None = None,
) -> None
Send a state update Signal to a running Workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
RunnableConfig with thread_id. |
required |
values
|
dict[str, Any]
|
Channel values to update. |
required |
as_node
|
str | None
|
Node name to attribute the update to (for trigger tracking). |
None
|
Source code in langgraph/temporal/graph.py
resume
async
¶
Send a resume Signal to a paused Workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
RunnableConfig with thread_id. |
required |
value
|
Any
|
The resume value to send. |
required |
Source code in langgraph/temporal/graph.py
create_worker
¶
Create a Temporal Worker configured for this graph.
Returns:
| Type | Description |
|---|---|
Any
|
A Temporal Worker instance ready to run. |
Source code in langgraph/temporal/graph.py
local
async
classmethod
¶
local(
graph: Pregel,
*,
task_queue: str = "langgraph-default",
**kwargs: Any,
) -> TemporalGraph
Create a TemporalGraph using Temporal's local test server.
This is a convenience factory for local development and testing. It starts an in-process Temporal test server, removing the need for a full Temporal server deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Pregel
|
A compiled Pregel graph instance. |
required |
task_queue
|
str
|
Default task queue name. |
'langgraph-default'
|
**kwargs
|
Any
|
Additional arguments passed to TemporalGraph. |
{}
|
Returns:
| Type | Description |
|---|---|
TemporalGraph
|
A TemporalGraph configured with the local test server client. |