Mastra
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/mastra adds Dynamo to Mastra agents (Agent.generate, Agent.stream, agents 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.
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 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/mastra..." build
node packages/plugin-mastra/examples/containment.mjs
Wrap an agent run in a budget
This is packages/plugin-mastra/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. make test-plugin-mastra runs it against a local core (test/examples.test.ts).
// SPDX-License-Identifier: Apache-2.0
// A small multi-agent app on Mastra — with Dynamo.
// Runs offline: the scripted model stands in for a real one.
import { DynamoMastra, usd } from "@dynamoprotocol/mastra";
import { mockPrices } from "@dynamoprotocol/agents/testing";
import { ScriptedLanguageModel } from "@dynamoprotocol/mastra/testing";
const dyn = await DynamoMastra.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 = scripted.model;
const defaultOptions = { modelSettings: { maxOutputTokens: 256 } };
const researcher = dyn.agent({ id: "researcher", name: "researcher", instructions: "You research.", model, defaultOptions });
const askResearcher = dyn.agentTool("researcher", researcher, { description: "Ask the researcher" });
const orchestrator = dyn.agent({ id: "orchestrator", name: "orchestrator", instructions: "You write briefs.", model, tools: { researcher: askResearcher }, defaultOptions });
const result = await dyn.run("orchestrator", () => orchestrator.generate("Write a brief on grid-scale storage"));
console.log(result.text);
dyn.agent(config, { price })builds a MastraAgentwith Dynamo's gate
processor. The agent's id names its slice.
dyn.agentTool(key, agent)runsagentas sub-agentkeyon a
short-lived child slice.
dyn.run(key, fn)runsfnas 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) and, if the provider's model id is not a row name, name the row: dyn.agent(config, { price: "openai/gpt-6-luna" }).
What a refusal looks like
A refusal is a native Mastra error (a MastraError subclass, domain AGENT, category USER, ids such as DYNAMO_CAP_EXCEEDED): DynamoCapExceeded, DynamoMandateRefused, DynamoRevoked, DynamoUnpricedModel, DynamoFrozen, DynamoStopped, DynamoApprovalPending, DynamoApprovalDenied and DynamoAmendmentRefused. Each carries reason, streamId, headroom and the agents-layer layerError.
Other refusals name their reason: a gated agent called outside dyn.run (no_run), a gated agent called directly inside another agent's run (agent_mismatch), a sub-agent not built with dyn.agent (ungated_agent), and a call with no completion limit (unbounded). 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-mastra/KNOWN-LIMITS.md in the repository before you rely on the plugin.