LangGraph.js
Not in the preview yet. This feature is built in the repository but is off in the v2.2.6 preview (test mode). Do not treat this page as available on a preview core. See ../preview.md and the release notes.
@dynamoprotocol/langgraph adds Dynamo to LangGraph.js (StateGraph, ToolNode, sub-graphs as tools). Every agent gets its own capped slice of one budget. A sub-agent called as a tool runs on a child slice, which can never exceed what its parent has left. A model call that would go over its slice is refused before the provider is called.
The plugin is not published. It is used from a clone of the repository. For LangGraph in Python, see LangChain, LangGraph and Deep Agents.
Install and try it
These are the commands from the plugin README. They build the workspace and run the offline containment demo, which boots a local core and uses a scripted chat model: no provider key, no model called. You need Node 22.12 or later and pnpm 9.
cd "$DYNAMO_REPO"
pwd
pnpm install --frozen-lockfile
pnpm --filter @dynamo/core-host... -r build
pnpm --filter "@dynamoprotocol/langgraph..." build
node packages/plugin-langgraph-js/examples/containment.mjs
Wrap an agent run in a budget
This is packages/plugin-langgraph-js/examples/app/with-dynamo.mjs: a small two-agent graph app with Dynamo added. It needs DYNAMO_CORE_URL and DYNAMO_OWNER_TOKEN set to a running core. make test-plugin-langgraph-js runs it against a local core (test/examples.test.ts).
// SPDX-License-Identifier: Apache-2.0
// A small multi-agent app on LangGraph.js — with Dynamo.
// Runs offline: the scripted model stands in for a real one.
import { AIMessage } from "@langchain/core/messages";
import { END, MessagesAnnotation, START, StateGraph } from "@langchain/langgraph";
import { ToolNode } from "@langchain/langgraph/prebuilt";
import { DynamoLangGraph, usd } from "@dynamoprotocol/langgraph";
import { mockPrices } from "@dynamoprotocol/agents/testing";
import { ScriptedChatModel } from "@dynamoprotocol/langgraph/testing";
const dyn = await DynamoLangGraph.connect({ prices: mockPrices(), cap: usd("5"), mandate: { categories: ["research", "writing"], maxDepth: 3 },
agents: { orchestrator: { slice: usd("2"), category: "writing" }, researcher: { slice: usd("1"), category: "research" } } });
const model = dyn.model(new ScriptedChatModel("mock/scripted-1", { maxTokens: 256 }));
model.script({ kind: "tool", name: "researcher", args: { input: "grid-scale storage" } }, { kind: "say", text: "three sources found" }, { kind: "say", text: "brief written" });
function agentGraph(tools = []) {
const bound = tools.length > 0 ? model.bindTools(tools) : model;
return new StateGraph(MessagesAnnotation)
.addNode("agent", async (state, config) => ({ messages: [await bound.invoke(state.messages, config)] }))
.addNode("tools", new ToolNode(tools))
.addEdge(START, "agent")
.addConditionalEdges("agent", (s) => (s.messages.at(-1) instanceof AIMessage && s.messages.at(-1).tool_calls?.length ? "tools" : END), ["tools", END])
.addEdge("tools", "agent")
.compile();
}
const researcher = agentGraph();
const askResearcher = dyn.agentTool("researcher", researcher, { description: "Ask the researcher" });
const orchestrator = agentGraph([askResearcher]);
const result = await dyn.run("orchestrator", () => orchestrator.invoke({ messages: [{ role: "user", content: "Write a brief on grid-scale storage" }] }));
console.log(result.messages.at(-1).content);
dyn.model(chat, { price })gateschatin place, and every copy bound
from it with bindTools or withConfig. With a real model: dyn.model(new ChatOpenAI({ model: "gpt-6-luna", maxTokens: 1024 }), { price: "openai/gpt-6-luna" }).
dyn.agentTool(key, graph)runsgraphas sub-agentkeyon a
short-lived child slice.
dyn.run(key, fn)runsfn(typicallygraph.invoke(...)) as agentkey.
With a real model, pass your price table instead of mockPrices(), for example prices: "quickstart/dynamo-guard/prices.json", or set DYNAMO_PRICE_TABLE.
What a refusal looks like
A refusal is a native LangChain error (a LangChainError subclass, so LangChainError.isInstance(err) holds): DynamoCapExceeded, DynamoMandateRefused, DynamoRevoked, DynamoUnpricedModel, DynamoFrozen, DynamoStopped, DynamoApprovalPending, DynamoApprovalDenied and DynamoAmendmentRefused. Each carries reason, streamId and headroom.
Other refusals name their reason: a model that sends no completion limit (unbounded), a gated model called outside dyn.run (no_run), and an ungated model in dyn.agentGraph (ungated_model). ToolNode turns a tool's error into a tool message; a Dynamo refusal inside a tool is remembered on the run, the run's next model call is refused without a provider call, and dyn.run raises the refusal.
Funding modes
- Control Mode (Live). A budget the plugin opens itself (
cap) is
always a Control Mode budget: every check runs and no money moves. The quickstart and every test of this plugin use one.
- A funded budget. You can pass an existing stablecoin or credit card
budget by id (budgetId). The plugin does not refuse it, but no test runs the plugin on one. In those modes the core requires signed hops by default, and a child slice opened without its delegator's signature is refused hop_unsigned. Pass hops (a LayerHops from @dynamoprotocol/agents: the delegator's key and each payee's own signed offer) so the plugin signs every hop it opens.
- Real money (Release-gated). A core runs a money mode only when its
operator allows it, and real-money settlement is not released.
Known limits
Read packages/plugin-langgraph-js/KNOWN-LIMITS.md in the repository before you rely on the plugin.