Use o11 with LangGraph

LangGraph can orchestrate an agent workflow while o11 handles access to external tool operations. The useful boundary is a graph node that submits one approved intent and a separate node that retrieves the existing invocation. Graph progress and supplier work remain connected without being confused.

This walkthrough builds a submit-and-inspect graph, then explains how to add persistence, approvals, and recovery for longer work. A research or media step can continue after the agent’s turn ends, while the application retains the accepted result and resumes from the right place.

Persist the request intent before a replayable execution node runs. A graph replay must recover the same external work rather than authorize a new purchase.

Define the boundary between graph and supplier

The graph owns task state, ordering, branching, and when the workflow should pause. The tool service owns the accepted external invocation and its execution lifecycle. A completed graph node may therefore mean “submission recorded,” while the supplier job remains pending.

Keep these states separate. A graph checkpoint does not prove a provider completed work. A supplier receipt does not prove the graph’s business acceptance criteria passed. The application needs both records to decide what to show the user.

LangGraph’s Graph API models state and node updates, then compiles the graph before invocation. Its current documentation uses StateSchema to define state fields. LangGraph Graph API.

For a research task, the graph might prepare the input, dispatch retrieval, wait for the existing call, validate evidence, and draft a brief. Each node should make a meaningful state transition rather than hide a long uncontrolled agent loop.

Prepare a durable intent before dispatch

The intent should contain the selected operation, exact input, account mode, approved maximum, and stable idempotency key. Store it through your application’s durable task path before executing the supplier-facing node.

Use an actual tool identifier and input contract from discovery and inspection. Keep account choice and spending authority in trusted configuration. An agent can propose a URL or task input, but it should not expand its own policy by selecting a different account or raising a maximum.

Do not create the idempotency key inside a node that may rerun. A fresh random key on replay turns recovery into a new purchase. The key must remain attached to the original approved intent.

Likewise, do not silently change the request while retaining the old key. If the user changes a media prompt or input document, that is a new intent with its own approval and record.

The migration guide explains how to preserve those intent records while changing execution infrastructure.

Build a submit-and-inspect graph

The following example demonstrates the boundary. It submits the approved request and retrieves its current receipt once. It deliberately does not spin until a long-running job finishes.

The API shape follows the current JavaScript Graph API documentation reviewed on October 18, 2026, including StateSchema, StateGraph, START, and END. It reuses the public HTTP adapter from the custom agent guide. Supplier access, pricing, and authority must be configured before paid execution; the verification section distinguishes this contract example from an installed runtime or live supplier test.

import { END, START, StateGraph, StateSchema } from "@langchain/langgraph";
import { z } from "zod";
import { createO11Http } from "./o11-http";

const Receipt = z.object({
  id: z.string().uuid(),
  state: z.enum([
    "awaiting_approval", "queued", "executing", "waiting",
    "succeeded", "failed", "unknown", "cancelled",
  ]),
  result: z.unknown(),
});

const RunState = new StateSchema({
  approvedRequest: z.unknown(),
  invocationId: z.string().nullable().default(null),
  outcome: z.string().default("not_submitted"),
});

export function createToolGraph(origin: string, key: string) {
  const call = createO11Http(origin, key);
  return new StateGraph(RunState)
    .addNode("dispatch", async (state) => {
      if (state.invocationId) return {};
      const receipt = Receipt.parse(
        await call("invoke", state.approvedRequest),
      );
      return { invocationId: receipt.id, outcome: receipt.state };
    })
    .addNode("inspectExisting", async (state) => {
      if (!state.invocationId) throw new Error("Missing invocation");
      const receipt = Receipt.parse(await call("get_invocation", {
        id: state.invocationId,
      }));
      return { outcome: receipt.state };
    })
    .addEdge(START, "dispatch")
    .addEdge("dispatch", "inspectExisting")
    .addEdge("inspectExisting", END)
    .compile();
}

approvedRequest is intentionally unknown at this illustrative boundary. Your application must validate and persist the actual o11 invocation contract before calling the graph. The server validates it again. The stable key remains necessary even when invocationId is null after a crash between external submission and state persistence.

This graph has no checkpointer configured and is not a production persistence solution. It demonstrates node responsibilities. Add your reviewed persistence backend and task scheduling before relying on restart recovery.

Add persistence with explicit identity

Choose a persistence backend appropriate to your deployment and configure the graph according to its current documentation. Use a stable workflow or thread identity controlled by your application, with authorization checks before access.

LangGraph’s persistence documentation describes checkpointed graph state. Its interrupt documentation also explains pausing and resuming execution and why code around an interrupt can run again. Those behaviors are relevant to external side effects. LangGraph persistence, LangGraph interrupts.

Keep supplier credentials outside checkpointed graph state. Store connection references and approved intent data rather than raw secrets. Be deliberate about what appears in streamed values and logs.

A restart test should confirm that the same intent leads to the same existing invocation. It should not merely confirm that the graph returns some final text. Inspect identifiers and external request counts in a controlled environment.

If your persistence configuration is not ready, stop at local orchestration and contract verification. Do not describe an in-memory demonstration as durable production execution.

Branch on the invocation state

After retrieval, route based on the receipt state. A succeeded invocation can move to output validation. Queued, executing, or waiting work should remain pending. Failed and cancelled work need their own application decisions. Unknown work needs reconciliation rather than automatic replacement.

Avoid a graph edge that sends every non-success back to dispatch. That collapses configuration failure, supplier failure, and uncertainty into repeated purchases. A failure branch should classify the cause and preserve the original invocation.

For long-running jobs, schedule a later status retrieval or wait through a supported event mechanism in your application. Do not repeatedly call the model to ask whether a provider job has completed.

When the supplier succeeds, validate the domain result. A research response without sources may fail your acceptance criteria even though the invocation is complete. Preserve the execution success and the quality rejection as separate facts.

Our asynchronous job guide maps those states into a user-visible lifecycle.

Place human decisions before side effects

If a task needs approval, collect it before dispatching the external operation. Bind it to the exact operation, input, account, and maximum. A graph interrupt can be part of the user experience, but it does not replace server-side authorization.

Keep the approval node separate from the side-effect node where possible. That makes replay behavior easier to reason about. If a node contains both an external call and a later pause, resuming can revisit code whose effects already happened.

LangGraph’s interrupt documentation explains that resumed execution can restart the containing node. Design surrounding side effects to be replay-safe and retain stable external intent identifiers. LangGraph interrupts.

Approvals also need an expiry or recovery route. A waiting task should be cancellable or revisitable by an authorized operator. Avoid a permanent workflow block that leaves no clear way to resume or resolve accepted work.

Scope retries to the failure

A validation failure before dispatch can be corrected with a new reviewed intent. A transient status-read failure can retry retrieval of the existing invocation. An uncertain dispatch needs recovery under the original request key. These are different operations.

Use graph retry policies only where the node’s semantics are understood. Adding a generic retry policy around supplier execution is safe only if the original intent is preserved and the tool service’s deduplication contract is respected.

Keep successful outputs in durable application state. If narration fails after a brief is accepted, resume the narration path rather than rerunning search and drafting. That reduces unnecessary setup and repeat usage without claiming a universal savings figure.

The failure recovery guide provides a practical classification for those node-level decisions.

Verify the graph contract before live execution

Use controlled receipts for queued, succeeded, failed, and unknown states. Check that pending work never becomes a completed artifact and that unknown work never routes to a new purchase. Simulate a restart between submission and graph-state persistence.

Review API shapes against the installed LangGraph version. This article follows the current JavaScript documentation; it does not claim an installed LangGraph build or a live paid supplier run was executed for the article.

When your environment is activated, authorize one bounded operation and retain the graph identity, intent key, invocation identifier, and accepted result. Confirm status recovery before adding more capabilities.

For multiple projects, move the HTTP adapter and domain result validation into a reusable tool layer. Let each graph retain its own ordering, approval flow, and task-specific acceptance rules.

Sources

Give your agents a wallet.
Open up their world.

The paid web, through one simple API.

Get started
Become a partner Sell your product/API to agents using o11.

Keep reading