Skip to main content

Agent Builder API

The Agent Builder API provides methods to interact with Agent Builder actions on the server. Each action is a workflow exposed under /agent-builder/:actionId/*. The Builder must be enabled on the server via MastraEditor.builder.enabled, with a valid MASTRA_EE_LICENSE in production.

Getting all actions
Direct link to Getting all actions

Retrieve a record of available Agent Builder actions:

const actions = await mastraClient.getAgentBuilderActions()

Returns a Record<string, WorkflowInfo> keyed by action ID.

Working with a specific action
Direct link to Working with a specific action

Get an instance of a specific action by its ID:

const action = mastraClient.getAgentBuilderAction('create-agent')

Action methods
Direct link to Action methods

details()
Direct link to details

Retrieve metadata about an Agent Builder action:

const info = await action.details()

createRun()
Direct link to createrun

Create a new run for this action and receive a runId. Use the returned id with startActionRun(), stream(), resume(), or observeStream().

const { runId } = await action.createRun()

You can also pass an explicit runId:

const { runId } = await action.createRun({ runId: 'my-run-id' })

startAsync()
Direct link to startasync

Start the action and wait for completion. Returns the final AgentBuilderActionResult with success, applied, branchName, message, validationResults, error, errors, and stepResults.

const result = await action.startAsync({
inputData: { agentName: 'support-bot' },
})

Pass an existing runId as the second argument to start a previously created run:

const { runId } = await action.createRun()
const result = await action.startAsync({ inputData }, runId)

startActionRun()
Direct link to startactionrun

Start an existing run without waiting for completion. Returns { message }.

const { runId } = await action.createRun()
await action.startActionRun({ inputData }, runId)

stream()
Direct link to stream

Start an existing run and stream progress events as a ReadableStream<{ type, payload }>.

const { runId } = await action.createRun()
const stream = await action.stream({ inputData }, runId)

for await (const event of stream) {
console.log(event.type, event.payload)
}

resume()
Direct link to resume

Resume a suspended step on a run. Returns { message }.

await action.resume({ step: 'review', resumeData: { approved: true } }, runId)

resumeAsync()
Direct link to resumeasync

Resume a suspended step and wait for completion. Returns an AgentBuilderActionResult.

const result = await action.resumeAsync({ step: 'review', resumeData: { approved: true } }, runId)

resumeStream()
Direct link to resumestream

Resume a suspended step and stream subsequent events.

const stream = await action.resumeStream({
runId,
step: 'review',
resumeData: { approved: true },
})

observeStream()
Direct link to observestream

Attach to an existing run, replaying cached events from the beginning, then continuing with live events. Use this to recover after a page refresh or hot reload.

const stream = await action.observeStream({ runId })

observeStreamLegacy()
Direct link to observestreamlegacy

Same as observeStream() but uses the legacy streaming endpoint. Prefer observeStream() for new code.

const stream = await action.observeStreamLegacy({ runId })

runs()
Direct link to runs

List runs for this action with optional filters.

const runs = await action.runs({ page: 0, perPage: 20 })

Accepts fromDate, toDate, page, perPage, resourceId, and legacy limit/offset.

runById()
Direct link to runbyid

Fetch a specific run by ID. Use fields to limit the returned payload and withNestedWorkflows to skip nested workflow data.

const run = await action.runById(runId, {
fields: ['result', 'steps'],
withNestedWorkflows: false,
})

cancelRun()
Direct link to cancelrun

Cancel an in-flight run.

await action.cancelRun(runId)

Access control
Direct link to Access control

The /agent-builder/* routes are gated by the agent-builder permission resource. Calling clients need at minimum agent-builder:read and agent-builder:execute, plus any picker resources the action touches (stored-agents, stored-skills, tools, workflows, memory). See Access control for the full grant list.