@mastra/core 1.86.0 → 1.87.0-alpha.0

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 (446) hide show
  1. package/dist/agent/durable/constants.d.ts +2 -0
  2. package/dist/agent/durable/evented-execution.d.ts +7 -0
  3. package/dist/agent/durable/execution-engine.d.ts +1 -0
  4. package/dist/agent/durable/execution-fence.d.ts +2 -0
  5. package/dist/agent/durable/index.cjs +3 -1
  6. package/dist/agent/durable/index.d.ts +1 -1
  7. package/dist/agent/durable/index.js +2 -2
  8. package/dist/agent/durable/run-registry.d.ts +2 -0
  9. package/dist/agent/durable/segment-spans.d.ts +54 -1
  10. package/dist/agent/durable/types.d.ts +10 -0
  11. package/dist/agent/durable/workflows/durable-loop-builder.d.ts +57 -2
  12. package/dist/agent/durable/workflows/finalize-run.d.ts +2 -0
  13. package/dist/agent/durable/workflows/shared/index.d.ts +1 -1
  14. package/dist/agent/durable/workflows/shared/reported-cost.d.ts +7 -0
  15. package/dist/agent/durable/workflows/shared/schemas.d.ts +16 -1
  16. package/dist/agent/durable/workflows/shared/tool-call-concurrency.d.ts +6 -0
  17. package/dist/agent/durable/workflows/steps/llm-execution.d.ts +5 -0
  18. package/dist/agent/durable/workflows/steps/llm-mapping.d.ts +6 -0
  19. package/dist/agent/durable/workflows/steps/tool-call.d.ts +20 -0
  20. package/dist/agent/index.cjs +2 -2
  21. package/dist/agent/index.js +2 -2
  22. package/dist/agent/request-context-snapshot.d.ts +3 -2
  23. package/dist/agent/streams/run-records.d.ts +9 -1
  24. package/dist/agent-builder/ee/index.cjs +1 -1
  25. package/dist/agent-builder/ee/index.js +1 -1
  26. package/dist/agent-controller/index.cjs +1 -1
  27. package/dist/agent-controller/index.js +1 -1
  28. package/dist/agent-controller/session-run-engine.d.ts +5 -2
  29. package/dist/agent-controller/session.d.ts +2 -0
  30. package/dist/agent-controller/types.d.ts +23 -0
  31. package/dist/{agent-controller-D5EKeS1H.js → agent-controller-B8LoFdtu.js} +43 -13
  32. package/dist/{agent-controller-D_5Dc8d3.cjs → agent-controller-DSnFynpa.cjs} +43 -13
  33. package/dist/background-tasks/index.cjs +1 -1
  34. package/dist/background-tasks/index.js +1 -1
  35. package/dist/background-tasks/manager.d.ts +4 -1
  36. package/dist/{background-tasks-BVxb0VGV.cjs → background-tasks-Ci5h0dhj.cjs} +139 -51
  37. package/dist/{background-tasks-idnlMbqD.js → background-tasks-IW7M4iD2.js} +139 -51
  38. package/dist/browser/index.cjs +1 -1
  39. package/dist/browser/index.js +1 -1
  40. package/dist/{builder-CBWoYNck.cjs → builder-14Uptu8y.cjs} +2 -2
  41. package/dist/{builder-Cuq-j2w3.js → builder-DI2c2xjy.js} +2 -2
  42. package/dist/cache/base.d.ts +40 -10
  43. package/dist/cache/index.cjs +1 -1
  44. package/dist/cache/index.js +1 -1
  45. package/dist/capabilities/302ai.json +200 -200
  46. package/dist/capabilities/abliteratedllm.json +34 -34
  47. package/dist/capabilities/abliteration-ai.json +8 -8
  48. package/dist/capabilities/above.json +24 -24
  49. package/dist/capabilities/adaption.json +15 -15
  50. package/dist/capabilities/adzuki.json +29 -29
  51. package/dist/capabilities/agentrouter.json +12 -12
  52. package/dist/capabilities/agnes.json +2 -2
  53. package/dist/capabilities/ai-router.json +5 -5
  54. package/dist/capabilities/aiand.json +25 -25
  55. package/dist/capabilities/aigrow.json +13 -13
  56. package/dist/capabilities/aimlapi.json +149 -152
  57. package/dist/capabilities/aixy.json +20 -20
  58. package/dist/capabilities/aki-io.json +10 -10
  59. package/dist/capabilities/alibaba-cn.json +85 -85
  60. package/dist/capabilities/alibaba-coding-plan-cn.json +5 -5
  61. package/dist/capabilities/alibaba-coding-plan.json +5 -5
  62. package/dist/capabilities/alibaba-token-plan-cn.json +44 -44
  63. package/dist/capabilities/alibaba-token-plan.json +47 -47
  64. package/dist/capabilities/alibaba.json +62 -62
  65. package/dist/capabilities/ambient.json +14 -14
  66. package/dist/capabilities/amd.json +8 -8
  67. package/dist/capabilities/anthropic.json +39 -39
  68. package/dist/capabilities/anyapi.json +13 -13
  69. package/dist/capabilities/apiko.json +5 -5
  70. package/dist/capabilities/arcee.json +11 -11
  71. package/dist/capabilities/augure.json +4 -4
  72. package/dist/capabilities/auriko.json +21 -21
  73. package/dist/capabilities/bailing.json +4 -4
  74. package/dist/capabilities/baseten.json +33 -33
  75. package/dist/capabilities/bee.json +5 -5
  76. package/dist/capabilities/berget.json +4 -4
  77. package/dist/capabilities/bothub.json +16 -16
  78. package/dist/capabilities/boundless.json +37 -37
  79. package/dist/capabilities/bumo.json +48 -48
  80. package/dist/capabilities/byteplus.json +25 -25
  81. package/dist/capabilities/cheapaimodel.json +5 -5
  82. package/dist/capabilities/cheapest-token.json +28 -28
  83. package/dist/capabilities/chutes.json +11 -14
  84. package/dist/capabilities/cline-pass.json +41 -41
  85. package/dist/capabilities/cloudcode.json +9 -9
  86. package/dist/capabilities/cloudferro-sherlock.json +4 -4
  87. package/dist/capabilities/cloudflare-workers-ai.json +18 -79
  88. package/dist/capabilities/commandcode.json +155 -155
  89. package/dist/capabilities/concentrate.json +279 -270
  90. package/dist/capabilities/cortecs.json +100 -100
  91. package/dist/capabilities/crossmodel.json +178 -178
  92. package/dist/capabilities/crusoe.json +9 -9
  93. package/dist/capabilities/daoxe.json +9 -9
  94. package/dist/capabilities/databricks.json +137 -137
  95. package/dist/capabilities/deepinfra.json +124 -61
  96. package/dist/capabilities/deepseek.json +3 -3
  97. package/dist/capabilities/digitalocean.json +113 -113
  98. package/dist/capabilities/dothoosh.json +32 -32
  99. package/dist/capabilities/doubleword.json +26 -26
  100. package/dist/capabilities/edenai.json +448 -473
  101. package/dist/capabilities/empiriolabs.json +163 -165
  102. package/dist/capabilities/engy.json +19 -19
  103. package/dist/capabilities/entrim.json +6 -6
  104. package/dist/capabilities/evroc.json +16 -16
  105. package/dist/capabilities/ezkielyna.json +12 -12
  106. package/dist/capabilities/fastrouter.json +73 -73
  107. package/dist/capabilities/fireworks-ai.json +83 -62
  108. package/dist/capabilities/freemodel.json +15 -15
  109. package/dist/capabilities/friendli.json +2 -2
  110. package/dist/capabilities/frogbot.json +99 -99
  111. package/dist/capabilities/gisoo.json +17 -17
  112. package/dist/capabilities/gmicloud.json +14 -14
  113. package/dist/capabilities/google.json +57 -57
  114. package/dist/capabilities/graphn.json +9 -9
  115. package/dist/capabilities/greenpt.json +36 -36
  116. package/dist/capabilities/groq.json +8 -8
  117. package/dist/capabilities/helicone.json +82 -82
  118. package/dist/capabilities/hopper.json +2 -2
  119. package/dist/capabilities/hostinger-router.json +10 -10
  120. package/dist/capabilities/hpc-ai.json +14 -14
  121. package/dist/capabilities/huawei-maas.json +16 -16
  122. package/dist/capabilities/hubris.json +29 -29
  123. package/dist/capabilities/huggingface.json +94 -84
  124. package/dist/capabilities/humain.json +2 -2
  125. package/dist/capabilities/hyper.json +23 -23
  126. package/dist/capabilities/impossibl.json +136 -136
  127. package/dist/capabilities/inception.json +2 -2
  128. package/dist/capabilities/inceptron.json +8 -8
  129. package/dist/capabilities/inco.json +2 -2
  130. package/dist/capabilities/infer.json +14 -14
  131. package/dist/capabilities/inferall.json +7 -7
  132. package/dist/capabilities/inference-coop.json +3 -3
  133. package/dist/capabilities/inferenceapis.json +20 -20
  134. package/dist/capabilities/inferris.json +3 -3
  135. package/dist/capabilities/infersia.json +8 -8
  136. package/dist/capabilities/inferx.json +3 -3
  137. package/dist/capabilities/infomaniak.json +2 -2
  138. package/dist/capabilities/io-net.json +4 -4
  139. package/dist/capabilities/isoquant.json +4 -4
  140. package/dist/capabilities/iteracompute.json +61 -61
  141. package/dist/capabilities/jalapeno.json +12 -12
  142. package/dist/capabilities/jiekou.json +60 -60
  143. package/dist/capabilities/joingonka.json +4 -4
  144. package/dist/capabilities/jzstoken.json +55 -55
  145. package/dist/capabilities/keln.json +25 -25
  146. package/dist/capabilities/kenari.json +122 -122
  147. package/dist/capabilities/kilo.json +633 -617
  148. package/dist/capabilities/kimi-code-plan-cn.json +6 -6
  149. package/dist/capabilities/kimi-code-plan-global.json +6 -6
  150. package/dist/capabilities/kitani.json +6 -6
  151. package/dist/capabilities/klavo.json +20 -20
  152. package/dist/capabilities/korouter.json +32 -32
  153. package/dist/capabilities/kunavo.json +9 -9
  154. package/dist/capabilities/liquid.json +12 -12
  155. package/dist/capabilities/lithosai.json +3 -3
  156. package/dist/capabilities/llmgateway-providers.json +912 -903
  157. package/dist/capabilities/llmgateway.json +346 -338
  158. package/dist/capabilities/llmtr.json +30 -30
  159. package/dist/capabilities/logits.json +2 -2
  160. package/dist/capabilities/lowrouter.json +53 -53
  161. package/dist/capabilities/lyceum.json +10 -10
  162. package/dist/capabilities/melious.json +12 -12
  163. package/dist/capabilities/merge-gateway.json +276 -276
  164. package/dist/capabilities/meta.json +10 -10
  165. package/dist/capabilities/mistral.json +21 -21
  166. package/dist/capabilities/mixlayer.json +2 -2
  167. package/dist/capabilities/modal.json +6 -6
  168. package/dist/capabilities/model-oracle-ai.json +25 -25
  169. package/dist/capabilities/modelis.json +15 -15
  170. package/dist/capabilities/modelscope.json +2 -2
  171. package/dist/capabilities/modular.json +6 -6
  172. package/dist/capabilities/moneo.json +14 -14
  173. package/dist/capabilities/moonshotai-cn.json +7 -7
  174. package/dist/capabilities/moonshotai.json +7 -7
  175. package/dist/capabilities/morph.json +16 -16
  176. package/dist/capabilities/munito-eu.json +6 -6
  177. package/dist/capabilities/munito.json +10 -10
  178. package/dist/capabilities/nan.json +24 -24
  179. package/dist/capabilities/nano-gpt.json +612 -579
  180. package/dist/capabilities/nearai.json +97 -97
  181. package/dist/capabilities/nebius.json +32 -32
  182. package/dist/capabilities/neon.json +131 -131
  183. package/dist/capabilities/neuralwatt.json +43 -43
  184. package/dist/capabilities/nokeep.json +4 -4
  185. package/dist/capabilities/novita-ai.json +148 -148
  186. package/dist/capabilities/nvidia.json +17 -49
  187. package/dist/capabilities/obscurify.json +26 -26
  188. package/dist/capabilities/oci.json +16 -7
  189. package/dist/capabilities/ofox.json +344 -344
  190. package/dist/capabilities/ollama-cloud.json +56 -56
  191. package/dist/capabilities/openai.json +81 -49
  192. package/dist/capabilities/opencode-go.json +90 -90
  193. package/dist/capabilities/openreason.json +5 -5
  194. package/dist/capabilities/openrouter.json +563 -547
  195. package/dist/capabilities/opper.json +29 -29
  196. package/dist/capabilities/orcarouter.json +252 -252
  197. package/dist/capabilities/outerlabs.json +33 -33
  198. package/dist/capabilities/ovhcloud.json +59 -5
  199. package/dist/capabilities/pareto.json +5 -5
  200. package/dist/capabilities/perplexity-agent.json +66 -66
  201. package/dist/capabilities/phala.json +30 -30
  202. package/dist/capabilities/pioneer.json +24 -24
  203. package/dist/capabilities/poe.json +117 -117
  204. package/dist/capabilities/poolside.json +2 -2
  205. package/dist/capabilities/powerspring.json +14 -14
  206. package/dist/capabilities/primalabs.json +11 -11
  207. package/dist/capabilities/prime.json +129 -113
  208. package/dist/capabilities/privatemode-ai.json +14 -14
  209. package/dist/capabilities/proxystacks.json +6 -6
  210. package/dist/capabilities/qiniu-ai.json +14 -14
  211. package/dist/capabilities/refuseless.json +5 -5
  212. package/dist/capabilities/regolo-ai.json +9 -9
  213. package/dist/capabilities/requesty.json +172 -172
  214. package/dist/capabilities/ruapi.json +18 -18
  215. package/dist/capabilities/runcrate.json +15 -15
  216. package/dist/capabilities/runinfra.json +16 -16
  217. package/dist/capabilities/sakana.json +6 -6
  218. package/dist/capabilities/sambanova.json +9 -9
  219. package/dist/capabilities/sandbase.json +21 -21
  220. package/dist/capabilities/sarvam.json +8 -8
  221. package/dist/capabilities/scaleway.json +18 -18
  222. package/dist/capabilities/scnet-token-plan.json +9 -9
  223. package/dist/capabilities/scx-ai.json +30 -30
  224. package/dist/capabilities/sensenova.json +8 -8
  225. package/dist/capabilities/siliconflow-cn.json +62 -62
  226. package/dist/capabilities/siliconflow.json +58 -58
  227. package/dist/capabilities/snowflake-cortex.json +22 -22
  228. package/dist/capabilities/sokkan.json +10 -10
  229. package/dist/capabilities/sparrowcodes.json +22 -22
  230. package/dist/capabilities/standardcompute.json +101 -101
  231. package/dist/capabilities/steadyrouter.json +43 -43
  232. package/dist/capabilities/stepfun-ai-step-plan.json +6 -6
  233. package/dist/capabilities/stepfun-ai.json +5 -5
  234. package/dist/capabilities/stepfun-step-plan.json +5 -5
  235. package/dist/capabilities/stepfun.json +5 -5
  236. package/dist/capabilities/stepping-stone.json +22 -22
  237. package/dist/capabilities/subconscious.json +2 -2
  238. package/dist/capabilities/superbot-gg.json +4 -4
  239. package/dist/capabilities/synthetic.json +14 -14
  240. package/dist/capabilities/synthorai.json +22 -22
  241. package/dist/capabilities/teamorouter.json +23 -23
  242. package/dist/capabilities/teapot-router.json +16 -16
  243. package/dist/capabilities/tencent-token-plan.json +57 -33
  244. package/dist/capabilities/tencent-tokenhub.json +48 -48
  245. package/dist/capabilities/tensorx.json +46 -46
  246. package/dist/capabilities/tenstorrent.json +2 -2
  247. package/dist/capabilities/the-grid-ai.json +31 -31
  248. package/dist/capabilities/thinkingmachines.json +44 -44
  249. package/dist/capabilities/tinfoil.json +11 -11
  250. package/dist/capabilities/toapis.json +3 -3
  251. package/dist/capabilities/togetherai.json +53 -51
  252. package/dist/capabilities/tokengo.json +24 -24
  253. package/dist/capabilities/tokenify.json +10 -10
  254. package/dist/capabilities/trustedrouter.json +6 -6
  255. package/dist/capabilities/trustedtokens.json +16 -16
  256. package/dist/capabilities/umans-ai-coding-plan.json +15 -15
  257. package/dist/capabilities/umans-ai.json +9 -9
  258. package/dist/capabilities/unrestricted.json +8 -8
  259. package/dist/capabilities/uplinkswitch.json +21 -21
  260. package/dist/capabilities/upstage.json +6 -6
  261. package/dist/capabilities/vancine.json +21 -21
  262. package/dist/capabilities/vercel.json +578 -578
  263. package/dist/capabilities/vivgrid.json +81 -81
  264. package/dist/capabilities/volcengine-coding-plan.json +26 -26
  265. package/dist/capabilities/volcengine.json +27 -27
  266. package/dist/capabilities/vultr.json +25 -25
  267. package/dist/capabilities/wafer.ai.json +18 -18
  268. package/dist/capabilities/wallaby.json +5 -5
  269. package/dist/capabilities/wally.json +12 -12
  270. package/dist/capabilities/wandb.json +19 -19
  271. package/dist/capabilities/watt.json +22 -22
  272. package/dist/capabilities/xai.json +7 -7
  273. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  274. package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
  275. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  276. package/dist/capabilities/xiaomi.json +2 -2
  277. package/dist/capabilities/xpersona.json +11 -11
  278. package/dist/capabilities/xxapi.json +32 -32
  279. package/dist/capabilities/zai-coding-plan.json +16 -16
  280. package/dist/capabilities/zai.json +34 -32
  281. package/dist/capabilities/zenifra.json +26 -26
  282. package/dist/capabilities/zenmux.json +187 -187
  283. package/dist/capabilities/zerogpu.json +13 -13
  284. package/dist/capabilities/zhipuai-coding-plan.json +7 -7
  285. package/dist/capabilities/zhipuai.json +29 -29
  286. package/dist/capabilities/zro.json +6 -6
  287. package/dist/channels/agent-channels.d.ts +2 -1
  288. package/dist/channels/formatting.d.ts +8 -0
  289. package/dist/channels/index.cjs +4 -2
  290. package/dist/channels/index.d.ts +1 -1
  291. package/dist/channels/index.js +3 -3
  292. package/dist/channels/types.d.ts +5 -3
  293. package/dist/{channels-DSOCNoab.js → channels-Wh32drgu.js} +1 -1
  294. package/dist/{channels-D7bBM9xD.cjs → channels-tVV_de9Q.cjs} +1 -1
  295. package/dist/coding-agent/index.cjs +1 -1
  296. package/dist/coding-agent/index.js +1 -1
  297. package/dist/datasets/index.cjs +2 -2
  298. package/dist/datasets/index.js +2 -2
  299. package/dist/docs/SKILL.md +1 -1
  300. package/dist/docs/assets/SOURCE_MAP.json +789 -789
  301. package/dist/docs/references/docs-agents-resumable-streams.md +15 -6
  302. package/dist/docs/references/docs-deployment-workers.md +3 -1
  303. package/dist/docs/references/docs-harness-background-tasks.md +4 -4
  304. package/dist/docs/references/docs-harness-durable-agents.md +39 -48
  305. package/dist/docs/references/docs-knowledge-importers.md +1 -1
  306. package/dist/docs/references/docs-mastra-platform-observability-overview.md +1 -1
  307. package/dist/docs/references/docs-sandbox-overview.md +1 -0
  308. package/dist/docs/references/docs-server-pubsub.md +1 -1
  309. package/dist/docs/references/docs-workflows-overview.md +67 -3
  310. package/dist/docs/references/integrations-agentic-ui-assistant-ui.md +2 -0
  311. package/dist/docs/references/integrations-frameworks-angular.md +39 -0
  312. package/dist/docs/references/integrations-frameworks-astro.md +5 -2
  313. package/dist/docs/references/integrations-frameworks-electron.md +40 -0
  314. package/dist/docs/references/integrations-frameworks-next-js.md +5 -2
  315. package/dist/docs/references/integrations-frameworks-nuxt.md +5 -2
  316. package/dist/docs/references/integrations-frameworks-sveltekit.md +5 -2
  317. package/dist/docs/references/integrations-frameworks-vite-react.md +40 -0
  318. package/dist/docs/references/integrations.md +3 -0
  319. package/dist/docs/references/reference-agent-controller-agent-controller-class.md +6 -0
  320. package/dist/docs/references/reference-agents-channels.md +1 -1
  321. package/dist/docs/references/reference-agents-durable-agent.md +3 -3
  322. package/dist/docs/references/reference-agents-generate.md +2 -0
  323. package/dist/docs/references/reference-configuration.md +1 -1
  324. package/dist/docs/references/reference-core-mastra-class.md +2 -0
  325. package/dist/docs/references/reference-knowledge-knowledge-class.md +1 -1
  326. package/dist/docs/references/reference-knowledge-knowledge-tools.md +11 -5
  327. package/dist/docs/references/reference-pubsub-caching-pubsub.md +2 -2
  328. package/dist/docs/references/reference-pubsub-redis-streams.md +2 -2
  329. package/dist/docs/references/reference-pubsub-valkey-streams.md +2 -2
  330. package/dist/docs/references/reference-workers-overview.md +2 -0
  331. package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +2 -0
  332. package/dist/docs/references/reference-workflows-workflow.md +2 -0
  333. package/dist/docs/references/reference.md +1 -0
  334. package/dist/error/index.cjs +2 -1
  335. package/dist/error/index.d.ts +1 -1
  336. package/dist/error/index.js +2 -2
  337. package/dist/error/provider-error.d.ts +2 -1
  338. package/dist/{error-BLwEXqOK.js → error-BC9Au-22.js} +13 -1
  339. package/dist/{error-BdEvO8za.cjs → error-L1V4uUbd.cjs} +18 -0
  340. package/dist/evals/index.cjs +1 -1
  341. package/dist/evals/index.js +1 -1
  342. package/dist/evals/scoreTraces/index.cjs +1 -1
  343. package/dist/evals/scoreTraces/index.js +1 -1
  344. package/dist/events/caching-pubsub.d.ts +28 -0
  345. package/dist/events/index.cjs +4 -1
  346. package/dist/events/index.js +2 -2
  347. package/dist/events/topics.d.ts +55 -9
  348. package/dist/harness/index.cjs +1 -1
  349. package/dist/harness/index.js +1 -1
  350. package/dist/index.cjs +1 -1
  351. package/dist/index.js +1 -1
  352. package/dist/{inmemory-BDD0w8gx.js → inmemory-BK3zLwvM.js} +42 -12
  353. package/dist/{inmemory-fgR8sq-U.cjs → inmemory-Dc86VWGB.cjs} +42 -12
  354. package/dist/knowledge/changes.d.ts +17 -5
  355. package/dist/knowledge/importers/runner.d.ts +6 -0
  356. package/dist/knowledge/index.cjs +78 -16
  357. package/dist/knowledge/index.d.ts +2 -2
  358. package/dist/knowledge/index.js +78 -16
  359. package/dist/knowledge/search-snippet.d.ts +30 -0
  360. package/dist/llm/index.cjs +3 -3
  361. package/dist/llm/index.js +3 -3
  362. package/dist/llm/model/provider-types.generated.d.ts +7986 -7970
  363. package/dist/{llm-DMNEZIV9.js → llm-B1zaFLYZ.js} +3 -3
  364. package/dist/{llm-BOQR5g0t.cjs → llm-BAiOsNAP.cjs} +3 -3
  365. package/dist/loop/index.cjs +2 -2
  366. package/dist/loop/index.js +2 -2
  367. package/dist/{manager-CyCR9IpR.cjs → manager-BVX9nVrM.cjs} +2 -2
  368. package/dist/{manager-BzNynLwT.js → manager-ChK9GdGz.js} +2 -2
  369. package/dist/mastra/index.cjs +1 -1
  370. package/dist/mastra/index.js +1 -1
  371. package/dist/{mastra-CqBmnzjM.js → mastra-CUGfgEpZ.js} +28 -18
  372. package/dist/{mastra-D2B01_gg.cjs → mastra-HSmofHEJ.cjs} +28 -18
  373. package/dist/memory/index.cjs +2 -2
  374. package/dist/memory/index.js +2 -2
  375. package/dist/{model-3AeJKHLU.js → model-C47BJRtR.js} +1 -1
  376. package/dist/{model-CrXDhcbw.cjs → model-WahorgzJ.cjs} +1 -1
  377. package/dist/{netlify-DUPSTzi6.js → netlify-CfDXkuLf.js} +2 -2
  378. package/dist/{netlify-DTXLQiG1.cjs → netlify-D99AnEhW.cjs} +2 -2
  379. package/dist/notifications/index.cjs +1 -1
  380. package/dist/notifications/index.js +1 -1
  381. package/dist/observability/index.cjs +1 -0
  382. package/dist/observability/index.d.ts +1 -1
  383. package/dist/observability/index.js +2 -2
  384. package/dist/{output-helpers-CedRCE17.js → output-helpers-CVzhy1Y0.js} +126 -56
  385. package/dist/{output-helpers-1Zu4Vt9C.cjs → output-helpers-DgsH4aTb.cjs} +143 -55
  386. package/dist/processor-provider/index.cjs +1 -1
  387. package/dist/processor-provider/index.js +1 -1
  388. package/dist/processors/index.cjs +2 -2
  389. package/dist/processors/index.js +2 -2
  390. package/dist/processors/runner.d.ts +2 -0
  391. package/dist/{provider-registry-B_rC-5aL.cjs → provider-registry-CO1NVbO5.cjs} +22281 -22258
  392. package/dist/{provider-registry-BeB8RQO8.js → provider-registry-CR385GJ4.js} +22281 -22258
  393. package/dist/provider-registry.json +22871 -22855
  394. package/dist/{registry-generator-Cv6GnxLG.js → registry-generator-B3erRqYS.js} +1 -1
  395. package/dist/{registry-generator-DbBoIOby.cjs → registry-generator-Cvp34qcB.cjs} +1 -1
  396. package/dist/{rehydrate-3f-i1Ga2.js → rehydrate-CJBLrZxs.js} +2 -2
  397. package/dist/{rehydrate-BWaa2eGN.cjs → rehydrate-Da4hNuaK.cjs} +2 -2
  398. package/dist/relevance/index.cjs +2 -2
  399. package/dist/relevance/index.js +2 -2
  400. package/dist/{run-registry-Bx06ZIN_.js → run-registry-DdeEBsVW.js} +1639 -568
  401. package/dist/{run-registry-Bk6QxNE4.cjs → run-registry-TOOfO3hT.cjs} +1668 -567
  402. package/dist/storage/domains/inmemory-db.d.ts +1 -0
  403. package/dist/storage/domains/knowledge/base.d.ts +5 -0
  404. package/dist/storage/domains/knowledge/inmemory.d.ts +1 -0
  405. package/dist/storage/domains/knowledge/pages-inmemory.d.ts +10 -2
  406. package/dist/storage/domains/knowledge/pages.d.ts +30 -0
  407. package/dist/storage/index.cjs +2 -2
  408. package/dist/storage/index.js +2 -2
  409. package/dist/storage/run-fencing.d.ts +5 -0
  410. package/dist/stream/index.cjs +2 -2
  411. package/dist/stream/index.js +2 -2
  412. package/dist/{stream-DVy0Z-m0.js → stream-C5PagEDs.js} +3 -3
  413. package/dist/{stream-BIXX67WE.cjs → stream-DH7Qgz8l.cjs} +3 -3
  414. package/dist/test-utils/llm-mock.cjs +1 -1
  415. package/dist/test-utils/llm-mock.js +1 -1
  416. package/dist/tool-loop-agent/index.cjs +1 -1
  417. package/dist/tool-loop-agent/index.js +1 -1
  418. package/dist/{tool-loop-agent-DDeKGwtr.cjs → tool-loop-agent-CJTs4T8b.cjs} +3 -3
  419. package/dist/{tool-loop-agent-PSKeNhuT.js → tool-loop-agent-DVYJXlQJ.js} +3 -3
  420. package/dist/{utils-BJiQF8Pi.js → utils-D8upuTwy.js} +1 -1
  421. package/dist/{utils-CAnUlnUm.cjs → utils-xJi_N6Tx.cjs} +1 -1
  422. package/dist/utils.cjs +1 -1
  423. package/dist/utils.js +1 -1
  424. package/dist/{validate-BMNxfs4Z.cjs → validate-6eZ8Wssn.cjs} +1 -1
  425. package/dist/{validate-BAVwAgtT.js → validate-DTkW3Vlp.js} +1 -1
  426. package/dist/vector/index.cjs +1 -1
  427. package/dist/vector/index.js +1 -1
  428. package/dist/worker/index.cjs +1 -1
  429. package/dist/worker/index.js +1 -1
  430. package/dist/{worker-CFUKBBCF.cjs → worker-24ORi-wV.cjs} +2 -2
  431. package/dist/{worker-Brwa-HqM.cjs → worker-BO3u_WjZ.cjs} +2 -2
  432. package/dist/{worker-BlvJM_Hu.js → worker-DbcFkKJO.js} +2 -2
  433. package/dist/{worker-CVoD3tts.js → worker-Dqubrnf8.js} +2 -2
  434. package/dist/{workflow-zvQGBMCM.cjs → workflow-D5Fc5ieC.cjs} +4 -4
  435. package/dist/{workflow-BSLS7_vB.js → workflow-wXOf72fO.js} +4 -4
  436. package/dist/workflows/builder/index.cjs +1 -1
  437. package/dist/workflows/builder/index.js +1 -1
  438. package/dist/workflows/evented/index.cjs +1 -1
  439. package/dist/workflows/evented/index.js +1 -1
  440. package/dist/workflows/index.cjs +4 -4
  441. package/dist/workflows/index.js +4 -4
  442. package/dist/workflows/run-ownership.d.ts +74 -8
  443. package/dist/workflows/types.d.ts +16 -0
  444. package/dist/workflows/workflow.d.ts +4 -0
  445. package/package.json +6 -6
  446. package/src/llm/model/provider-types.generated.d.ts +7986 -7970
@@ -18,7 +18,12 @@ Resumable streams don't make the run itself durable. Reconnecting isn't crash re
18
18
  | Plain agent with `durable: false` | Off, including registered agents |
19
19
  | Explicit `createDurableAgent()` wrapper | Always published; pass `cache: false` to the factory to disable the replay cache, not transport history |
20
20
 
21
- A registered agent, durable or not, publishes on `mastra.pubsub` and caches events in `mastra.serverCache`, or an in-memory cache when the server has none. Every `Mastra` instance that shares that PubSub and cache can observe the run. An agent-level `pubsub` takes precedence, except on the evented engine, whose steps always publish on `mastra.pubsub`.
21
+ Mastra resolves the stream transport and replay cache separately:
22
+
23
+ - **Transport:** For the plain loop and the default durable engine, Mastra uses the first configured option: the agent's `durable.pubsub`, the agent's top-level `pubsub`, or `mastra.pubsub`. Evented steps publish on `mastra.pubsub` so workers can publish to the same stream.
24
+ - **Replay cache:** Mastra uses the agent's `durable.cache`, then `mastra.serverCache`, then an in-memory cache. Evented runs use the shared Mastra cache when replay caching is enabled. If the transport is already a `CachingPubSub`, Mastra reuses its cache. Set `durable.cache: false` to skip adding a replay cache without changing the transport or its retained history.
25
+
26
+ For deployments with more than one process, see [PubSub setup for resumable streams](https://mastra.ai/docs/server/pubsub).
22
27
 
23
28
  ## Configure streams
24
29
 
@@ -48,7 +53,9 @@ export const supportAgent = new Agent({
48
53
 
49
54
  `durable: true` turns streams on with these defaults, including for standalone agents.
50
55
 
51
- On a plain `Agent`, `durable` configures resumable streams only. For checkpoint-backed execution, wrap the agent explicitly with `createDurableAgent({ agent })`. To recover in-flight runs after a crash, also configure persistent workflow storage and `recovery: { durableAgents: 'auto' }`. For manual recovery instead, pass a `shouldPersistSnapshot` policy that includes `running` snapshots and call `recoverActiveRuns()` yourself. See [crash recovery](https://mastra.ai/docs/harness/durable-agents) for setup and persistence policies.
56
+ To checkpoint execution as well as publish run frames, set `durable.executionEngine` to `'default'` or `'evented'` on the agent, or inherit the setting from `Mastra`. Without an engine setting, `durable: true` only enables stream publication.
57
+
58
+ To continue an in-flight run after a crash, configure [crash recovery](https://mastra.ai/docs/harness/durable-agents) separately.
52
59
 
53
60
  Configure the wrapper's stream cache and transport through the factory's `cache`, `pubsub`, `shouldCache`, and `cleanupTimeoutMs` options.
54
61
 
@@ -72,15 +79,17 @@ To keep live observation but skip the replay cache, pass `durable: { cache: fals
72
79
 
73
80
  ### How long runs stay available
74
81
 
75
- After a run finishes, the executing process schedules cleanup of its events and ownership record after `cleanupTimeoutMs`. The timer allows the process to exit before cleanup. Shared cache data then remains until expiry or eviction. Redis Streams retains its native topic data until `clearTopic()` succeeds or its idle TTL expires. The transport's default idle TTL is seven days. Configure `streamIdleTtlMs` to change it, or set it to `0` to disable transport expiry. A run parked on a tool approval or suspension isn't cleared by that timer, because resuming it continues on the same topic.
82
+ When a run finishes, the executing process schedules deletion of its events and ownership record after `cleanupTimeoutMs` (30 seconds by default). That's the fast path. Everything is also bounded by idle retention, refreshed on every append, so a process that restarts before the deletion timer fires can't leave a run's state behind indefinitely. A run parked on a tool approval or suspension isn't deleted, because resuming it continues on the same topic.
76
83
 
77
- The cache bounds everything else:
84
+ The retentions that apply:
78
85
 
79
- - Run logs and ownership records ask the cache for a 24-hour TTL. The in-memory cache uses at least this TTL for indexed run logs, unless cache expiry is disabled. Cache entry limits can evict data sooner.
86
+ - A run's replay cache requests a minimum 24-hour lifetime after the last append (`runLogTtlMs` on [`CachingPubSub`](https://mastra.ai/reference/pubsub/caching-pubsub)). Redis and Valkey Streams use a separate 24-hour transport default for run topics. These defaults match the run record's own 24-hour lifetime, deliberately: a run parked on a tool approval appends nothing while it waits, so its retention is never refreshed, and the events must outlive every moment the record still authorizes an `observe()` or resume. For thread streams, `threadStreamLogTtlMs` requests one hour in the cache while the transport independently defaults to one hour, enough for an idle thread's tail to survive a reconnect. Cache TTL overrides leave the transport defaults unchanged, though `streamIdleTtlMs` can shorten them. The replay cache's retention is stamped only when an event is appended. The transport's is also refreshed when a reader subscribes.
87
+ - A run's ownership record keeps a 24-hour lifetime, so a run parked overnight on an approval stays authorizable for observe and resume, and because its events share that lifetime, the approval request is still there to replay. The run log is a delivery buffer and messages live in storage: once both expire, `observe()` returns 404 rather than replaying, and a client fetches the conversation from storage.
88
+ - Topics that don't belong to a single run or thread, such as work queues and application feeds, keep the transport's own idle TTL, seven days by default for [Redis Streams](https://mastra.ai/reference/pubsub/redis-streams) and [Valkey Streams](https://mastra.ai/reference/pubsub/valkey-streams). They need it: a grouped consumer that was offline must still find its backlog. Configure `streamIdleTtlMs` to change it, or set it to `0` to disable transport expiry. Lowering it also lowers the retention on run topics.
80
89
  - The in-memory cache holds 1,000 entries by default. Each run uses several entries (its event log, a counter and its ownership record), so heavy traffic evicts older runs sooner.
81
90
  - The server's observe and abort routes return 404 when a run's ownership record is evicted or expires. Evicted run events can't be replayed.
82
91
 
83
- Use a shared cache such as Redis, sized for your traffic, when runs must stay observable across servers or for long approval waits.
92
+ A run log recreated after its retention lapsed normally numbers above the indices it issued before. An attached observer then keeps receiving the new frames. Treat that as the common case rather than a guarantee: the built-in Redis, Valkey and in-memory caches derive the numbering from a clock, Convex numbers densely instead, and the fallback that detects a restarted log only recognizes one that restarts at zero. An observer attached across a log recreated below its cursor can miss new frames. Reattaching without the old offset can replay the entries still retained in the new log, while reusing that offset can skip them. Storage remains the source of truth for a run's messages. Use a shared cache such as Redis, sized for your traffic, when runs must stay observable across servers or for long approval waits.
84
93
 
85
94
  ## Follow a run
86
95
 
@@ -60,7 +60,9 @@ Extra scheduler instances add availability, not throughput. Each one polls stora
60
60
 
61
61
  ### Background task worker
62
62
 
63
- Executes agent tool calls marked with `background: { enabled: true }`. When an agent invokes a background tool, the API dispatches the task to this worker instead of blocking the response stream.
63
+ Executes agent tool calls marked with `background: { enabled: true }` without blocking the response stream.
64
+
65
+ A background tool call is bound to the agent run that made it, so it runs on the process that executes the agent loop. An API server with `MASTRA_WORKERS=false` doesn't hand its agents' tool calls to a dedicated background task worker: a durable agent runs the tool inline, and a regular agent returns a dispatch error as the tool result unless you pass `disableBackgroundTasks: true`. See [BackgroundTaskWorker](https://mastra.ai/reference/workers/overview).
64
66
 
65
67
  The background task worker manages concurrency limits, task lifecycle, and result delivery through the PubSub bus.
66
68
 
@@ -496,7 +496,7 @@ Every Mastra process with background tasks enabled runs its own manager. You can
496
496
  ### Deployment requirements
497
497
 
498
498
  - Every manager must use the same storage backend, and its `updateTask` must apply the write conditions atomically. Mastra's storage adapters do. In-memory storage is only shared within one process.
499
- - `leaseExpiresAt` is a timestamp written with the owner's clock and compared against the clock of the manager that reads it. Keep server clocks synchronized, for example with Network Time Protocol (NTP), to well under `leaseDurationMs`. If a reader's clock runs ahead by more than the lease, it can recover a task whose owner is still alive. If it runs behind, recovery is delayed. The startup scan recovers a task as soon as its lease has expired by the reader's clock. Follow-up scans wait about one second past the expiry to absorb small differences.
499
+ - `leaseExpiresAt` is a timestamp written with the owner's clock and compared against the clock of the manager that reads it. Keep server clocks synchronized, for example with Network Time Protocol (NTP), to well under `leaseDurationMs`. If a reader's clock runs ahead by more than the lease, it can recover a task whose owner is still alive. If it runs behind, recovery is delayed. The startup scan and the periodic check recover a task as soon as its lease has expired by the reader's clock. Follow-up scans wait about one second past the expiry to absorb small differences.
500
500
  - A longer [`leaseDurationMs`](https://mastra.ai/reference/configuration) delays recovery after a crash. A shorter one adds storage writes and makes it more likely that a stalled owner loses its lease while still running. The default is 30 seconds and the minimum is 3000 ms.
501
501
 
502
502
  ### Lease guarantees and repeated tool calls
@@ -519,17 +519,17 @@ Before a manager runs a task, it claims the task with a conditional write. The w
519
519
 
520
520
  While the task runs, the owner renews the lease every `leaseDurationMs / 3`, with a minimum of one second. Each renewal is conditional on the task still being `running` under the same owner. The task's final writes, such as `completed`, `failed`, `timed_out`, or `suspended`, carry the same condition, so a manager that lost the task can't overwrite the result of the manager that replaced it.
521
521
 
522
- The owner stops renewing when the task completes, fails, or suspends. On shutdown, the manager releases the leases it still holds, so other managers can recover those tasks without waiting for the lease to expire. A lease that isn't released, for example because the process crashed, expires on its own.
522
+ The owner stops renewing when the task completes, fails, or suspends. On shutdown, the manager releases the leases it still holds, so other managers can recover those tasks without waiting for the lease to expire. A running task with `maxRetries: 0` can't run again, so shutdown fails it with `Worker process terminated before task completed`, the same ending as a crash, rather than cancelling it. A lease that isn't released, for example because the process crashed, expires on its own.
523
523
 
524
524
  ### Recover a task from a dead owner
525
525
 
526
526
  A manager treats a `running` task as abandoned only after its lease expires.
527
527
 
528
- When `recoverStaleTasksOnStart` is `true`, the default, each manager that runs tasks scans for abandoned tasks on startup. If the scan finds a lease that hasn't expired yet, the manager scans again shortly after that lease expires, and repeats until no live lease is left. A task that a manager starts after that and then abandons waits for the next startup scan. For each task the scan recovers:
528
+ When `recoverStaleTasksOnStart` is `true`, the default, each manager that runs tasks scans for abandoned tasks on startup. If the scan finds a lease that hasn't expired yet, the manager scans again shortly after that lease expires, and repeats until no live lease is left. After startup, the manager also checks for running tasks with an expired lease every `leaseDurationMs`, so a task whose worker dies later is recovered without a restart. Each check reads up to `globalConcurrency` running tasks (at least 100, at most 1,000), which normally covers all of them, so the task is recovered within about one `leaseDurationMs` after its lease expires. When more tasks are running than that, for example because other servers use a higher `globalConcurrency`, each further page of running tasks adds one `leaseDurationMs`. For each task the scan recovers:
529
529
 
530
530
  - If the task's worker shut down gracefully, it returns to `pending` and is dispatched again without using a retry.
531
531
  - If the worker died and the task's `retryCount` is below `maxRetries`, it uses a retry, returns to `pending`, and is dispatched again.
532
- - Otherwise, it fails with `Worker process terminated before task completed`.
532
+ - Otherwise, it fails with `Worker process terminated before task completed`. The failure fires `task.failed` and `onTaskFailed` like any other failure.
533
533
 
534
534
  Only a crash counts against `maxRetries`, so a task that keeps taking its worker down stops after its retries are used, while a deploy doesn't use one.
535
535
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
10
10
 
11
- A durable agent wraps a regular [`Agent`](https://mastra.ai/docs/agents/overview) so the agentic loop runs inside a workflow. Events flow through [PubSub](https://mastra.ai/docs/server/pubsub), which means a client can disconnect and reconnect without missing chunks. The run state is persisted, so it survives process restarts.
11
+ A durable agent runs the [agentic loop](https://mastra.ai/docs/agents/overview) inside a workflow. Clients can reconnect over [PubSub](https://mastra.ai/docs/server/pubsub) and replay retained stream events. With persistent storage and recovery configured, the agent can continue from a checkpoint after a process restart.
12
12
 
13
13
  ## When to use durable agents
14
14
 
@@ -23,46 +23,42 @@ For short-lived, request-scoped calls where the client stays connected, a regula
23
23
 
24
24
  ## Quickstart
25
25
 
26
- Wrap an existing agent with `createDurableAgent()` from `@mastra/core/agent/durable`:
26
+ Set `durable.executionEngine` to `'default'` on your agent to run it in the current process. This example uses an `OPENAI_API_KEY` for the model:
27
27
 
28
28
  ```typescript
29
29
  import { Agent } from '@mastra/core/agent'
30
- import { createDurableAgent } from '@mastra/core/agent/durable'
31
30
 
32
- const agent = new Agent({
31
+ export const researcher = new Agent({
33
32
  id: 'researcher',
34
33
  name: 'Researcher',
35
34
  instructions: 'You research topics thoroughly.',
36
35
  model: 'openai/gpt-6.1-sol',
36
+ durable: { executionEngine: 'default' },
37
37
  })
38
-
39
- export const durableResearcher = createDurableAgent({ agent })
40
38
  ```
41
39
 
42
- Register the durable agent with Mastra and call `stream()`:
40
+ Register the agent with Mastra and call `stream()`:
43
41
 
44
42
  ```typescript
45
43
  import { Mastra } from '@mastra/core'
46
- import { durableResearcher } from './agents/researcher'
44
+ import { researcher } from './agents/researcher'
47
45
 
48
- const mastra = new Mastra({
49
- agents: { durableResearcher },
46
+ export const mastra = new Mastra({
47
+ agents: { researcher },
50
48
  })
51
49
 
52
- const { output, runId, cleanup } = await durableResearcher.stream(
53
- 'Research quantum computing advances in 2025',
54
- )
50
+ const output = await mastra
51
+ .getAgent('researcher')
52
+ .stream('Research quantum computing advances in 2025')
55
53
 
56
54
  for await (const chunk of output.fullStream) {
57
55
  // Process each chunk as it arrives
58
56
  }
59
-
60
- // Release PubSub subscriptions and clear the run from the registry.
61
- // If you skip this, an automatic cleanup timer fires after the stream ends.
62
- cleanup()
63
57
  ```
64
58
 
65
- The returned `runId` identifies the execution. Pass it to `observe()` to reconnect from a different client. Visit the [DurableAgent reference](https://mastra.ai/reference/agents/durable-agent) for the full configuration and method API.
59
+ The native `stream()` returns the model output directly. Use `output.runId` to [reconnect](#resumable-streams). With a wrapper, `stream()` returns a handle with the model output in `.output`. See the [wrapper example](https://mastra.ai/reference/agents/durable-agent).
60
+
61
+ To continue a run after a process restart, configure persistent storage and [crash recovery](#crash-recovery).
66
62
 
67
63
  ## How it works
68
64
 
@@ -76,32 +72,23 @@ A durable agent adds three layers on top of a regular agent:
76
72
 
77
73
  ## Execution variants
78
74
 
79
- Mastra provides three factory functions that produce durable agents. They differ in how the workflow is executed:
75
+ Choose the engine based on where the agent should run:
80
76
 
81
- | Factory | Package | Best for |
82
- | ---------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
83
- | `createDurableAgent()` | `@mastra/core` | Local development and single-process servers. You get a stream you can await directly. |
84
- | `createEventedAgent()` | `@mastra/core` | Background execution. The workflow starts without blocking, and you consume chunks through PubSub. Running it on several processes needs a [supported PubSub backend and storage adapter](https://mastra.ai/docs/server/pubsub). |
85
- | `createInngestAgent()` | `@mastra/inngest` | Production deployments. Inngest adds step memoization, retries, and a monitoring dashboard. |
77
+ | Native agent setting | Wrapper equivalent | Best for |
78
+ | ------------------------------------ | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
79
+ | `durable.executionEngine: 'default'` | `createDurableAgent()` from `@mastra/core/agent/durable` | Local development and single-process servers. You get a stream you can await directly. |
80
+ | `durable.executionEngine: 'evented'` | `createEventedAgent()` from `@mastra/core/agent/durable` | Runs in the background, and you can follow the run through PubSub. It can run in one process or across multiple processes with a [supported PubSub backend and storage adapter](https://mastra.ai/docs/server/pubsub). |
81
+ | No native setting | `createInngestAgent()` from `@mastra/inngest` | On Inngest, with step memoization, retries, and a monitoring dashboard. |
86
82
 
87
- All three return an object you register with `Mastra` the same way as a regular agent. `createDurableAgent()` and `createEventedAgent()` return class instances that extend `Agent`. `createInngestAgent()` returns a Proxy-backed object that forwards `Agent` methods to the underlying agent. When a signal wakes an idle thread, all three start that run with the durable `stream()`. `sendSignal()` and `sendNotificationSignal()` both work this way.
83
+ To set a default for registered native agents, use `durable.executionEngine` on [Mastra](https://mastra.ai/reference/core/mastra-class). An explicit agent setting overrides it. The choice is fixed at registration or first execution. Wrapper factories select their own engine without changing the wrapped agent's selection.
88
84
 
89
- ### In-process with `createDurableAgent()`
85
+ Before switching engines, stop sending new runs to the old engine and let its active runs finish. Resolve suspended runs on the old engine too. Don't rely on the new engine to resume or recover them.
90
86
 
91
- Wrap your agent and call `stream()`. You get a `DurableAgentStreamResult` back in the same process. No external infrastructure is required, so this is the fastest way to get started:
92
-
93
- ```typescript
94
- import { Agent } from '@mastra/core/agent'
95
- import { createDurableAgent } from '@mastra/core/agent/durable'
87
+ Register a wrapper with `Mastra` the same way as a regular agent. The Core wrappers return `Agent` subclasses. `createInngestAgent()` returns a proxy that forwards `Agent` methods to the underlying agent. When `sendSignal()` or `sendNotificationSignal()` wakes an idle thread, the registered agent starts a run with its configured engine.
96
88
 
97
- const agent = new Agent({
98
- id: 'helper',
99
- instructions: 'You are a helpful assistant.',
100
- model: 'openai/gpt-6.1-sol',
101
- })
89
+ ### In-process with `createDurableAgent()`
102
90
 
103
- export const durableHelper = createDurableAgent({ agent })
104
- ```
91
+ For wrapper setup, see [`createDurableAgent()`](https://mastra.ai/reference/agents/durable-agent) in the API reference.
105
92
 
106
93
  ### Fire-and-forget with `createEventedAgent()`
107
94
 
@@ -124,7 +111,9 @@ In one process, an evented agent runs on the default PubSub backend with no extr
124
111
 
125
112
  ### Resumable streams for stored agents
126
113
 
127
- Agents created with [`createStoredAgent()`](https://mastra.ai/reference/client-js/agents) use the `durable` field to configure resumable streams only. The server hydrates a plain `Agent` with stream publishing and replay enabled:
114
+ Stored agents inherit the server's `Mastra.durable.executionEngine` default when registered, unless their `durable` field is `false`. Loading a specific `versionId` of an already registered stored agent creates a separate instance that doesn't inherit the engine default. When no engine default applies, `durable: true` enables resumable streams without checkpointing.
115
+
116
+ Enable the stored agent's `durable` setting with [`createStoredAgent()`](https://mastra.ai/reference/client-js/agents):
128
117
 
129
118
  ```typescript
130
119
  await mastraClient.createStoredAgent({
@@ -136,7 +125,7 @@ await mastraClient.createStoredAgent({
136
125
  })
137
126
  ```
138
127
 
139
- `durable` also accepts `{ cleanupTimeoutMs }`. Cache and pubsub are inherited from the server's `Mastra` instance. Existing stored agents with `durable: true` now load with resumable streams but without durable execution or checkpoint recovery. To retain durable execution, define a code agent wrapped with `createDurableAgent({ agent })` and pass `maxSteps` and snapshot persistence options to the factory.
128
+ `durable` also accepts `{ cleanupTimeoutMs }`. Stored agents inherit the server's replay cache and PubSub transport. To select an engine per agent, use a [code-defined agent](#quickstart).
140
129
 
141
130
  ### Inngest-powered with `createInngestAgent()`
142
131
 
@@ -162,10 +151,10 @@ Visit the [`createInngestAgent()` reference](https://mastra.ai/reference/agents/
162
151
 
163
152
  ## Resumable streams
164
153
 
165
- Durable agents support resumable streams through PubSub and an event cache. When a client disconnects mid-stream, the cache continues storing events. The same client can reconnect by calling `observe()` with the `runId`:
154
+ Durable agents support resumable streams through PubSub and an event cache. When a client disconnects mid-stream, the cache continues storing events. To reconnect, pass the run ID to `observe()` and read the stream from the returned handle's `.output`:
166
155
 
167
156
  ```typescript
168
- const { output } = await durableResearcher.observe(runId)
157
+ const { output } = await mastra.getAgent('researcher').observe(runId)
169
158
 
170
159
  for await (const chunk of output.fullStream) {
171
160
  // Chunks from the run, including any missed while disconnected
@@ -176,12 +165,12 @@ Calling `observe(runId)` without an offset is the supported general reconnect fl
176
165
 
177
166
  The optional `offset` is a run-log position, which chunks report as `chunk.index`. To resume after a dropped connection, pass `index + 1` of the last chunk that has an `index`, or omit `offset` if nothing arrived. This works the same with `stream()` and `observe()`, over HTTP, and in `@mastra/client-js`. See [`observe(runId, options?)`](https://mastra.ai/reference/agents/durable-agent) for which chunks carry no index, structured output, and transport limits.
178
167
 
179
- Replay isn't a permanent execution archive. Events remain available only until [cleanup](#cleanup) clears them or the cache removes them. A workflow snapshot can't reconstruct cleared stream events, and disabling caching prevents historical replay.
168
+ Replay isn't a permanent execution archive. Events remain available only until [cleanup](#cleanup) clears them or the cache removes them. A workflow snapshot can't reconstruct cleared stream events, and disabling the replay cache doesn't disable history retained by a transport such as Redis Streams.
180
169
 
181
170
  Observing doesn't own the run. When the loop ends, or you leave it early with `break`, `return`, or an error, the observer unsubscribes and the run keeps going for anyone else watching it. To stop observing from outside the loop, for example when the client disconnects, call `detach()`:
182
171
 
183
172
  ```typescript
184
- const { output, detach } = await durableResearcher.observe(runId)
173
+ const { output, detach } = await mastra.getAgent('researcher').observe(runId)
185
174
 
186
175
  request.signal.addEventListener('abort', detach, { once: true })
187
176
 
@@ -255,11 +244,11 @@ Background tasks have their own execution lease, stored on each task record, sep
255
244
 
256
245
  ## Cleanup
257
246
 
258
- Every `stream()` and `observe()` call returns a `cleanup` function that tears the run down: it unsubscribes from PubSub, removes the run from the internal registry, and deletes the run's cached events so nobody can replay it afterward.
247
+ Call `cleanup()` from the process that started the run to release its resources and clear its cached stream events. Wrapper `stream()` and `observe()` handles expose `cleanup()`. On native durable stream output, use the optional `cleanup()` method on [`AgentStreamOutput`](https://mastra.ai/reference/agents/durable-agent).
259
248
 
260
249
  When you don't call `cleanup()` yourself, Mastra calls it `cleanupTimeoutMs` after the run finishes, errors, or is aborted. The default is 30 seconds, so completed-run replay is limited to that window unless you configure a different value or call `cleanup()` sooner. Detaching an observer or reaching a plain `idleTimeoutMs` doesn't start this timer. Set `cleanupTimeoutMs: 0` to turn the timer off. The cache's own TTL and eviction still apply.
261
250
 
262
- Call `cleanup()` from the process that started the run. To stop watching a run from `observe()`, use `detach()` or leave the loop instead.
251
+ To stop watching a run from `observe()` without clearing it, call `detach()` or leave the loop.
263
252
 
264
253
  ## Tool approval
265
254
 
@@ -331,7 +320,7 @@ export const mastra = new Mastra({
331
320
  })
332
321
  ```
333
322
 
334
- On startup, this discovers every registered durable agent with runs stuck in `running` status and re-drives them from the last persisted snapshot.
323
+ At boot, Mastra recovers `running` runs for registered durable agents from their last persisted snapshots. If a stored agent loads after boot recovery, follow the [manual recovery](#manual-recovery) steps.
335
324
 
336
325
  Recovery processes up to five agents concurrently, with up to five run waits per agent. Each wait covers both `recover()` setup and settlement of the whole recovered workflow and lasts at most 30 seconds. If it expires, the attempt continues in the background and frees a slot for another run. These limits bound waiting, not the number of live executions. Discovery and overridden custom recovery methods aren't bounded by this budget.
337
326
 
@@ -362,7 +351,9 @@ for (const run of recovered) {
362
351
  await durableAgent.recoverActiveRuns({ runId: 'run-abc-123' })
363
352
  ```
364
353
 
365
- `recoverAllDurableAgents()` returns counts and schedules eligible ownership re-checks itself. `recoverActiveRuns()` returns each run's outcome as `success`, `failed`, or `skipped`, and doesn't re-check skipped runs. A run skipped because another process drives it carries `retryAt`, the time after which its claim lapses unless renewed. A timed-out attempt instead returns `status: 'skipped'` with `reason: 'recovery-timeout'` and no `retryAt`, so Mastra doesn't automatically retry it. Only the `skipped` count includes this attempt; the `recovered`, `succeeded`, and `failed` counts exclude it even if it settles later.
354
+ To recover a stored agent that wasn't registered at boot, first load it with `await mastra.getEditor()?.agent.getById(agentId)` without a `versionId`. Once it loads, call `mastra.recoverAllDurableAgents()`.
355
+
356
+ `recoverActiveRuns()` reports `success`, `failed`, or `skipped` for each run. If a skipped run returns `retryAt`, schedule your own re-check when calling `recoverActiveRuns()` directly. `mastra.recoverAllDurableAgents()` schedules that re-check for you and counts timed-out attempts only as `skipped`.
366
357
 
367
358
  Manual recovery reads the same `running` checkpoints as automatic recovery. For a `DurableAgent` using the default snapshot policy with `recovery.durableAgents` set to `'off'`, in-flight runs are only checkpointed at step boundaries reached after `mastra.shutdown()` starts. A run that crashes before then, or doesn't reach a step boundary during the drain, has no checkpoint, so `listActiveRuns()` and `recoverActiveRuns()` don't find it. See [snapshot persistence](#snapshot-persistence).
368
359
 
@@ -98,7 +98,7 @@ export class HelpDeskImporter extends KnowledgeImporter({
98
98
 
99
99
  `htmlToMarkdown()` stands in for your own conversion. A few things the example relies on:
100
100
 
101
- - **Await every `ctx.items` call.** Items are buffered and sent in batches, so a call can wait for the previous batch to land.
101
+ - **Await every `ctx.items` call.** Items are buffered and sent in batches, so a call can wait for the previous batch to land. A batch is sent when 200 items are waiting, when you call `ctx.state.set()`, when `import` returns, or once the oldest waiting item has waited 30 seconds, so items from a slow source still land during the run. A batch sent on the timer carries only items: the cursor moves only with `ctx.state.set()`. If the run ends early, the next run resends those items from the saved cursor, and writing the same `sourceId` again is safe. If the host can't take a batch (an item with an empty `sourceId`, say), the run fails there and saves no cursor after it, even if you catch the error.
102
102
  - **`ctx.state.set()` saves the cursor with the items before it.** Call it after the items it covers, never before.
103
103
  - **Use `ctx.fetch` and watch `ctx.signal`.** The signal fires when the run is canceled or reaches its time limit. `ctx.fetch` always uses that signal. If you pass your own `signal`, for example `AbortSignal.timeout()`, it's combined with the run's: either one aborts the fetch, so a run that's canceled or out of time never leaves a fetch running. `ctx.fetch` doesn't retry, so handle rate limits and server errors yourself, for example by waiting for the source's `Retry-After` header before trying again.
104
104
  - **Throw `KnowledgeImporterSourceError` with the HTTP status** when the source fails. The run ends with a fixed error code, such as `source_auth_failed` for 401 or 403 and `source_rate_limited` for 429, and your error text stays in your own logs.
@@ -208,7 +208,7 @@ Platform adds these fields and grouping options:
208
208
  | `aggregateTraces()` | Supports `groupBy: ['projectId']` and `countDistinct.projectId`. |
209
209
  | `aggregateSpans()` | Supports `groupBy: ['projectId']`, but not `countDistinct.projectId`. |
210
210
 
211
- Data retention depends on your plan: 15 days for Free, 60 days for Starter, 180 days for Team, and custom retention for Enterprise. See [pricing](https://mastra.ai/pricing) for current plan limits.
211
+ All traces are retained for six months. This retention period is subject to change for all month-to-month plans. See [pricing](https://mastra.ai/pricing) for current plan limits.
212
212
 
213
213
  ### Other observability data
214
214
 
@@ -146,6 +146,7 @@ Use a remote or container sandbox when commands need a stronger boundary from th
146
146
  - [Railway](https://mastra.ai/integrations/sandboxes/railway)
147
147
  - [Fly.io Sprites](https://mastra.ai/integrations/sandboxes/sprites)
148
148
  - [Vercel](https://mastra.ai/integrations/sandboxes/vercel)
149
+ - [WBX Sandbox](https://mastra.ai/integrations/sandboxes/wbx)
149
150
 
150
151
  If Mastra doesn't support your sandbox provider, implement the [sandbox provider interface](https://mastra.ai/reference/workspace/sandbox) to add it.
151
152
 
@@ -107,7 +107,7 @@ export const mastra = new Mastra({
107
107
 
108
108
  ## Evented workflows and agents
109
109
 
110
- Workflows on the [evented execution engine](https://mastra.ai/docs/workflows/scheduled-workflows) and agents created with [`createEventedAgent()`](https://mastra.ai/docs/harness/durable-agents) advance a run one event at a time. Any worker can take the next event, which lets several processes share one run. That only holds when the deployment has both of the following:
110
+ Workflows on the [evented execution engine](https://mastra.ai/docs/workflows/scheduled-workflows) and agents using [evented durable execution](https://mastra.ai/docs/harness/durable-agents) advance a run one event at a time. Any worker can take the next event, which lets several processes share one run. That only holds when the deployment has both of the following:
111
111
 
112
112
  - **A PubSub backend that redelivers unacknowledged events**: When a worker stops in the middle of a step, the backend gives the step's event to another worker.
113
113
  - **A storage adapter with workflow step guards**: The backend can deliver the same event more than once, and the step guard keeps a later delivery from saving the step's result a second time. A step can still run more than once, so [make steps with side effects idempotent](https://mastra.ai/docs/workflows/overview).
@@ -498,9 +498,11 @@ workflow.restartAllActiveWorkflowRuns()
498
498
 
499
499
  Runs restart concurrently, up to `recovery.workflowConcurrency` at a time (default `5`). Set it to `1` in the Mastra config if your runs share side effects that must not run in parallel.
500
500
 
501
- To exclude a workflow from automatic boot-time restarts triggered by `Mastra.restartAllActiveWorkflowRuns()`, set `autoRestartActiveRuns: false` in the workflow's `options`. This is useful for workflows with side effects that must not be re-driven by a blanket restart. Durable agent workflows set this automatically because their recovery is owned by the opt-in `recovery.durableAgents: 'auto'` path.
501
+ To exclude a workflow from automatic boot-time restarts triggered by `Mastra.restartAllActiveWorkflowRuns()`, set `autoRestartActiveRuns: false` in the workflow's `options`. This is useful for workflows with side effects that must not be re-driven by a blanket restart. Such a workflow's runs also hold no storage lease, so their saves aren't refused after another instance restarts them. Durable agent workflows set this automatically because their recovery is owned by the opt-in `recovery.durableAgents: 'auto'` path.
502
502
 
503
- While a run executes, Mastra holds a storage lease on it and renews it in the background. `restart()` refuses to take over a run whose lease hasn't expired: it throws a `WORKFLOW_RESTART_RUN_OWNED` error and the sweep skips the run. The lease is advisory and doesn't fence writes. If a process stops renewing its lease but keeps executing a step, for example because its event loop is blocked for longer than the lease TTL, recovery can run that step a second time. `workflow.restartAllActiveWorkflowRuns()` skips such a run without a recheck, so call it after the lease expires if you need to recover that run. Storage adapters without run-ownership support keep the previous behavior and restart every active run.
503
+ While a run executes, Mastra holds a storage lease on it and renews it in the background. `restart()` refuses to take over a run whose lease hasn't expired: it throws a `WORKFLOW_RESTART_RUN_OWNED` error and the sweep skips the run. `workflow.restartAllActiveWorkflowRuns()` skips such a run without a recheck, so call it after the lease expires if you need to recover that run. Storage adapters without run-ownership support keep the previous behavior and restart every active run.
504
+
505
+ If a process stops renewing its lease but keeps executing, for example because its event loop is blocked for longer than the lease TTL, recovery on another instance can take the run over. From then on, storage refuses the stalled process's saves to the run, and its `start()`, `resume()`, `restart()` or `timeTravel()` call rejects with a `STORAGE_RUN_FENCE_CONFLICT` error. Over HTTP, a request that waits for such a run gets a 409 with that `code`. A run started with `startAsync()` that was already dispatched only logs a warning, and on `stream()`, `resumeStream()` and `timeTravelStream()` the stream closes and its `result` rejects with the same error. The step it was running can still finish, so recovery can run that step a second time. Keep steps idempotent, as described below. To see the run as the instance that took it over drives it, read it with `getWorkflowRunById()`. This applies to default-engine runs that hold a lease, on storage adapters with run-ownership support. Other runs save as before.
504
506
 
505
507
  `mastra.restartAllActiveWorkflowRuns()`, which the server calls on boot, restarts a default-engine run only once it stopped: no instance holds its lease, and neither the run nor its lease changed for `recovery.workflowGraceMs` (2 seconds by default). A run that's still running, or stopped more recently, is left to the [recovery loop](#recovery-loop).
506
508
 
@@ -520,7 +522,7 @@ For tools that agents call, see [make tools safe to repeat](https://mastra.ai/do
520
522
 
521
523
  ### Recovery loop
522
524
 
523
- `mastra.startWorkers()` also starts a recovery loop on an instance that runs the orchestration worker. Every `recovery.workflowScanIntervalMs` (60 seconds by default, give or take a fifth), it restarts the default-engine runs that stopped, by the same rule as `restartAllActiveWorkflowRuns()`. A run whose instance crashed is restarted at the first pass after its lease expired (`MASTRA_AGENT_THREAD_LEASE_TTL_MS`, 15 seconds by default) and `recovery.workflowGraceMs` passed. When a pass finds a run in its grace period, the next pass runs once that period ends, but no sooner than a second later.
525
+ `mastra.startWorkers()` also starts a recovery loop on an instance that runs the orchestration worker. Every `recovery.workflowScanIntervalMs` (60 seconds by default, give or take a fifth), it restarts the default-engine runs that stopped, by the same rule as `restartAllActiveWorkflowRuns()`. A run whose instance crashed is restarted at the first pass after its lease expired (the workflow's `leaseTtlMs`, 15 seconds by default) and `recovery.workflowGraceMs` passed. When a pass finds a run in its grace period, the next pass runs once that period ends, but no sooner than a second later.
524
526
 
525
527
  Instances that share a storage adapter elect one loop leader through a lease row in storage. Only the leader's loop lists runs. The loops of the other instances only try to take its place. The leader keeps the role until its `stopWorkers()` or `shutdown()` hands it back, or until its lease expires after a crash. With `restartAllActiveWorkflowRuns()` at boot, each instance still restarts its own stopped default-engine runs, whichever instance leads. Between boots, the loop recovers only the workflows the leader registers, so instances that register different workflows on one storage get loop recovery for the leader's workflows only and the others' runs at their next boot. A run the loop restarts executes on the leader.
526
528
 
@@ -532,6 +534,68 @@ export const mastra = new Mastra({
532
534
 
533
535
  The loop never restarts evented runs. A broker that redelivers unacknowledged events recovers them, and on other pubsubs `restartAllActiveWorkflowRuns()` restarts them at boot. The loop also leaves workflows that set `autoRestartActiveRuns: false` alone, and an instance that registers no other default-engine workflow never claims the leader row. It doesn't run when `recovery.workflows` is `'off'`, on an instance started with `workers: false` or a `MASTRA_WORKERS` filter without `orchestration`, or on a storage adapter without run-ownership support. A process that calls `restartAllActiveWorkflowRuns()` but never `startWorkers()` runs no loop.
534
536
 
537
+ ### Steps that block the event loop
538
+
539
+ A run's lease is renewed from the event loop of the process that runs it, every third of the lease. A step that blocks the event loop for longer than the lease (15 seconds by default) stops those renewals. Other instances then see the run as stopped: recovery restarts it elsewhere, and storage refuses the blocked process's result. If the step blocks every time, the next instance can lose the run the same way.
540
+
541
+ Keep the event loop free first. Move CPU-heavy or synchronous work to a worker thread, a child process or another service, or split it into chunks that yield between them:
542
+
543
+ ```typescript
544
+ import { Worker } from 'node:worker_threads'
545
+ import { createStep } from '@mastra/core/workflows'
546
+ import { z } from 'zod'
547
+
548
+ export const render = createStep({
549
+ id: 'render',
550
+ inputSchema: z.object({ pages: z.number() }),
551
+ outputSchema: z.object({ pdf: z.string() }),
552
+ execute: async ({ inputData }) =>
553
+ new Promise<{ pdf: string }>((resolve, reject) => {
554
+ const worker = new Worker(new URL('./render-worker.js', import.meta.url), {
555
+ workerData: inputData,
556
+ })
557
+ worker.once('message', resolve)
558
+ worker.once('error', reject)
559
+ }),
560
+ })
561
+ ```
562
+
563
+ The worker does the blocking work and sends the step's output back:
564
+
565
+ ```javascript
566
+ import { parentPort, workerData } from 'node:worker_threads'
567
+
568
+ // Synchronous work here blocks this thread only, not the event loop that renews the lease.
569
+ const pdf = `report with ${workerData.pages} pages`
570
+
571
+ parentPort.postMessage({ pdf })
572
+ ```
573
+
574
+ If the work has to block, split it into several steps that each block for well under half the lease, for example a third of it. On Postgres, two blocks can pass between renewals. Start each blocking step with `await new Promise(resolve => setImmediate(resolve))` too, because stores that don't wait on the network, such as the in-memory store or a local LibSQL file, give the renewal no other chance to run between steps.
575
+
576
+ Raise the lease only when neither is possible. Set `leaseTtlMs` on the workflow, or on one run. This example reuses the `render` step above:
577
+
578
+ ```typescript
579
+ import { createWorkflow } from '@mastra/core/workflows'
580
+ import { z } from 'zod'
581
+ import { render } from './render'
582
+
583
+ const report = createWorkflow({
584
+ id: 'report',
585
+ inputSchema: z.object({ pages: z.number() }),
586
+ outputSchema: z.object({ pdf: z.string() }),
587
+ options: { leaseTtlMs: 60_000 },
588
+ })
589
+ .then(render)
590
+ .commit()
591
+
592
+ const run = await report.createRun({ leaseTtlMs: 120_000 })
593
+ ```
594
+
595
+ A longer lease delays the recovery of an instance that crashed by the same amount. A run's own `leaseTtlMs` isn't saved with the run, so another instance that restarts it uses the workflow's.
596
+
597
+ When a restart takes over a run whose lease lapsed, it logs a warning and doubles the length of that lease, up to 8 times the run's `leaseTtlMs`. Doubling needs a storage adapter that reports when the lease last changed: the in-memory store, `@mastra/pg` and `@mastra/libsql` today. On other adapters with run-ownership support, the restart uses the base length. A process that went a whole lease without renewing, found by its next renewal or when the run ends, logs one warning per stall with how long that took. Either warning means a step can run again on another instance, so keep steps idempotent.
598
+
535
599
  ### Restarting an active workflow run with `restart()`
536
600
 
537
601
  Use `restart()` to restart an active workflow run from the last active step. This will resume execution from the last active step, and the workflow will continue from there.
@@ -149,6 +149,8 @@ Run Mastra as a standalone server and connect your Next.js frontend (with Assist
149
149
 
150
150
  Now, the Assistant UI frontend will send chat requests directly to your running Mastra server.
151
151
 
152
+ > **Note:** This setup doesn't save conversations in [Mastra memory](https://mastra.ai/docs/memory/overview). To save them, send a `memory` object with a `thread` ID for the conversation and a `resource` ID for the user with each request. Visit [Using Mastra Memory](https://mastra.ai/integrations/agentic-ui/ai-sdk-ui) for an example.
153
+
152
154
  6. You're ready to connect the pieces! Ensure both the Mastra server and the Assistant UI frontend are running. Start the Next.js development server:
153
155
 
154
156
  ```bash
@@ -164,6 +164,21 @@ import { Component, signal } from '@angular/core'
164
164
  import { Chat } from '@ai-sdk/angular'
165
165
  import { DefaultChatTransport } from 'ai'
166
166
 
167
+ // Replace with the signed-in user's ID from your auth provider
168
+ const RESOURCE_ID = 'example-user'
169
+
170
+ function getThreadId(): string {
171
+ const key = `mastra-thread-id:${RESOURCE_ID}`
172
+ let threadId = localStorage.getItem(key)
173
+ if (!threadId) {
174
+ threadId = crypto.randomUUID()
175
+ localStorage.setItem(key, threadId)
176
+ }
177
+ return threadId
178
+ }
179
+
180
+ const THREAD_ID = getThreadId()
181
+
167
182
  @Component({
168
183
  selector: 'app-root',
169
184
  imports: [JsonPipe],
@@ -268,6 +283,15 @@ export class App {
268
283
  readonly chat = new Chat({
269
284
  transport: new DefaultChatTransport({
270
285
  api: 'http://localhost:4111/chat/weather-agent',
286
+ prepareSendMessagesRequest: ({ messages }) => ({
287
+ body: {
288
+ messages: [messages[messages.length - 1]],
289
+ memory: {
290
+ thread: THREAD_ID,
291
+ resource: RESOURCE_ID,
292
+ },
293
+ },
294
+ }),
271
295
  }),
272
296
  })
273
297
 
@@ -293,6 +317,19 @@ It renders text parts as they arrive and shows tool calls in a collapsible `<det
293
317
 
294
318
  > **Note:** Older Angular projects may name the root component file `app.component.ts` and its class `AppComponent`. If you're using an existing project, keep its file and class names so the imports in `src/main.ts` continue to work.
295
319
 
320
+ ### Save the conversation in memory
321
+
322
+ The weather agent has [memory](https://mastra.ai/docs/memory/overview), but it only saves a conversation when a request names one. The `prepareSendMessagesRequest` function adds a `memory` object to every request:
323
+
324
+ - `thread` identifies the conversation. The component creates one ID and keeps it in `localStorage` under a key that includes the resource ID, so reloading the page continues the same conversation. Create a new ID to start a new conversation. Never reuse a thread ID for a different resource: Mastra rejects the request.
325
+ - `resource` identifies the user who owns the conversation. In a real app, take it from your authentication, such as the signed-in user's ID. Don't use one constant for every user in production, or all users share the same memory.
326
+
327
+ Mastra loads earlier messages from memory on the server. The transport only needs to send the newest message. Visit [Using Mastra Memory](https://mastra.ai/integrations/agentic-ui/ai-sdk-ui) for details.
328
+
329
+ > **Note:** A request body is under the client's control. In production, set the resource ID on the server from the authenticated user instead, as described in [Reserved keys](https://mastra.ai/docs/server/request-context).
330
+
331
+ After a reload, the chat starts empty even though the agent remembers the conversation. To show earlier messages, fetch them from `GET http://localhost:4111/api/memory/threads/<thread>/messages?agentId=weather-agent`, read the `messages` array from the response, convert that array with [`toAISdkMessages()`](https://mastra.ai/reference/ai-sdk/to-ai-sdk-messages) using `{ version: 'v7' }` to match the installed AI SDK version, and pass the result to the `Chat` constructor as `messages`.
332
+
296
333
  ## Test your agent
297
334
 
298
335
  To test your agent with the chat interface, run both the Mastra server and the Angular development server.
@@ -353,6 +390,8 @@ To test your agent with the chat interface, run both the Mastra server and the A
353
390
 
354
391
  4. Try asking about the weather. If your API key is set up correctly, you'll get a response
355
392
 
393
+ 5. Reload the page and ask which city you asked about. The agent answers from memory
394
+
356
395
  ## Next steps
357
396
 
358
397
  From here, you can extend the project with your own tools and logic:
@@ -198,8 +198,9 @@ import { toAISdkV5Messages } from '@mastra/ai-sdk/ui'
198
198
  import { createUIMessageStreamResponse } from 'ai'
199
199
  import { mastra } from '@/mastra'
200
200
 
201
- const THREAD_ID = 'example-user-id'
202
- const RESOURCE_ID = 'weather-chat'
201
+ const THREAD_ID = 'weather-chat'
202
+ // Replace with the signed-in user's ID from your auth provider
203
+ const RESOURCE_ID = 'example-user-id'
203
204
 
204
205
  export const POST: APIRoute = async ({ request }) => {
205
206
  const params = await request.json()
@@ -240,6 +241,8 @@ export const GET: APIRoute = async () => {
240
241
 
241
242
  The `POST` route accepts a prompt and streams the agent's response back in AI SDK format, while the `GET` route fetches message history from memory so the UI can be hydrated when the client reloads.
242
243
 
244
+ The `THREAD_ID` identifies the conversation, and the `RESOURCE_ID` identifies the user who owns it. Both are constants here, so the app has a single shared conversation. In a real app, take the resource ID from your authentication, such as the signed-in user's ID, and create a thread ID per conversation. Don't use one resource ID for every user in production, or all users share the same memory. The `GET` route must use the same IDs as the `POST` route to load the right history.
245
+
243
246
  ## Create a chat component
244
247
 
245
248
  Create `src/components/chat.tsx`: