@mastra/mcp-docs-server 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/.docs/docs/agents/adding-voice.md +18 -17
  2. package/.docs/docs/agents/background-tasks.md +242 -0
  3. package/.docs/docs/agents/channels.md +2 -1
  4. package/.docs/docs/agents/overview.md +4 -0
  5. package/.docs/docs/agents/processors.md +177 -5
  6. package/.docs/docs/agents/structured-output.md +66 -1
  7. package/.docs/docs/agents/supervisor-agents.md +65 -0
  8. package/.docs/docs/agents/using-tools.md +73 -0
  9. package/.docs/docs/browser/agent-browser.md +78 -0
  10. package/.docs/docs/browser/browser-viewer.md +144 -0
  11. package/.docs/docs/browser/overview.md +168 -0
  12. package/.docs/docs/browser/stagehand.md +129 -0
  13. package/.docs/docs/deployment/cloud-providers.md +5 -1
  14. package/.docs/docs/deployment/mastra-server.md +4 -4
  15. package/.docs/docs/deployment/monorepo.md +3 -3
  16. package/.docs/docs/deployment/overview.md +11 -8
  17. package/.docs/docs/editor/overview.md +290 -0
  18. package/.docs/docs/editor/prompts.md +134 -0
  19. package/.docs/docs/editor/tools.md +152 -0
  20. package/.docs/docs/evals/custom-scorers.md +63 -3
  21. package/.docs/docs/evals/datasets/overview.md +1 -1
  22. package/.docs/docs/index.md +2 -2
  23. package/.docs/docs/mastra-platform/configuration.md +36 -0
  24. package/.docs/docs/mastra-platform/overview.md +78 -0
  25. package/.docs/docs/mcp/overview.md +17 -0
  26. package/.docs/docs/memory/memory-processors.md +3 -3
  27. package/.docs/docs/memory/message-history.md +8 -2
  28. package/.docs/docs/memory/observational-memory.md +65 -8
  29. package/.docs/docs/memory/storage.md +1 -2
  30. package/.docs/docs/memory/working-memory.md +2 -2
  31. package/.docs/docs/observability/logging.md +1 -1
  32. package/.docs/docs/observability/metrics/overview.md +2 -2
  33. package/.docs/docs/observability/overview.md +1 -1
  34. package/.docs/docs/observability/tracing/bridges/datadog.md +217 -0
  35. package/.docs/docs/observability/tracing/bridges/otel.md +2 -2
  36. package/.docs/docs/observability/tracing/exporters/arthur.md +163 -0
  37. package/.docs/docs/observability/tracing/exporters/cloud.md +135 -63
  38. package/.docs/docs/observability/tracing/exporters/datadog.md +3 -1
  39. package/.docs/docs/observability/tracing/exporters/default.md +5 -5
  40. package/.docs/docs/observability/tracing/exporters/laminar.md +22 -14
  41. package/.docs/docs/observability/tracing/exporters/langfuse.md +50 -33
  42. package/.docs/docs/observability/tracing/overview.md +87 -20
  43. package/.docs/docs/server/custom-adapters.md +5 -5
  44. package/.docs/docs/server/custom-api-routes.md +3 -3
  45. package/.docs/docs/server/mastra-client.md +2 -2
  46. package/.docs/docs/server/mastra-server.md +1 -1
  47. package/.docs/docs/server/middleware.md +46 -42
  48. package/.docs/docs/server/request-context.md +13 -2
  49. package/.docs/docs/server/server-adapters.md +91 -8
  50. package/.docs/docs/streaming/background-task-streaming.md +80 -0
  51. package/.docs/docs/streaming/overview.md +3 -0
  52. package/.docs/docs/studio/deployment.md +24 -6
  53. package/.docs/docs/studio/observability.md +1 -1
  54. package/.docs/docs/studio/overview.md +4 -4
  55. package/.docs/docs/voice/overview.md +74 -5
  56. package/.docs/docs/voice/speech-to-speech.md +45 -1
  57. package/.docs/docs/voice/speech-to-text.md +7 -7
  58. package/.docs/docs/voice/text-to-speech.md +10 -10
  59. package/.docs/docs/workflows/agents-and-tools.md +1 -1
  60. package/.docs/docs/workflows/overview.md +105 -4
  61. package/.docs/docs/workflows/scheduled-workflows.md +181 -0
  62. package/.docs/docs/workspace/filesystem.md +64 -6
  63. package/.docs/docs/workspace/lsp.md +76 -4
  64. package/.docs/docs/workspace/overview.md +62 -15
  65. package/.docs/docs/workspace/sandbox.md +3 -1
  66. package/.docs/docs/workspace/search.md +41 -2
  67. package/.docs/docs/workspace/skills.md +19 -19
  68. package/.docs/guides/agent-frameworks/ai-sdk.md +4 -4
  69. package/.docs/guides/build-your-ui/ai-sdk-ui.md +56 -9
  70. package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
  71. package/.docs/guides/deployment/mastra-platform.md +191 -0
  72. package/.docs/guides/deployment/netlify.md +16 -1
  73. package/.docs/guides/getting-started/nestjs.md +238 -0
  74. package/.docs/guides/getting-started/next-js.md +0 -4
  75. package/.docs/guides/guide/code-review-bot.md +2 -2
  76. package/.docs/guides/guide/dev-assistant.md +4 -4
  77. package/.docs/{docs/mcp → guides/guide}/publishing-mcp-server.md +21 -1
  78. package/.docs/guides/guide/slack-assistant.md +191 -0
  79. package/.docs/guides/migrations/mastra-cloud.md +368 -0
  80. package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
  81. package/.docs/models/embeddings.md +3 -3
  82. package/.docs/models/gateways/azure-openai.md +74 -35
  83. package/.docs/models/gateways/mastra.md +64 -0
  84. package/.docs/models/gateways/netlify.md +7 -3
  85. package/.docs/models/gateways/openrouter.md +28 -12
  86. package/.docs/models/gateways/vercel.md +22 -2
  87. package/.docs/models/gateways.md +1 -0
  88. package/.docs/models/index.md +43 -8
  89. package/.docs/models/providers/302ai.md +37 -4
  90. package/.docs/models/providers/abliteration-ai.md +71 -0
  91. package/.docs/models/providers/alibaba-cn.md +8 -2
  92. package/.docs/models/providers/alibaba-coding-plan-cn.md +3 -2
  93. package/.docs/models/providers/alibaba-coding-plan.md +3 -2
  94. package/.docs/models/providers/alibaba.md +8 -1
  95. package/.docs/models/providers/anthropic.md +18 -5
  96. package/.docs/models/providers/baseten.md +3 -1
  97. package/.docs/models/providers/berget.md +10 -12
  98. package/.docs/models/providers/chutes.md +4 -2
  99. package/.docs/models/providers/cloudflare-workers-ai.md +14 -48
  100. package/.docs/models/providers/cortecs.md +22 -2
  101. package/.docs/models/providers/deepinfra.md +8 -2
  102. package/.docs/models/providers/deepseek.md +6 -4
  103. package/.docs/models/providers/digitalocean.md +133 -0
  104. package/.docs/models/providers/fireworks-ai.md +6 -1
  105. package/.docs/models/providers/firmware.md +12 -10
  106. package/.docs/models/providers/friendli.md +6 -7
  107. package/.docs/models/providers/google.md +9 -3
  108. package/.docs/models/providers/helicone.md +1 -2
  109. package/.docs/models/providers/hpc-ai.md +73 -0
  110. package/.docs/models/providers/huggingface.md +6 -2
  111. package/.docs/models/providers/inception.md +9 -11
  112. package/.docs/models/providers/kilo.md +359 -339
  113. package/.docs/models/providers/kimi-for-coding.md +2 -1
  114. package/.docs/models/providers/llmgateway.md +67 -77
  115. package/.docs/models/providers/mistral.md +3 -2
  116. package/.docs/models/providers/mixlayer.md +75 -0
  117. package/.docs/models/providers/moonshotai-cn.md +3 -2
  118. package/.docs/models/providers/moonshotai.md +3 -2
  119. package/.docs/models/providers/nano-gpt.md +8 -2
  120. package/.docs/models/providers/neuralwatt.md +84 -0
  121. package/.docs/models/providers/novita-ai.md +19 -4
  122. package/.docs/models/providers/nvidia.md +8 -1
  123. package/.docs/models/providers/ollama-cloud.md +7 -2
  124. package/.docs/models/providers/openai.md +7 -2
  125. package/.docs/models/providers/opencode-go.md +21 -13
  126. package/.docs/models/providers/opencode.md +11 -4
  127. package/.docs/models/providers/ovhcloud.md +6 -8
  128. package/.docs/models/providers/poe.md +10 -15
  129. package/.docs/models/providers/regolo-ai.md +83 -0
  130. package/.docs/models/providers/siliconflow-cn.md +5 -2
  131. package/.docs/models/providers/siliconflow.md +6 -3
  132. package/.docs/models/providers/stepfun.md +8 -7
  133. package/.docs/models/providers/synthetic.md +5 -2
  134. package/.docs/models/providers/tencent-token-plan.md +71 -0
  135. package/.docs/models/providers/tencent-tokenhub.md +71 -0
  136. package/.docs/models/providers/togetherai.md +8 -7
  137. package/.docs/models/providers/vivgrid.md +7 -3
  138. package/.docs/models/providers/vultr.md +7 -6
  139. package/.docs/models/providers/wafer.ai.md +73 -0
  140. package/.docs/models/providers/wandb.md +3 -2
  141. package/.docs/models/providers/xai.md +6 -1
  142. package/.docs/models/providers/xiaomi-token-plan-ams.md +75 -0
  143. package/.docs/models/providers/xiaomi-token-plan-cn.md +75 -0
  144. package/.docs/models/providers/xiaomi-token-plan-sgp.md +75 -0
  145. package/.docs/models/providers/xiaomi.md +4 -2
  146. package/.docs/models/providers/zai-coding-plan.md +11 -19
  147. package/.docs/models/providers/zai.md +2 -1
  148. package/.docs/models/providers/zenmux.md +17 -6
  149. package/.docs/models/providers/zhipuai-coding-plan.md +11 -21
  150. package/.docs/models/providers/zhipuai.md +2 -1
  151. package/.docs/models/providers.md +11 -0
  152. package/.docs/reference/agents/agent.md +1 -1
  153. package/.docs/reference/agents/channels.md +3 -3
  154. package/.docs/reference/agents/generate.md +88 -6
  155. package/.docs/reference/agents/generateLegacy.md +1 -1
  156. package/.docs/reference/ai-sdk/chat-route.md +2 -0
  157. package/.docs/reference/ai-sdk/handle-chat-stream.md +19 -0
  158. package/.docs/reference/ai-sdk/handle-network-stream.md +2 -0
  159. package/.docs/reference/ai-sdk/network-route.md +2 -0
  160. package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +95 -0
  161. package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +15 -0
  162. package/.docs/reference/browser/agent-browser.md +375 -0
  163. package/.docs/reference/browser/browser-viewer.md +228 -0
  164. package/.docs/reference/browser/mastra-browser.md +286 -0
  165. package/.docs/reference/browser/stagehand-browser.md +286 -0
  166. package/.docs/reference/cli/mastra.md +703 -0
  167. package/.docs/reference/client-js/agents.md +166 -0
  168. package/.docs/reference/client-js/conversations.md +1 -1
  169. package/.docs/reference/client-js/mastra-client.md +23 -0
  170. package/.docs/reference/client-js/observability.md +2 -2
  171. package/.docs/reference/client-js/responses.md +1 -1
  172. package/.docs/reference/client-js/workflows.md +62 -1
  173. package/.docs/reference/configuration.md +67 -1
  174. package/.docs/reference/core/addGateway.md +5 -5
  175. package/.docs/reference/core/getEditor.md +35 -0
  176. package/.docs/reference/core/getGateway.md +5 -5
  177. package/.docs/reference/core/getGatewayById.md +5 -5
  178. package/.docs/reference/core/getMCPServer.md +2 -2
  179. package/.docs/reference/core/getMCPServerById.md +2 -2
  180. package/.docs/reference/core/getScorer.md +3 -3
  181. package/.docs/reference/core/getScorerById.md +3 -3
  182. package/.docs/reference/core/listGateways.md +5 -5
  183. package/.docs/reference/core/listMCPServers.md +2 -2
  184. package/.docs/reference/core/listScorers.md +3 -3
  185. package/.docs/reference/core/mastra-class.md +11 -1
  186. package/.docs/reference/core/mastra-model-gateway.md +5 -5
  187. package/.docs/reference/datasets/create.md +4 -4
  188. package/.docs/reference/datasets/startExperiment.md +28 -2
  189. package/.docs/reference/datasets/update.md +4 -4
  190. package/.docs/reference/deployer/cloudflare.md +14 -1
  191. package/.docs/reference/deployer/netlify.md +50 -2
  192. package/.docs/reference/editor/mastra-editor.md +168 -0
  193. package/.docs/reference/editor/tool-provider.md +85 -0
  194. package/.docs/reference/evals/context-precision.md +3 -3
  195. package/.docs/reference/evals/context-relevance.md +3 -3
  196. package/.docs/reference/evals/create-scorer.md +5 -3
  197. package/.docs/reference/evals/filter-run.md +117 -0
  198. package/.docs/reference/evals/mastra-scorer.md +4 -4
  199. package/.docs/reference/evals/noise-sensitivity.md +6 -6
  200. package/.docs/reference/evals/prompt-alignment.md +12 -12
  201. package/.docs/reference/evals/run-evals.md +6 -6
  202. package/.docs/reference/evals/scorer-utils.md +3 -3
  203. package/.docs/reference/evals/trajectory-accuracy.md +3 -3
  204. package/.docs/reference/harness/harness-class.md +152 -53
  205. package/.docs/reference/index.md +25 -0
  206. package/.docs/reference/logging/pino-logger.md +0 -2
  207. package/.docs/reference/mastra-platform/api.md +108 -0
  208. package/.docs/reference/memory/clone-utilities.md +4 -2
  209. package/.docs/reference/memory/cloneThread.md +4 -2
  210. package/.docs/reference/memory/observational-memory.md +4 -0
  211. package/.docs/reference/observability/metrics/automatic-metrics.md +3 -3
  212. package/.docs/reference/observability/tracing/bridges/datadog.md +211 -0
  213. package/.docs/reference/observability/tracing/bridges/otel.md +3 -3
  214. package/.docs/reference/observability/tracing/configuration.md +18 -11
  215. package/.docs/reference/observability/tracing/exporters/arthur.md +122 -0
  216. package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +102 -21
  217. package/.docs/reference/observability/tracing/exporters/console-exporter.md +8 -8
  218. package/.docs/reference/observability/tracing/exporters/datadog.md +3 -1
  219. package/.docs/reference/observability/tracing/exporters/default-exporter.md +8 -8
  220. package/.docs/reference/observability/tracing/exporters/langfuse.md +25 -32
  221. package/.docs/reference/observability/tracing/exporters/otel.md +3 -3
  222. package/.docs/reference/observability/tracing/instances.md +7 -7
  223. package/.docs/reference/observability/tracing/interfaces.md +23 -6
  224. package/.docs/reference/observability/tracing/span-filtering.md +95 -0
  225. package/.docs/reference/observability/tracing/spans.md +6 -6
  226. package/.docs/reference/processors/prefill-error-handler.md +70 -0
  227. package/.docs/reference/processors/processor-interface.md +400 -40
  228. package/.docs/reference/processors/skill-search-processor.md +20 -1
  229. package/.docs/reference/processors/stream-error-retry-processor.md +54 -0
  230. package/.docs/reference/processors/tool-call-filter.md +23 -0
  231. package/.docs/reference/server/create-route.md +3 -3
  232. package/.docs/reference/server/express-adapter.md +4 -4
  233. package/.docs/reference/server/fastify-adapter.md +4 -4
  234. package/.docs/reference/server/hono-adapter.md +4 -4
  235. package/.docs/reference/server/koa-adapter.md +4 -4
  236. package/.docs/reference/server/mastra-server.md +3 -3
  237. package/.docs/reference/server/nestjs-adapter.md +169 -0
  238. package/.docs/reference/server/register-api-route.md +4 -4
  239. package/.docs/reference/server/routes.md +11 -10
  240. package/.docs/reference/storage/clickhouse.md +300 -0
  241. package/.docs/reference/storage/cloudflare-d1.md +42 -42
  242. package/.docs/reference/storage/composite.md +5 -3
  243. package/.docs/reference/storage/duckdb.md +150 -0
  244. package/.docs/reference/storage/overview.md +1 -1
  245. package/.docs/reference/storage/redis.md +266 -0
  246. package/.docs/reference/streaming/ChunkType.md +143 -3
  247. package/.docs/reference/streaming/agents/MastraModelOutput.md +2 -2
  248. package/.docs/reference/streaming/agents/stream.md +10 -2
  249. package/.docs/reference/streaming/agents/streamUntilIdle.md +94 -0
  250. package/.docs/reference/streaming/workflows/resumeStream.md +2 -0
  251. package/.docs/reference/templates/overview.md +88 -14
  252. package/.docs/reference/tools/create-tool.md +107 -5
  253. package/.docs/reference/tools/mcp-client.md +45 -0
  254. package/.docs/reference/tools/mcp-server.md +1 -3
  255. package/.docs/reference/tools/perplexity.md +155 -0
  256. package/.docs/reference/tools/tavily.md +307 -0
  257. package/.docs/reference/vectors/mongodb.md +0 -2
  258. package/.docs/reference/voice/aws-nova-sonic.md +247 -0
  259. package/.docs/reference/voice/cloudflare.md +3 -3
  260. package/.docs/reference/voice/sarvam.md +29 -23
  261. package/.docs/reference/voice/voice.connect.md +4 -4
  262. package/.docs/reference/voice/voice.listen.md +3 -3
  263. package/.docs/reference/workflows/run-methods/resume.md +24 -0
  264. package/.docs/reference/workflows/run-methods/startAsync.md +1 -1
  265. package/.docs/reference/workflows/step.md +88 -7
  266. package/.docs/reference/workflows/workflow-methods/foreach.md +14 -1
  267. package/.docs/reference/workflows/workflow.md +88 -4
  268. package/.docs/reference/workspace/azure-blob-filesystem.md +219 -0
  269. package/.docs/reference/workspace/docker-sandbox.md +196 -0
  270. package/.docs/reference/workspace/gcs-filesystem.md +1 -0
  271. package/.docs/reference/workspace/google-drive-filesystem.md +185 -0
  272. package/.docs/reference/workspace/modal-sandbox.md +168 -0
  273. package/.docs/reference/workspace/process-manager.md +1 -1
  274. package/.docs/reference/workspace/s3-filesystem.md +80 -5
  275. package/.docs/reference/workspace/vercel.md +1 -1
  276. package/.docs/reference/workspace/workspace-class.md +37 -6
  277. package/CHANGELOG.md +500 -4
  278. package/dist/stdio.js.map +1 -1
  279. package/dist/utils.d.ts +1 -4
  280. package/dist/utils.d.ts.map +1 -1
  281. package/package.json +11 -11
  282. package/.docs/docs/mastra-cloud/deployment.md +0 -77
  283. package/.docs/docs/mastra-cloud/observability.md +0 -38
  284. package/.docs/docs/mastra-cloud/overview.md +0 -23
  285. package/.docs/docs/mastra-cloud/setup.md +0 -42
@@ -327,23 +327,24 @@ For the complete list of supported AI SDK providers and their capabilities:
327
327
 
328
328
  Mastra supports multiple voice providers for text-to-speech (TTS) and speech-to-text (STT) capabilities:
329
329
 
330
- | Provider | Package | Features | Reference |
331
- | --------------- | ------------------------------- | ------------------------- | ------------------------------------------------------------------ |
332
- | OpenAI | `@mastra/voice-openai` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/openai) |
333
- | OpenAI Realtime | `@mastra/voice-openai-realtime` | Realtime speech-to-speech | [Documentation](https://mastra.ai/reference/voice/openai-realtime) |
334
- | ElevenLabs | `@mastra/voice-elevenlabs` | High-quality TTS | [Documentation](https://mastra.ai/reference/voice/elevenlabs) |
335
- | PlayAI | `@mastra/voice-playai` | TTS | [Documentation](https://mastra.ai/reference/voice/playai) |
336
- | Google | `@mastra/voice-google` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/google) |
337
- | Deepgram | `@mastra/voice-deepgram` | STT | [Documentation](https://mastra.ai/reference/voice/deepgram) |
338
- | Murf | `@mastra/voice-murf` | TTS | [Documentation](https://mastra.ai/reference/voice/murf) |
339
- | Speechify | `@mastra/voice-speechify` | TTS | [Documentation](https://mastra.ai/reference/voice/speechify) |
340
- | Sarvam | `@mastra/voice-sarvam` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/sarvam) |
341
- | Azure | `@mastra/voice-azure` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
342
- | Cloudflare | `@mastra/voice-cloudflare` | TTS | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
330
+ | Provider | Package | Features | Reference |
331
+ | --------------- | ------------------------------- | ----------------------------------------- | ------------------------------------------------------------------ |
332
+ | OpenAI | `@mastra/voice-openai` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/openai) |
333
+ | OpenAI Realtime | `@mastra/voice-openai-realtime` | Realtime speech-to-speech | [Documentation](https://mastra.ai/reference/voice/openai-realtime) |
334
+ | AWS Nova Sonic | `@mastra/voice-aws-nova-sonic` | Realtime speech-to-speech via AWS Bedrock | [Documentation](https://mastra.ai/reference/voice/aws-nova-sonic) |
335
+ | ElevenLabs | `@mastra/voice-elevenlabs` | High-quality TTS | [Documentation](https://mastra.ai/reference/voice/elevenlabs) |
336
+ | PlayAI | `@mastra/voice-playai` | TTS | [Documentation](https://mastra.ai/reference/voice/playai) |
337
+ | Google | `@mastra/voice-google` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/google) |
338
+ | Deepgram | `@mastra/voice-deepgram` | STT | [Documentation](https://mastra.ai/reference/voice/deepgram) |
339
+ | Murf | `@mastra/voice-murf` | TTS | [Documentation](https://mastra.ai/reference/voice/murf) |
340
+ | Speechify | `@mastra/voice-speechify` | TTS | [Documentation](https://mastra.ai/reference/voice/speechify) |
341
+ | Sarvam | `@mastra/voice-sarvam` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/sarvam) |
342
+ | Azure | `@mastra/voice-azure` | TTS, STT | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
343
+ | Cloudflare | `@mastra/voice-cloudflare` | TTS | [Documentation](https://mastra.ai/reference/voice/mastra-voice) |
343
344
 
344
345
  ## Next steps
345
346
 
346
- - [Voice API Reference](https://mastra.ai/reference/voice/mastra-voice) - Detailed API documentation for voice capabilities
347
- - [Text to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/text-to-speech) - Interactive story generator and other TTS implementations
348
- - [Speech to Text Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-text) - Voice memo app and other STT implementations
349
- - [Speech to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-speech) - Real-time voice conversation with call analysis
347
+ - [Voice API Reference](https://mastra.ai/reference/voice/mastra-voice): Detailed API documentation for voice capabilities
348
+ - [Text to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/text-to-speech): Interactive story generator and other TTS implementations
349
+ - [Speech to Text Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-text): Voice memo app and other STT implementations
350
+ - [Speech to Speech Examples](https://github.com/mastra-ai/voice-examples/tree/main/speech-to-speech): Real-time voice conversation with call analysis
@@ -0,0 +1,242 @@
1
+ # Background tasks
2
+
3
+ **Added in:** `@mastra/core@1.29.0`
4
+
5
+ Background tasks let an agent dispatch a long-running tool call without blocking the agentic loop. The tool returns an immediate acknowledgement, the LLM continues responding, and the task runs to completion in the background. When it finishes, its result is written to memory and if you use [`streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) the agent is re-invoked automatically so the result is processed in the same call.
6
+
7
+ ## When to use background tasks
8
+
9
+ Use background tasks when a tool call may take long enough that the user shouldn't wait for it before seeing a response. Common cases:
10
+
11
+ - Subagent delegations that themselves run multi-step research or writing.
12
+ - Tool calls that hit slow external services, queues, or large data jobs.
13
+ - Workflows triggered from a tool call that may take minutes to complete.
14
+
15
+ For tool calls that return quickly, foreground execution using `agent.stream()` and `agent.generate()` is simpler.
16
+
17
+ > **Note:** Background tasks require a configured [storage](https://mastra.ai/docs/memory/storage) backend on the Mastra instance. Tasks are persisted so they survive process restarts.
18
+
19
+ ## Quickstart
20
+
21
+ Background tasks are off by default. Enable them by setting `backgroundTasks.enabled` on the Mastra instance:
22
+
23
+ ```typescript
24
+ import { Mastra } from '@mastra/core'
25
+ import { LibSQLStore } from '@mastra/libsql'
26
+
27
+ export const mastra = new Mastra({
28
+ storage: new LibSQLStore({ id: 'storage', url: 'file:mastra.db' }),
29
+ backgroundTasks: {
30
+ enabled: true,
31
+ globalConcurrency: 10,
32
+ perAgentConcurrency: 5,
33
+ backpressure: 'queue',
34
+ defaultTimeoutMs: 300_000,
35
+ },
36
+ })
37
+ ```
38
+
39
+ The full set of options is listed in the [backgroundTasks configuration reference](https://mastra.ai/reference/configuration).
40
+
41
+ ## Run a tool in the background
42
+
43
+ Enabling the manager doesn't run anything in the background by itself as every tool defaults to foreground execution. You can run a tool in the background at one of three layers, in priority order:
44
+
45
+ 1. **LLM per-call override**: the model decides it should run in the background and includes a `_background` field in the tool arguments.
46
+ 2. **Agent-level config**: the agent declares which of its tools are background-eligible.
47
+ 3. **Tool-level config**: the tool itself declares it as background-eligible.
48
+
49
+ ### Tool-level
50
+
51
+ Set `backgroundTasks.enabled: true` on the tool definition. Tools opted in at this layer run in the background whenever called by an agent that has the manager enabled.
52
+
53
+ ```typescript
54
+ import { createTool } from '@mastra/core/tools'
55
+ import { z } from 'zod'
56
+
57
+ export const researchTool = createTool({
58
+ id: 'research',
59
+ description: 'Run a long research job',
60
+ inputSchema: z.object({ topic: z.string() }),
61
+ backgroundTasks: {
62
+ enabled: true,
63
+ timeoutMs: 600_000,
64
+ maxRetries: 1,
65
+ },
66
+ execute: async ({ context }) => {
67
+ // ...
68
+ },
69
+ })
70
+ ```
71
+
72
+ ### Agent-level
73
+
74
+ Use `backgroundTasks.tools` on the agent to opt in specific tools, override timeouts for individual tools, or run all background-eligible tools in the background. Use `disabled: true` to short-circuit background dispatch for the agent entirely.
75
+
76
+ ```typescript
77
+ import { Agent } from '@mastra/core/agent'
78
+
79
+ export const researcher = new Agent({
80
+ id: 'researcher',
81
+ instructions: 'You research topics and answer questions.',
82
+ model: 'openai/gpt-5.4',
83
+ tools: { researchTool, summarizeTool },
84
+ backgroundTasks: {
85
+ tools: {
86
+ researchTool: { enabled: true, timeoutMs: 600_000 },
87
+ summarizeTool: false,
88
+ },
89
+ },
90
+ })
91
+ ```
92
+
93
+ Set `tools: 'all'` to opt in every tool the agent has.
94
+
95
+ ### LLM per-call override
96
+
97
+ When a tool is registered on an agent that has background tasks enabled, the model can include a `_background` field in the tool arguments to override the resolved configuration for that specific call. The model only includes what it wants to override, all fields in `_background` are optional. The override is stripped from the arguments before the tool runs.
98
+
99
+ ```json
100
+ {
101
+ "topic": "solana",
102
+ "_background": { "enabled": true, "timeoutMs": 900_000 }
103
+ }
104
+ ```
105
+
106
+ ### Resolution order
107
+
108
+ When a tool call is dispatched, the resolved background config is computed in this priority order:
109
+
110
+ 1. LLM `_background` override (if present in the call's arguments).
111
+ 2. Agent-level `backgroundTasks.tools` entry for the tool.
112
+ 3. Tool-level `backgroundTasks` config.
113
+ 4. Manager defaults (`defaultTimeoutMs`, `defaultRetries`).
114
+
115
+ If the agent has `backgroundTasks.disabled: true`, every tool call runs synchronously regardless of the layers above.
116
+
117
+ ## Background tasks related stream chunks
118
+
119
+ When a tool call dispatches as a background task, two streams may surface lifecycle events for it: the agent's own stream and the [`backgroundTaskManager.stream()`](https://mastra.ai/docs/streaming/background-task-streaming) SSE stream. Each stream covers a different set of chunk types:
120
+
121
+ | Chunk type | When it fires | Emitted by |
122
+ | --------------------------- | -------------------------------------------------------------------------------------- | -------------- |
123
+ | `background-task-started` | The task has been enqueued and assigned a `taskId`. | Agent stream |
124
+ | `background-task-running` | The task picked up a worker and started executing. | Manager stream |
125
+ | `background-task-progress` | Shows number of running background tasks. | Agent stream |
126
+ | `background-task-output` | A streamed output chunk from the task's `execute`. | Manager stream |
127
+ | `background-task-completed` | The task finished successfully. The `payload.result` matches the eventual tool result. | Manager stream |
128
+ | `background-task-failed` | The task threw or timed out. | Manager stream |
129
+ | `background-task-cancelled` | The task was cancelled before completing. | Manager stream |
130
+
131
+ `agent.stream().fullStream` only emits the agent-loop chunks (`background-task-started`, `background-task-progress`) on its own. `agent.streamUntilIdle()` emits the same two chunks and additionally subscribes to the manager pubsub for the run's memory scope and pipes the five manager chunks (`background-task-running`, `background-task-output`, `background-task-completed`, `background-task-failed`, `background-task-cancelled`) into the same `fullStream`, so consumers of `streamUntilIdle().fullStream` see all seven types.
132
+
133
+ `backgroundTaskManager.stream()` only emits the five manager chunks.
134
+
135
+ The full payload shapes are documented in the [background task chunks reference](https://mastra.ai/reference/streaming/ChunkType).
136
+
137
+ ## Keep the agent stream open with `streamUntilIdle()`
138
+
139
+ `agent.stream()` returns once the LLM emits a final response even if a background task is still running. Use `agent.streamUntilIdle()` when you want the stream to stay open until every dispatched background task has completed and the LLM has had a chance to respond to the result:
140
+
141
+ ```typescript
142
+ const stream = await agent.streamUntilIdle('Research solana for me', {
143
+ memory: { thread: 't1', resource: 'u1' },
144
+ maxIdleMs: 5 * 60_000,
145
+ })
146
+
147
+ for await (const chunk of stream.fullStream) {
148
+ // chunks from the initial turn AND any continuation turns triggered by
149
+ // background task completions flow through here
150
+ }
151
+ ```
152
+
153
+ When a background task completes, the result is injected into the agent memory, `streamUntilIdle()` re-enters the agentic loop so the LLM can react to it. The stream closes when no tasks are running and no completions are queued.
154
+
155
+ `maxIdleMs` caps how long the stream waits between turns. The timer only runs while the wrapper is between turns, so a slow first token won't close the stream. The default is 5 minutes.
156
+
157
+ > **Note:** Visit [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) for the full API.
158
+
159
+ ### Aggregate properties
160
+
161
+ `streamUntilIdle()` returns a `MastraModelOutput` that looks like the one from `stream()`, but only `fullStream` spans the initial turn **and** any auto-continuations. Aggregate properties (`text`, `toolCalls`, `toolResults`, `finishReason`, `messageList`, `getFullOutput()`) still resolve against the **first turn's** internal buffer. If you need an aggregate view across continuations, consume `fullStream` yourself and accumulate.
162
+
163
+ ## Subagents in the background
164
+
165
+ Subagent invocations are dispatched as tool calls under the hood, so the same background configuration applies. The recommended pattern is to opt each subagent in on the supervisor, it's clearer and lets you tune `timeoutMs` per subagent in one place:
166
+
167
+ ```typescript
168
+ import { Agent } from '@mastra/core/agent'
169
+
170
+ const supervisor = new Agent({
171
+ id: 'supervisor',
172
+ instructions: 'Coordinate research and writing using the available agents.',
173
+ model: 'openai/gpt-5.4',
174
+ agents: { researchAgent, writingAgent },
175
+ backgroundTasks: {
176
+ tools: {
177
+ researchAgent: { enabled: true, timeoutMs: 900_000 },
178
+ writingAgent: { enabled: true, timeoutMs: 900_000 },
179
+ },
180
+ },
181
+ })
182
+
183
+ const stream = await supervisor.streamUntilIdle('Research AI in education and write an article', {
184
+ memory: { thread: 't1', resource: 'u1' },
185
+ })
186
+ ```
187
+
188
+ ### Inheriting from the subagent
189
+
190
+ If a subagent isn't listed under the supervisor's `backgroundTasks.tools` but has background-eligible tools of its own (either via tool-level `backgroundTasks.enabled: true` or its own `backgroundTasks.tools` entry) the framework still dispatches the entire subagent invocation as a background task. The supervisor inherits the subagent's intent: the subagent itself becomes the background task, and its inner tools run in the foreground inside the subagent's loop.
191
+
192
+ The background config used for the inherited dispatch (for example `waitTimeoutMs`) is derived from the subagent's own `backgroundTasks` config.
193
+
194
+ ```typescript
195
+ const researchAgent = new Agent({
196
+ id: 'research-agent',
197
+ description: 'Gathers factual information.',
198
+ model: 'openai/gpt-5-mini',
199
+ tools: { deepResearchTool },
200
+ backgroundTasks: {
201
+ tools: {
202
+ deepResearchTool: { enabled: true, timeoutMs: 600_000 },
203
+ },
204
+ waitTimeoutMs: 900_000,
205
+ },
206
+ })
207
+ ```
208
+
209
+ When this `researchAgent` is delegated to from a supervisor that has no backgroundTask configuration for the `researchAgent`, the supervisor still dispatches the whole `researchAgent` invocation as a background task, and `deepResearchTool` runs in the foreground inside that invocation, instead of dispatching its own nested background task.
210
+
211
+ Use this pattern when you want a subagent to behave consistently in the background regardless of which supervisor invokes it. Use the supervisor-side opt-in (above) when you want to tune background behavior centrally per supervisor.
212
+
213
+ ## Lifecycle callbacks
214
+
215
+ Each layer can register terminal-state callbacks. They don't replace one another, and success/failure hooks fire for their respective outcomes:
216
+
217
+ - Tool-level `backgroundTasks.onComplete` / `onFailed`: scoped to one tool.
218
+ - Agent-level `backgroundTasks.onTaskComplete` / `onTaskFailed`: scoped to all tasks dispatched by this agent.
219
+ - Manager-level `onTaskComplete` / `onTaskFailed`: scoped globally.
220
+
221
+ ```typescript
222
+ export const mastra = new Mastra({
223
+ storage,
224
+ backgroundTasks: {
225
+ enabled: true,
226
+ onTaskComplete: task => {
227
+ logger.info('Background task complete', { taskId: task.id, toolName: task.toolName })
228
+ },
229
+ onTaskFailed: task => {
230
+ logger.error('Background task failed', { taskId: task.id, error: task.error })
231
+ },
232
+ },
233
+ })
234
+ ```
235
+
236
+ ## Related
237
+
238
+ - [`Agent.streamUntilIdle()` reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
239
+ - [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
240
+ - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
241
+ - [Stream chunk types](https://mastra.ai/reference/streaming/ChunkType)
242
+ - [Storage](https://mastra.ai/docs/memory/storage)
@@ -72,7 +72,7 @@ Platform webhooks need a public URL to reach your local server. Use a tunnel to
72
72
  ngrok http 4111
73
73
 
74
74
  # cloudflared
75
- cloudflared tunnel --url http://localhost:4111
75
+ npx cloudflared tunnel --url http://localhost:4111
76
76
  ```
77
77
 
78
78
  Copy the generated URL and use it as the base for your webhook paths (e.g. `https://abc123.ngrok.io/api/agents/support-agent/channels/slack/webhook`).
@@ -164,6 +164,7 @@ By default, only images are sent inline (`inlineMedia: ['image/*']`). Unsupporte
164
164
 
165
165
  ## Related
166
166
 
167
+ - [Guide: Building a Slack assistant](https://mastra.ai/guides/guide/slack-assistant)
167
168
  - [Agent overview](https://mastra.ai/docs/agents/overview)
168
169
  - [Tool approval](https://mastra.ai/docs/agents/agent-approval)
169
170
  - [Channels reference](https://mastra.ai/reference/agents/channels)
@@ -52,6 +52,8 @@ When referencing an agent from your Mastra instance, use `mastra.getAgentById()`
52
52
 
53
53
  Returns the full response after all tool calls and steps complete. The result includes `text`, `toolCalls`, `toolResults`, `steps`, and token `usage` statistics.
54
54
 
55
+ See the [`Agent.generate()` reference](https://mastra.ai/reference/agents/generate) for the response shape, including tool call and tool result payloads.
56
+
55
57
  ```ts
56
58
  const agent = mastra.getAgentById('test-agent')
57
59
  const response = await agent.generate('Help me organize my day')
@@ -62,6 +64,8 @@ console.log(response.text)
62
64
 
63
65
  Returns a stream you can consume as tokens arrive. The result exposes `textStream` for incremental output and promises for `toolCalls`, `toolResults`, `steps`, and token `usage` that resolve when the stream finishes.
64
66
 
67
+ See the [`MastraModelOutput` reference](https://mastra.ai/reference/streaming/agents/MastraModelOutput) for the stream shape, including tool call and tool result payloads.
68
+
65
69
  ```ts
66
70
  const agent = mastra.getAgentById('test-agent')
67
71
  const stream = await agent.stream('Help me organize my day')
@@ -11,6 +11,8 @@ You can use individual [`Processor`](https://mastra.ai/reference/processors/proc
11
11
 
12
12
  Some processors implement both input and output logic and can be used in either array depending on where the transformation should occur.
13
13
 
14
+ Some built-in processors also persist hidden system reminder messages using `<system-reminder>...</system-reminder>` text plus `metadata.systemReminder`. These reminders stay available in raw memory history and retry/prompt reconstruction paths, but standard UI-facing message conversions and default memory recall hide them unless you explicitly opt in.
15
+
14
16
  ## When to use processors
15
17
 
16
18
  Use processors to:
@@ -81,9 +83,64 @@ Your processors run first, then memory persists messages.
81
83
 
82
84
  This ordering ensures that if your output guardrail calls `abort()`, memory processors are skipped and no messages are saved. See [Memory Processors](https://mastra.ai/docs/memory/memory-processors) for details.
83
85
 
86
+ ## Attach processors to an agent
87
+
88
+ Processors are configured on the agent through three arrays:
89
+
90
+ ```typescript
91
+ import { Agent } from '@mastra/core/agent'
92
+ import { PrefillErrorHandler, TokenLimiter, ModerationProcessor } from '@mastra/core/processors'
93
+
94
+ const agent = new Agent({
95
+ name: 'support-agent',
96
+ model: 'openai/gpt-5',
97
+ instructions: '...',
98
+ inputProcessors: [
99
+ new TokenLimiter(4000),
100
+ new ModerationProcessor({ model: 'openai/gpt-4.1-nano' }),
101
+ ],
102
+ outputProcessors: [new ModerationProcessor({ model: 'openai/gpt-4.1-nano' })],
103
+ errorProcessors: [new PrefillErrorHandler()],
104
+ })
105
+ ```
106
+
107
+ - `inputProcessors` run before the LLM.
108
+ - `outputProcessors` run during and after the LLM response.
109
+ - `errorProcessors` run when the LLM API call throws, so they can recover from provider errors.
110
+
111
+ Each array also accepts a function that returns an array, so processors can be built per-request from `RequestContext`:
112
+
113
+ ```typescript
114
+ new Agent({
115
+ // ...
116
+ inputProcessors: ({ requestContext }) => {
117
+ const limit = requestContext.get('tokenLimit') ?? 4000
118
+ return [new TokenLimiter(limit)]
119
+ },
120
+ })
121
+ ```
122
+
123
+ ### Override processors per call
124
+
125
+ `agent.generate()` and `agent.stream()` accept the same three arrays. When you pass one, it **replaces** the matching array on the agent for that call only. Memory, workspace, and other framework-managed processors still run around your array.
126
+
127
+ ```typescript
128
+ await agent.stream('Summarize this', {
129
+ inputProcessors: [new TokenLimiter(2000)],
130
+ maxProcessorRetries: 5,
131
+ })
132
+ ```
133
+
84
134
  ## Create custom processors
85
135
 
86
- Custom processors implement the `Processor` interface:
136
+ Custom processors implement the `Processor` interface.
137
+
138
+ Processor methods receive two arguments for accessing the conversation:
139
+
140
+ - `messages`: A snapshot array of `MastraDBMessage` objects for the current stage.
141
+ - `messageList`: The live `MessageList` instance. Use it to read other stages, or to add, remove, or replace messages in place.
142
+
143
+ Text lives in `message.content.parts`, not on `message.content` itself. Iterate `parts` and filter by `part.type === 'text'` to read user or assistant text. A flattened `message.content.content` string exists for legacy compatibility and can be used as a fallback. See [Message arguments](https://mastra.ai/reference/processors/processor-interface) in the `Processor` reference for full details.
87
144
 
88
145
  ### Transform input messages
89
146
 
@@ -95,12 +152,15 @@ export class CustomInputProcessor implements Processor {
95
152
  id = 'custom-input'
96
153
 
97
154
  async processInput({ messages }: ProcessInputArgs): Promise<MastraDBMessage[]> {
98
- // Transform messages before they reach the LLM
155
+ // Transform messages before they reach the LLM.
156
+ // Text lives in content.parts — iterate parts and rewrite text parts only.
99
157
  return messages.map(msg => ({
100
158
  ...msg,
101
159
  content: {
102
160
  ...msg.content,
103
- content: msg.content.content.toLowerCase(),
161
+ parts: msg.content.parts?.map(part =>
162
+ part.type === 'text' ? { ...part, text: part.text.toLowerCase() } : part,
163
+ ),
104
164
  },
105
165
  }))
106
166
  }
@@ -212,12 +272,23 @@ export class StreamFilter implements Processor {
212
272
  id = 'stream-filter'
213
273
 
214
274
  async processOutputStream({ part }): Promise<ChunkType | null> {
215
- // Transform or filter streaming chunks
275
+ // Drop text-delta chunks that contain the word "secret"
276
+ if (part.type === 'text-delta' && part.payload.text.includes('secret')) {
277
+ return null
278
+ }
279
+
280
+ // Return the (possibly modified) chunk to emit it
216
281
  return part
217
282
  }
218
283
  }
219
284
  ```
220
285
 
286
+ Return values:
287
+
288
+ - A `ChunkType` emits that chunk. Return the original `part` to pass it through unchanged.
289
+ - `null` or `undefined` drops the chunk. Both behave the same way, so a method that falls through without returning also drops the chunk.
290
+ - Dropping only affects one chunk. To stop the stream entirely, call `abort()`.
291
+
221
292
  To also receive custom `data-*` chunks emitted by tools via `writer.custom()`, set `processDataParts = true` on your processor. This lets you inspect, modify, or block tool-emitted data chunks before they reach the client.
222
293
 
223
294
  ### Validate each response
@@ -244,6 +315,31 @@ export class ResponseValidator implements Processor {
244
315
 
245
316
  For more on retry behavior, see [Retry mechanism](#retry-mechanism) in Advanced patterns.
246
317
 
318
+ ### Persist data across chunks and steps
319
+
320
+ Output methods receive a `state` object that persists for the lifetime of one request. State is keyed by the processor's `id`, so each processor sees only its own data, and it is shared between `processOutputStream`, `processOutputStep`, and `processOutputResult`. A new state object is created for every new `agent.generate()` or `agent.stream()` call.
321
+
322
+ ```typescript
323
+ import type { Processor } from '@mastra/core/processors'
324
+
325
+ export class WordCounter implements Processor {
326
+ id = 'word-counter'
327
+
328
+ async processOutputStream({ part, state }) {
329
+ state.wordCount ??= 0
330
+ if (part.type === 'text-delta') {
331
+ state.wordCount += part.payload.text.split(/\s+/).filter(Boolean).length
332
+ }
333
+ return part
334
+ }
335
+
336
+ async processOutputResult({ messages, state }) {
337
+ console.log(`Total words: ${state.wordCount}`)
338
+ return messages
339
+ }
340
+ }
341
+ ```
342
+
247
343
  ## Built-in utility processors
248
344
 
249
345
  Mastra provides utility processors for common tasks:
@@ -271,6 +367,14 @@ See the [`TokenLimiterProcessor` reference](https://mastra.ai/reference/processo
271
367
 
272
368
  Removes tool calls and results from messages sent to the LLM, saving tokens on verbose tool interactions. Optionally exclude only specific tools. This filter only affects the LLM input, filtered messages are still saved to memory.
273
369
 
370
+ By default, `ToolCallFilter` filters the initial input before the agent loop starts. Use `filterAfterToolSteps` to also filter during each loop step while preserving recent tool-producing steps.
371
+
372
+ ```typescript
373
+ new ToolCallFilter({
374
+ filterAfterToolSteps: 2,
375
+ })
376
+ ```
377
+
274
378
  See the [`ToolCallFilter` reference](https://mastra.ai/reference/processors/tool-call-filter) for configuration options and the [Memory Processors](https://mastra.ai/docs/memory/memory-processors) page for pre-memory filtering.
275
379
 
276
380
  ### `ToolSearchProcessor`
@@ -390,6 +494,23 @@ for await (const chunk of stream.fullStream) {
390
494
 
391
495
  Custom chunk types must use the `data-` prefix (e.g., `data-moderation-update`, `data-status`).
392
496
 
497
+ By default, `processOutputStream()` skips `data-*` chunks so it does not accidentally operate on tool telemetry or other processors' output. To inspect, modify, or block these chunks in a processor, set `processDataParts = true` on that processor:
498
+
499
+ ```typescript
500
+ class ModerationCollector implements Processor {
501
+ id = 'moderation-collector'
502
+ processDataParts = true
503
+
504
+ async processOutputStream({ part, state }) {
505
+ if (part.type === 'data-moderation-update') {
506
+ state.warnings ??= []
507
+ state.warnings.push(part.data)
508
+ }
509
+ return part
510
+ }
511
+ }
512
+ ```
513
+
393
514
  ### Add metadata to messages
394
515
 
395
516
  You can add custom metadata to messages in `processOutputResult`. This metadata is accessible via the response object:
@@ -525,7 +646,7 @@ const agent = new Agent({
525
646
  name: 'Quality Agent',
526
647
  model: 'openai/gpt-5.4',
527
648
  outputProcessors: [new QualityChecker()],
528
- maxProcessorRetries: 3, // Maximum retry attempts (default: 3)
649
+ maxProcessorRetries: 3, // Maximum retry attempts. If unset, retries are disabled (unless errorProcessors are configured, in which case it defaults to 10).
529
650
  })
530
651
  ```
531
652
 
@@ -536,6 +657,57 @@ The retry mechanism:
536
657
  - Tracks retry count via the `retryCount` parameter
537
658
  - Respects `maxProcessorRetries` limit on the agent
538
659
 
660
+ ### Abort and tripwire chunks
661
+
662
+ Calling `abort(reason, options)` throws a `TripWire` error that ends processing. On streams, Mastra emits a `tripwire` chunk clients can detect:
663
+
664
+ ```typescript
665
+ for await (const chunk of stream.fullStream) {
666
+ if (chunk.type === 'tripwire') {
667
+ console.log('Blocked by', chunk.payload.processorId, '-', chunk.payload.reason)
668
+ break
669
+ }
670
+ }
671
+ ```
672
+
673
+ For `agent.generate()`, the result exposes the same information as `result.tripwire` with `result.finishReason === 'other'`.
674
+
675
+ `abort` accepts a second options argument:
676
+
677
+ - `retry: true` asks the agent to retry instead of ending. Retries require `maxProcessorRetries` to be set on the agent or call.
678
+ - `metadata` attaches structured data to the `tripwire` chunk so downstream consumers can branch on categories like `pii`, `quality`, or `moderation`.
679
+
680
+ ## API error handling
681
+
682
+ The `processAPIError` method handles LLM API rejections — errors where the API rejects the request (such as 400 or 422 status codes) rather than network or server failures. This lets you modify the request and retry when the API rejects the message format.
683
+
684
+ ```typescript
685
+ import { APICallError } from '@ai-sdk/provider'
686
+ import type { Processor, ProcessAPIErrorArgs, ProcessAPIErrorResult } from '@mastra/core/processors'
687
+
688
+ export class ContextLengthHandler implements Processor {
689
+ id = 'context-length-handler'
690
+
691
+ processAPIError({
692
+ error,
693
+ messageList,
694
+ retryCount,
695
+ }: ProcessAPIErrorArgs): ProcessAPIErrorResult | void {
696
+ if (retryCount > 0) return
697
+
698
+ if (APICallError.isInstance(error) && error.message.includes('context length exceeded')) {
699
+ const messages = messageList.get.all.db()
700
+ if (messages.length > 4) {
701
+ messageList.removeByIds([messages[1]!.id, messages[2]!.id])
702
+ return { retry: true }
703
+ }
704
+ }
705
+ }
706
+ }
707
+ ```
708
+
709
+ Mastra includes a built-in [`PrefillErrorHandler`](https://mastra.ai/reference/processors/prefill-error-handler) that automatically handles the Anthropic "assistant message prefill" error. This processor is auto-injected and requires no configuration.
710
+
539
711
  ## Related documentation
540
712
 
541
713
  - [Guardrails](https://mastra.ai/docs/agents/guardrails): Security and validation processors
@@ -8,7 +8,7 @@ Use structured output when you need an agent to return a data object rather than
8
8
 
9
9
  ## Define schemas
10
10
 
11
- Agents can return structured data by defining the expected output with either [Zod](https://zod.dev/) or [JSON Schema](https://json-schema.org/). Zod is recommended because it provides TypeScript type inference and runtime validation, while JSON Schema is useful when you need a language agnostic format.
11
+ Agents can return structured data by defining the expected output with either [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.) or [JSON Schema](https://json-schema.org/). Libraries like Zod are recommended because they provide TypeScript type inference and runtime validation, while JSON Schema is useful when you need a language agnostic format.
12
12
 
13
13
  **Zod**:
14
14
 
@@ -31,6 +31,49 @@ const response = await testAgent.generate('Help me plan my day.', {
31
31
  console.log(response.object)
32
32
  ```
33
33
 
34
+ **Valibot**:
35
+
36
+ Define the `output` shape using [Valibot](https://valibot.dev/):
37
+
38
+ ```typescript
39
+ import * as v from 'valibot'
40
+ import { toStandardJsonSchema } from '@valibot/to-json-schema'
41
+
42
+ const response = await testAgent.generate('Help me plan my day.', {
43
+ structuredOutput: {
44
+ schema: toStandardJsonSchema(
45
+ v.array(
46
+ v.object({
47
+ name: v.string(),
48
+ activities: v.array(v.string()),
49
+ }),
50
+ ),
51
+ ),
52
+ },
53
+ })
54
+
55
+ console.log(response.object)
56
+ ```
57
+
58
+ **ArkType**:
59
+
60
+ Define the `output` shape using [ArkType](https://arktype.io/):
61
+
62
+ ```typescript
63
+ import { type } from 'arktype'
64
+
65
+ const response = await testAgent.generate('Help me plan my day.', {
66
+ structuredOutput: {
67
+ schema: type({
68
+ name: 'string',
69
+ activities: 'string[]',
70
+ }).array(),
71
+ },
72
+ })
73
+
74
+ console.log(response.object)
75
+ ```
76
+
34
77
  **JSON Schema**:
35
78
 
36
79
  You can also use JSON Schema to define your output structure:
@@ -210,6 +253,28 @@ const response = await testAgent.generate('Tell me about TypeScript.', {
210
253
  })
211
254
  ```
212
255
 
256
+ If you want that structuring model to also see the current conversation history, set `useAgent: true` alongside `model`. Mastra will reuse the parent agent with the separate structuring model and attach read-only memory context when a thread is available.
257
+
258
+ ```typescript
259
+ const response = await testAgent.generate('Return my profile as structured data.', {
260
+ memory: {
261
+ thread: 'thread-123',
262
+ resource: 'user-123',
263
+ },
264
+ structuredOutput: {
265
+ schema: z.object({
266
+ favoriteColor: z.string(),
267
+ hometown: z.string(),
268
+ petName: z.string(),
269
+ }),
270
+ model: 'openai/gpt-5.4',
271
+ useAgent: true,
272
+ },
273
+ })
274
+ ```
275
+
276
+ Leave `useAgent` unset if you want the separate structuring model to work only from the current response and not inherit prior conversation memory.
277
+
213
278
  ### Multi-step approach with `prepareStep`
214
279
 
215
280
  For models that don't support tools and structured outputs together, you can use `prepareStep` to handle them in separate steps.