Vercel AI SDK
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/ai-sdk adds Dynamo to the Vercel AI SDK (generateText, streamText, ToolLoopAgent). 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.
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 the AI SDK's own MockLanguageModelV4: 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/ai-sdk..." build
node packages/plugin-ai-sdk/examples/containment.mjs
Wrap an agent run in a budget
This is packages/plugin-ai-sdk/examples/app/with-dynamo.mjs: a small two-agent app with Dynamo added. It needs DYNAMO_CORE_URL and DYNAMO_OWNER_TOKEN set to a running core. No test runs this file; make test-plugin-ai-sdk tests the plugin itself (the middleware tests and the nine shared per-call conformance scenarios against a local core).
// SPDX-License-Identifier: Apache-2.0
// A small multi-agent app on the Vercel AI SDK — with Dynamo.
// Runs offline: the scripted model stands in for a real one.
import { ToolLoopAgent } from "ai";
import { DynamoAISDK, usd } from "@dynamoprotocol/ai-sdk";
import { mockPrices } from "@dynamoprotocol/agents/testing";
import { ScriptedLanguageModel } from "@dynamoprotocol/ai-sdk/testing";
const dyn = await DynamoAISDK.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 scripted = new ScriptedLanguageModel("mock/scripted-1");
scripted.script({ kind: "tool", name: "researcher", args: { input: "grid-scale storage" } }, { kind: "say", text: "three sources found" }, { kind: "say", text: "brief written" });
const model = dyn.model(scripted.model);
const researcher = new ToolLoopAgent({ model, instructions: "You research.", maxOutputTokens: 256 });
const askResearcher = dyn.agentTool("researcher", researcher, { description: "Ask the researcher" });
const orchestrator = new ToolLoopAgent({ model, instructions: "You write briefs.", tools: { researcher: askResearcher }, maxOutputTokens: 256 });
const result = await dyn.run("orchestrator", () => orchestrator.generate({ prompt: "Write a brief on grid-scale storage" }));
console.log(result.text);
dyn.model(model, { price })wraps a language model with Dynamo's
middleware. With a real model: dyn.model(openai("gpt-6-luna"), { price: "openai/gpt-6-luna" }).
dyn.run(key, fn)runsfnas agentkey. A gated model called outside
dyn.run is refused.
dyn.agentTool(key, agent)runsagentas sub-agentkeyon a
short-lived child slice.
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 AI SDK error (an AISDKError subclass, so AISDKError.isInstance(err) holds): DynamoCapExceeded, DynamoMandateRefused, DynamoRevoked, DynamoUnpricedModel, DynamoFrozen, DynamoStopped, DynamoApprovalPending, DynamoApprovalDenied and DynamoAmendmentRefused. Each carries reason, streamId and headroom.
The AI SDK turns a tool's error into a tool result for the model. 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-ai-sdk/KNOWN-LIMITS.md in the repository before you rely on the plugin.