$ fssg build --deterministic --validate |

How to Split an AI Agent Between LangGraph and Temporal

AI Engineering

An agent graph and a durable workflow solve different failures. I would not migrate a LangGraph agent to Temporal by wrapping the whole graph in a retry. I would split it at the side-effect boundary.

LangGraph is good at expressing the changing path of reasoning: state, nodes, conditional edges, interrupts, and checkpoints. Temporal is built to preserve workflow execution across worker crashes and infrastructure failures, while moving external operations into Activities with explicit timeouts and retry policies. The recent Temporal–LangGraph integration makes these layers composable. It does not erase the need to decide which layer owns each guarantee.

That ownership decision is the migration.

Start with the failure, not the framework

Before changing code, I classify every operation by what can go wrong after it starts.

Operation Main failure Owner I want
Choose the next reasoning step Wrong or stale decision LangGraph state and routing
Call an LLM Timeout, rate limit, nondeterministic result Temporal Activity
Read an external API Network failure, changed response Temporal Activity
Send email, charge, deploy, write a ticket Duplicate or uncertain side effect Temporal Activity plus business idempotency
Wait for approval Process restart, long pause LangGraph interrupt carried by Temporal signal/query
Transform already-recorded state Replay divergence Deterministic Workflow code
Remember data across conversations Wrong lifetime or scope A durable application store, not a workflow checkpoint

This table prevents the most common migration mistake: treating persistence as one undifferentiated feature. A graph checkpoint preserves graph state. A workflow history supports deterministic replay. An application store preserves cross-thread knowledge. An idempotency record protects an external effect. They may all use storage, but they do not restore the same thing.

I use the broader layer model from Agent, Harness, Workflow, or Runtime? to identify the missing invariant first. Only then do I select the integration point.

Draw the boundary around effects

The integration supports two execution locations for graph nodes and tasks:

  • an Activity, with configurable timeout and retry policy;
  • directly inside the Workflow, where code must remain deterministic.

That distinction should shape the graph. If a node can observe or change the outside world, I put it in an Activity. Model calls, tool calls, HTTP requests, database writes, notifications, and deployments belong there. A conditional edge that selects a route from recorded state can stay inside the Workflow, provided it is deterministic.

A useful rule is:

Workflow code decides from recorded facts.
Activity code obtains facts or causes effects.

This is stricter than “pure code versus impure code.” The real question is whether replaying the operation could produce a new observation or repeat a consequence. A current timestamp, random value, network response, or model completion can change between executions. It must not silently enter replay-sensitive logic.

Temporal's integration documentation makes this concrete: conditional edge functions run in the Workflow and must be deterministic and asynchronous; Activity nodes receive retry and timeout controls. The boundary is not an implementation detail. It is the recovery contract.

Migrate in four passes

1. Inventory nodes by effect class

I label every node as one of four types:

  1. decision — routes using state that is already recorded;
  2. observation — reads a model, API, file, or service;
  3. effect — changes an external system;
  4. wait — pauses for a person, event, or deadline.

A single node that mixes all four is a migration warning. I split it before introducing durable execution. Otherwise a retry policy can repeat an email while merely trying to recover an LLM timeout.

2. Move observations and effects into Activities

Each Activity gets a timeout based on the operation, not one global default. Retry policy is equally specific. A read-only status request may tolerate automatic retry. A payment or deployment requires a stable business operation ID and a reconciliation path before retry.

This is where Effect IDs Before Retry matters. Temporal can re-execute an Activity under its delivery semantics; it cannot make an arbitrary external API idempotent. The destination or an adapter still needs to recognize the same intended effect.

3. Keep graph routing replay-safe

Conditional edges, state reducers, and Workflow-local nodes should operate only on serializable, recorded inputs. They must not read the network, ambient time, mutable global state, or uncontrolled randomness.

The Temporal plugin allows graph and functional APIs, but the invariant is the same: the replayed path must agree with the recorded history. If a routing decision depends on a fresh model call, the model call belongs in an Activity and its result becomes recorded state before routing continues.

4. Model pauses as protocol, not sleep

LangGraph interrupts are useful for human review. In the Temporal integration, an interrupt can be surfaced through Workflow queries and resumed through signals. That gives the pause an explicit protocol:

draft produced
→ pending approval exposed
→ reviewer decision received
→ graph resumed with that decision

The process can disappear while the decision is pending. More importantly, the identity and scope of the pending action can remain explicit. Approval should bind to the proposed effect, not merely to a conversation turn.

Do not run two durability systems by accident

LangGraph has its own persistence model. Checkpointers save thread-scoped graph snapshots; stores hold application-defined data across threads. Temporal has Workflow history and replay. Combining them without assigning ownership can create two authorities for “current state.”

The Temporal plugin documentation says an in-memory LangGraph checkpointer can run inside the Workflow because Temporal provides durability. It also notes an important current limitation: stores are not supported by the integration. That means the plugin does not replace long-term application memory.

My default boundary is:

  • Temporal Workflow history owns execution recovery;
  • LangGraph state owns the agent's current reasoning state inside that execution;
  • an application database owns durable business and cross-thread memory;
  • the destination system or an effect ledger owns side-effect identity.

Do not mirror the same mutable execution state into all four. Store references and identities across boundaries, then define one source of truth for each lifecycle.

A decision matrix for the combined stack

Requirement LangGraph alone Temporal alone Combined boundary
Dynamic agent topology Native graph abstraction Must be modeled manually LangGraph
Thread checkpoints and time travel Native checkpointer model Event history is not the same API LangGraph, when needed
Infrastructure-level durable execution Depends on deployment and checkpointer configuration Core model Temporal
Activity retries and timeouts Implement around nodes/tools Native Temporal Activities
Human-in-the-loop graph pause Native interrupt model Signals, queries, updates LangGraph interrupt over Temporal protocol
Cross-thread long-term memory Store abstraction Not Workflow history's job External durable store
Exactly-once business effect Not guaranteed by graph state Not guaranteed for arbitrary destinations Stable effect ID plus destination/ledger

This is not a product ranking. It is a responsibility map. The combined stack is justified only when the application needs both a dynamic agent graph and durable workflow semantics. A short, read-only assistant may need neither. A fixed business process may need Temporal without LangGraph. A local coding loop may need LangGraph persistence without a workflow service.

Verify recovery before trusting it

After migration, I test boundaries rather than the happy path:

  1. kill the worker after an Activity commits externally but before completion is acknowledged;
  2. resume an approval after the original worker and client are gone;
  3. change Workflow code and run replay tests against captured histories;
  4. force a long graph to continue as new before history growth becomes operational debt;
  5. confirm that a repeated effect ID reconciles instead of duplicating the action;
  6. verify that cross-thread memory survives independently of Workflow retention.

The integration documentation explicitly calls out continue-as-new for long-running graphs and a serializable task-result cache to avoid recomputing completed nodes. That solves history growth at the workflow layer. It still requires an application decision about what state deserves to cross into the new run.

For recovery semantics beyond retries, I use the distinctions in Retry, Resume, Roll Back, or Compensate?. Durable execution does not collapse those operations into one.

The practical conclusion

I would adopt the combined stack when one sentence describes the need: the agent must choose a changing path, and the system must preserve the consequences of that path across failure.

LangGraph should own the topology of reasoning. Temporal should own durable execution around observations, effects, waits, and retries. The application should still own business identity, memory lifetime, authorization, and reconciliation.

The integration reduces glue code. It does not remove architecture. Its value is that the boundary can now be expressed directly—if we draw it before we migrate.

Sources

FACET AI CLI Terminal
facet@ai:~$