M
Mastra•4w ago
Boragorn

chatRoute + useChat not working for tool suspension in @mastra/ai-sdk@beta

When using chatRoute with @ai-sdk useChat hook, tool suspension events (tool-call-suspended) are not emitted, causing the frontend to never receive them. This makes HITL (Human-in-the-Loop) flows impossible with the chatRoute + useChat combination. I'm using the same example of conditional approvals by calling the suspend function within the tool execution. It works in the playground-ui but it doesn't work with ai-sdk. Reference: https://mastra.ai/blog/tool-approval#conditional-approvals chatRoute Stream Output
data: {"type":"start","messageId":"..."}
data: {"type":"start-step"}
data: {"type":"tool-input-start","toolCallId":"....","toolName
":"myTool","dynamic":false}
data: {"type":"tool-input-delta","toolCallId":"...","inputTex
tDelta":"{}"}
data: {"type":"tool-input-available","toolCallId":"...","tool
Name":"myTool","input":{},"providerMetadata":{...}}
data: [DONE]
data: {"type":"start","messageId":"..."}
data: {"type":"start-step"}
data: {"type":"tool-input-start","toolCallId":"....","toolName
":"myTool","dynamic":false}
data: {"type":"tool-input-delta","toolCallId":"...","inputTex
tDelta":"{}"}
data: {"type":"tool-input-available","toolCallId":"...","tool
Name":"myTool","input":{},"providerMetadata":{...}}
data: [DONE]
POST /api/agents/.../stream Stream Output
data: {"type":"start","runId":"agent","from":"AGENT","payload":{"id":"agent"}}

data: {"runId":"agent","from":"AGENT","type":"step-start","payload":{...}}

data: {"type":"tool-call-input-streaming-start","runId":"agent","from":"AGENT","payload":{"toolCallId":"...","toolName":"myTool"}}

data: {"type":"tool-call-delta","runId":"agent","from":"AGENT","payload":{"argsTextDelta":"{}","toolCallId":"...","toolName":"myTool"}}

data: {"type":"tool-call-input-streaming-end","runId":"agent","from":"AGENT","payload":{"toolCallId":"..."}}

data: {"type":"tool-call","runId":"agent","from":"AGENT","payload":{"toolCallId":"...","toolName":"myTool","args":{},"providerMetadata":{...}}}

data: {"type":"tool-call-suspended","runId":"agent","from":"AGENT","payload":{"toolCallId":"...","toolName":"myTool","suspendPayload":{...}}}
data: {"type":"start","runId":"agent","from":"AGENT","payload":{"id":"agent"}}

data: {"runId":"agent","from":"AGENT","type":"step-start","payload":{...}}

data: {"type":"tool-call-input-streaming-start","runId":"agent","from":"AGENT","payload":{"toolCallId":"...","toolName":"myTool"}}

data: {"type":"tool-call-delta","runId":"agent","from":"AGENT","payload":{"argsTextDelta":"{}","toolCallId":"...","toolName":"myTool"}}

data: {"type":"tool-call-input-streaming-end","runId":"agent","from":"AGENT","payload":{"toolCallId":"..."}}

data: {"type":"tool-call","runId":"agent","from":"AGENT","payload":{"toolCallId":"...","toolName":"myTool","args":{},"providerMetadata":{...}}}

data: {"type":"tool-call-suspended","runId":"agent","from":"AGENT","payload":{"toolCallId":"...","toolName":"myTool","suspendPayload":{...}}}
HITL: Ask Before Acting
Learn how to use HITL (Human-in-the-Loop) to safely build tools that require human approval.
1 Reply
Mastra Triager
Mastra Triager•4w ago
šŸ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10173 šŸ” If you're experiencing an error, please provide a minimal reproducible example to help us resolve it quickly. šŸ™ Thank you @Boragorn for helping us improve Mastra!

Did you find this page helpful?