askUserTool
A built-in, agent-agnostic tool that asks the user a question and waits for their response. The tool supports free-text questions, single-select prompts, and multi-select prompts.
The tool pauses through the native tool suspension primitive: it calls suspend() with the question payload, which makes the agent emit a tool-call-suspended event and persist run state. Resume the run with agent.resumeStream(answer, { runId }).
When executed outside an agent run (no suspend available), the tool returns a readable fallback string containing the question and choices.
Usage exampleDirect link to Usage example
Add askUserTool to an agent's toolset:
import { Agent } from '@mastra/core/agent'
import { askUserTool } from '@mastra/core/tools'
const agent = new Agent({
id: 'assistant',
name: 'Assistant',
instructions: 'Ask the user for clarification when the request is ambiguous.',
model,
tools: { askUserTool },
})
Handle the suspension and resume:
const stream = await agent.stream('Summarize my project')
for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-suspended') {
const { question, options, selectionMode } = chunk.payload.suspendPayload
// Present the question to the user, collect their answer, then resume:
const resumed = await agent.resumeStream('The main repo', { runId: stream.runId })
for await (const c of resumed.textStream) process.stdout.write(c)
}
}
For multi-select prompts, resume with a string array:
await agent.resumeStream(['Add tests', 'Update docs'], { runId: stream.runId })
Input schemaDirect link to Input schema
The model calls this tool with the following parameters:
question:
options?:
label:
description?:
selectionMode?:
Suspend payloadDirect link to Suspend payload
The tool-call-suspended event carries a suspendPayload with the same shape as the input:
question:
options?:
selectionMode?:
Resume dataDirect link to Resume data
Pass the user's answer to agent.resumeStream():
- Free-text and single-select: A
string. - Multi-select: A
string[]of selected option labels.