Route LangGraph workflow
A lending graph can run eligibility and credit independently, then combine their artifacts. When status changes, replaying every node repeats credit work; continuing from graph state alone can keep a stale recommendation. Use Co2 inside existing node functions, then let explicit LangGraph routes choose the eligible affected nodes. LangGraph retains scheduling, parallelism and retries.
Install and run
With CPython 3.11–3.14, Rust/Cargo 1.95+, Maturin 1.10.2 and a native build toolchain, from the repository root:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install maturin==1.10.2
maturin develop --locked --extras langgraph
python examples/langgraph_lending.py
python -m unittest discover -s agent_frameworks_tests/langgraph_tests -v
The example uses actual StateGraph parallel branches and conditional routing, but synthetic in-memory data and historical records. It changes customer status within one graph invocation. The observed counts are: eligibility 2, credit 1, recommendation 2, history seeding 1, status change 1, plan 1, review 1, and irreversible funding execution 0.
The current approval disposition is REVALIDATE and funding is ESCALATE. The prior approval and funding values are host-supplied synthetic historical records, not proof that a human approved or an external transfer occurred. The example logs each successful node's computation, attempt and artifact IDs; eligibility and recommendation receive new attempts and artifacts on recomputation while credit's artifact is reused.
Map nodes and artifacts
Create one LangGraphAdapter(thread_id) per live graph thread/session. Pass the same session_id in graph state and {"configurable": {"thread_id": thread_id}} as LangGraph config. The adapter rejects a mismatched token or thread. Its UUID namespace maps a host-chosen logical node name to a stable Co2 computation ID, and each call generates a fresh attempt and successful artifact ID. Separate adapter instances use separate namespaces, including when they share a supplied Coherence; node names or thread labels cannot collide across sessions. The session ID is a correlation value, not authentication.
Inside a node, call run_node(session_id, config, node=..., versions=..., artifacts=..., execution=..., strategy=..., declaration=..., work=...). versions maps every accessible resource name to the host's observed version; artifacts is a sequence of (logical_node, artifact_id) pairs for every accessible artifact. Before the graph, or when a source changes, the host calls register_resource(name, version) in authoritative order.
The adapter captures the Co2 invocation and verifies the host versions match its snapshot before calling work(scope, invocation). Work returns bytes; only a successful return is atomically registered by the existing Co2 API. NodeResult records the session, LangGraph thread, logical node, Co2 computation, attempt, artifact and immutable execution record.
For example, a LangGraph node can call the adapter as follows; the host creates the adapter and registers the initial version before graph execution:
from langchain_core.runnables import RunnableConfig
from co2 import ExecutionKind
from co2.integrations.langgraph import LangGraphAdapter
adapter = LangGraphAdapter("loan-thread")
adapter.register_resource("customer-status", "v1")
def eligibility(state: dict, config: RunnableConfig) -> dict:
# `state` must identify every accessible semantic input; this toy callback
# is supplied only the status value captured by the host.
status = state["status"]
result = adapter.run_node(
state["session_id"], config, node="eligibility",
versions={"customer-status": state["status_version"]},
execution=ExecutionKind.DETERMINISTIC,
work=lambda _context, _invocation: status.encode(),
)
return {"eligibility_artifact": result.artifact}
The complete example shows graph construction and explicit plan-based routing.
The host must list all accessible information that can influence the computation, including graph state, configuration, prompts and closure or tool inputs, as versioned resources or artifacts. Node edges and a node's state access do not prove completeness. The example uses trusted developer declarations such as Declaration(DeclarationSource.DEVELOPER, (adapter.resource_ref("status"), ...)); this is an assertion by host code, not a guarantee inferred by the adapter.
Model declarations retain LLM_FALLBACK; runtime access retains RUNTIME_OBSERVED_FALLBACK, even if accessed through scope. A wrong or missing host observation can make a plan unsound. The host must bind actual source data to the reported versions and ensure the registration stream is ordered.
Resource registrations are individual operations, not an atomic multi-resource snapshot.
The host obtains adapter.plan(session_id, config) and explicitly routes based on the returned Co2 steps. adapter.reuse(...) verifies that the specific current artifact has Co2 validity and disposition REUSE. It is still a point-in-time check: an update may occur immediately afterward.
For new node attempts, existing outputs must have disposition RECOMPUTE or REFRESH; stale probabilistic work needs an explicit PlanPolicy permitting it. The adapter's callback runner rejects unknown, human, side-effecting and irreversible execution kinds. It cannot detect a host that misclassifies a callback as deterministic or prevent direct calls to the SDK or external services.
record_historical records host-supplied human/effect bytes once and executes nothing; it does not prove the claimed effect or implement human revalidation.
A source update racing node execution is caught by Co2's atomic completion check if the update was registered through the same authority. A failed callback publishes no artifact; a LangGraph retry calls the adapter again with a fresh attempt. The adapter abandons captured attempts on callback, encoding or publication failure and burns unused issued identities.
Abandonment fences publication; external execution cancellation remains host-owned. Adapter boundary errors subclass RuntimeError, which LangGraph 1.2.24 excludes from its default retry predicate. Configure RetryPolicy.retry_on narrowly for known transient failures; Co2 domain exceptions have their own types and must not be blindly retried against an unchanged graph snapshot.
If graph code fails after Co2 has committed but before LangGraph accepts the state update, a retry is rejected as not eligible and graph state can be incomplete; do not silently replay or assume exactly-once execution.
Handle checkpoints and failures
LangGraph checkpoints and thread IDs track graph state, not Co2's in-memory resources, attempts or artifact history. See LangGraph's persistence guide. This integration does not persist or reconstruct a Co2 authority and does not support process restart, checkpoint rollback, time travel, or cross-process resume.
A new adapter creates a new session even for the same thread_id; old session state is rejected. At a quiescent graph boundary, call validate_snapshot(session_id, config, all_node_artifacts) with the complete node-to-artifact mapping. It rejects a mismatched session/thread, missing or additional bindings, unknown artifacts, and superseded artifacts.
Stale current artifacts are allowed there only so the host can plan them. At use, reuse or run_node performs its own current checks. These checks are not an atomic transaction with LangGraph's checkpoint or an external system; the host must not mutate the graph concurrently during reconciliation.
Do not resume a checkpoint from a different or missing Co2 authority.
An adapter cannot automatically detect a host bypassing these methods or fabricating the complete checkpoint mapping. Do not serialize/recreate Coherence, bind one adapter to multiple LangGraph thread IDs, or infer source consistency from the existence of a checkpoint. If safe reconciliation cannot be established, stop and start a new workflow under a new session.
Documentation
- LangGraph Graph API: public
StateGraph, parallel branches, state updates, reducers and conditional routing. The example gives parallel nodes distinct state keys. - LangGraph fault tolerance: public node retry policies. Integration tests exercise a retry before registration and reject a failure after Co2 commit.
- LangGraph persistence: graph checkpoints are scoped by
thread_idand are separate from application state outside the graph.
Use the pinned LangGraph version and the configuration matrix for actual platform/interpreter evidence. Configured CI targets are not a claim that a remote run passed. The example is synthetic; framework checkpoint recovery remains unsupported even when the Core uses durable storage.
Example outcome
The default synthetic workflow records eligibility 2, credit 1, recommendation 2. Late-node rejection is exercised by the integration tests; this graph example changes status between completed node stages. These are executed mock-boundary counts, not billing or live-provider performance measurements. Credit retains its artifact; replacements get new attempt/artifact identities. Stale approval requires REVALIDATE; irreversible funding requires ESCALATE and funding execution stays zero. This graph example uses deterministic assessments. If the host substitutes probabilistic reasoning, stale reasoning blocks unless PlanPolicy(allow_probabilistic_recomputation=True) is explicitly supplied.
Check versions, complete accessible context, output schema and current artifact bindings before using results. Session IDs correlate process-local state; they are not authorization credentials. Rejected late results need fresh current context and new identities when eligible. A source update after a successful check can still occur; no adapter locks external source systems. See execution semantics, failure handling and lifecycle cleanup.

