@mastra/mcp-docs-server 0.0.0-a2a-20250421213654

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 (274) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +253 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +16 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +202 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  15. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +113 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +281 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +302 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  52. package/.docs/organized/changelogs/create-mastra.md +302 -0
  53. package/.docs/organized/changelogs/mastra.md +302 -0
  54. package/.docs/organized/code-examples/agent-network.md +282 -0
  55. package/.docs/organized/code-examples/agent.md +426 -0
  56. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  57. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  58. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  59. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  60. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  61. package/.docs/organized/code-examples/client-side-tools.md +69 -0
  62. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  63. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  64. package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
  65. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  66. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  67. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  68. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  69. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  70. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  71. package/.docs/organized/code-examples/quick-start.md +129 -0
  72. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  73. package/.docs/organized/code-examples/weather-agent.md +331 -0
  74. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  75. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  76. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  77. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  78. package/.docs/raw/agents/adding-tools.mdx +288 -0
  79. package/.docs/raw/agents/adding-voice.mdx +200 -0
  80. package/.docs/raw/agents/agent-memory.mdx +62 -0
  81. package/.docs/raw/agents/mcp-guide.mdx +215 -0
  82. package/.docs/raw/agents/overview.mdx +303 -0
  83. package/.docs/raw/agents/runtime-variables.mdx +137 -0
  84. package/.docs/raw/community/discord.mdx +12 -0
  85. package/.docs/raw/community/licensing.mdx +63 -0
  86. package/.docs/raw/deployment/client.mdx +120 -0
  87. package/.docs/raw/deployment/deployment.mdx +127 -0
  88. package/.docs/raw/deployment/overview.mdx +63 -0
  89. package/.docs/raw/deployment/server.mdx +282 -0
  90. package/.docs/raw/evals/custom-eval.mdx +22 -0
  91. package/.docs/raw/evals/overview.mdx +95 -0
  92. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  93. package/.docs/raw/evals/textual-evals.mdx +54 -0
  94. package/.docs/raw/faq/index.mdx +63 -0
  95. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  96. package/.docs/raw/frameworks/next-js.mdx +238 -0
  97. package/.docs/raw/getting-started/installation.mdx +442 -0
  98. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  99. package/.docs/raw/getting-started/model-capability.mdx +11 -0
  100. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  101. package/.docs/raw/index.mdx +22 -0
  102. package/.docs/raw/integrations/index.mdx +213 -0
  103. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  104. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  105. package/.docs/raw/local-dev/mastra-dev.mdx +124 -0
  106. package/.docs/raw/mastra-cloud/deploying.mdx +136 -0
  107. package/.docs/raw/mastra-cloud/observability.mdx +163 -0
  108. package/.docs/raw/mastra-cloud/overview.mdx +57 -0
  109. package/.docs/raw/mastra-cloud/setting-up.mdx +122 -0
  110. package/.docs/raw/memory/memory-processors.mdx +131 -0
  111. package/.docs/raw/memory/overview.mdx +119 -0
  112. package/.docs/raw/memory/semantic-recall.mdx +126 -0
  113. package/.docs/raw/memory/working-memory.mdx +87 -0
  114. package/.docs/raw/observability/logging.mdx +38 -0
  115. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  116. package/.docs/raw/observability/tracing.mdx +115 -0
  117. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  118. package/.docs/raw/rag/overview.mdx +85 -0
  119. package/.docs/raw/rag/retrieval.mdx +365 -0
  120. package/.docs/raw/rag/vector-databases.mdx +340 -0
  121. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  122. package/.docs/raw/reference/agents/generate.mdx +334 -0
  123. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  124. package/.docs/raw/reference/agents/stream.mdx +369 -0
  125. package/.docs/raw/reference/cli/build.mdx +55 -0
  126. package/.docs/raw/reference/cli/dev.mdx +134 -0
  127. package/.docs/raw/reference/cli/init.mdx +43 -0
  128. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  129. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  130. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  131. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  132. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  133. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  134. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  135. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  136. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  137. package/.docs/raw/reference/deployer/cloudflare.mdx +212 -0
  138. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  139. package/.docs/raw/reference/deployer/netlify.mdx +116 -0
  140. package/.docs/raw/reference/deployer/vercel.mdx +122 -0
  141. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  142. package/.docs/raw/reference/evals/bias.mdx +186 -0
  143. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  144. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  145. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  146. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  147. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  148. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  149. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  150. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  151. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  152. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  153. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  154. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  155. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  156. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  157. package/.docs/raw/reference/index.mdx +12 -0
  158. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  159. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  160. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  161. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  162. package/.docs/raw/reference/memory/query.mdx +167 -0
  163. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  164. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  165. package/.docs/raw/reference/observability/logger.mdx +55 -0
  166. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  167. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  168. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  169. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  170. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  171. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  172. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  173. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  174. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  175. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  176. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  177. package/.docs/raw/reference/rag/astra.mdx +258 -0
  178. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  179. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  180. package/.docs/raw/reference/rag/document.mdx +127 -0
  181. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  182. package/.docs/raw/reference/rag/extract-params.mdx +249 -0
  183. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  184. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  185. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  186. package/.docs/raw/reference/rag/pg.mdx +501 -0
  187. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  188. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  189. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  190. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  191. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  192. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  193. package/.docs/raw/reference/storage/cloudflare-d1.mdx +89 -0
  194. package/.docs/raw/reference/storage/cloudflare.mdx +93 -0
  195. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  196. package/.docs/raw/reference/storage/postgresql.mdx +93 -0
  197. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  198. package/.docs/raw/reference/tools/client.mdx +321 -0
  199. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  200. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  201. package/.docs/raw/reference/tools/mcp-configuration.mdx +222 -0
  202. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  203. package/.docs/raw/reference/voice/azure.mdx +215 -0
  204. package/.docs/raw/reference/voice/cloudflare.mdx +152 -0
  205. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  206. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  207. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  208. package/.docs/raw/reference/voice/google.mdx +198 -0
  209. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  210. package/.docs/raw/reference/voice/murf.mdx +251 -0
  211. package/.docs/raw/reference/voice/openai-realtime.mdx +432 -0
  212. package/.docs/raw/reference/voice/openai.mdx +168 -0
  213. package/.docs/raw/reference/voice/playai.mdx +159 -0
  214. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  215. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  216. package/.docs/raw/reference/voice/voice.addInstructions.mdx +70 -0
  217. package/.docs/raw/reference/voice/voice.addTools.mdx +77 -0
  218. package/.docs/raw/reference/voice/voice.answer.mdx +69 -0
  219. package/.docs/raw/reference/voice/voice.close.mdx +56 -0
  220. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  221. package/.docs/raw/reference/voice/voice.events.mdx +80 -0
  222. package/.docs/raw/reference/voice/voice.getSpeakers.mdx +283 -0
  223. package/.docs/raw/reference/voice/voice.listen.mdx +198 -0
  224. package/.docs/raw/reference/voice/voice.off.mdx +72 -0
  225. package/.docs/raw/reference/voice/voice.on.mdx +129 -0
  226. package/.docs/raw/reference/voice/voice.send.mdx +81 -0
  227. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  228. package/.docs/raw/reference/voice/voice.updateConfig.mdx +87 -0
  229. package/.docs/raw/reference/workflows/after.mdx +88 -0
  230. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  231. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  232. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  233. package/.docs/raw/reference/workflows/else.mdx +72 -0
  234. package/.docs/raw/reference/workflows/events.mdx +305 -0
  235. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  236. package/.docs/raw/reference/workflows/if.mdx +107 -0
  237. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  238. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  239. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  240. package/.docs/raw/reference/workflows/start.mdx +84 -0
  241. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  242. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  243. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  244. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  245. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  246. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  247. package/.docs/raw/reference/workflows/then.mdx +74 -0
  248. package/.docs/raw/reference/workflows/until.mdx +165 -0
  249. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  250. package/.docs/raw/reference/workflows/while.mdx +168 -0
  251. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  252. package/.docs/raw/storage/overview.mdx +378 -0
  253. package/.docs/raw/voice/overview.mdx +816 -0
  254. package/.docs/raw/voice/speech-to-speech.mdx +73 -0
  255. package/.docs/raw/voice/speech-to-text.mdx +84 -0
  256. package/.docs/raw/voice/text-to-speech.mdx +89 -0
  257. package/.docs/raw/workflows/control-flow.mdx +778 -0
  258. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  259. package/.docs/raw/workflows/error-handling.mdx +183 -0
  260. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  261. package/.docs/raw/workflows/overview.mdx +170 -0
  262. package/.docs/raw/workflows/runtime-variables.mdx +153 -0
  263. package/.docs/raw/workflows/steps.mdx +108 -0
  264. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  265. package/.docs/raw/workflows/variables.mdx +313 -0
  266. package/LICENSE.md +46 -0
  267. package/README.md +129 -0
  268. package/dist/_tsup-dts-rollup.d.ts +140 -0
  269. package/dist/chunk-HYPVNJL7.js +194 -0
  270. package/dist/prepare-docs/prepare.d.ts +1 -0
  271. package/dist/prepare-docs/prepare.js +1 -0
  272. package/dist/stdio.d.ts +1 -0
  273. package/dist/stdio.js +650 -0
  274. package/package.json +60 -0
@@ -0,0 +1,352 @@
1
+ # Nested Workflows
2
+
3
+ Mastra allows you to use workflows as steps within other workflows, enabling you to create modular and reusable workflow components. This feature helps in organizing complex workflows into smaller, manageable pieces and promotes code reuse.
4
+
5
+ It is also visually easier to understand the flow of a workflow when you can see the nested workflows as steps in the parent workflow.
6
+
7
+ ## Basic Usage
8
+
9
+ You can use a workflow as a step directly in another workflow using the `step()` method:
10
+
11
+ ```typescript
12
+ // Create a nested workflow
13
+ const nestedWorkflow = new Workflow({ name: "nested-workflow" })
14
+ .step(stepA)
15
+ .then(stepB)
16
+ .commit();
17
+
18
+ // Use the nested workflow in a parent workflow
19
+ const parentWorkflow = new Workflow({ name: "parent-workflow" })
20
+ .step(nestedWorkflow, {
21
+ variables: {
22
+ city: {
23
+ step: "trigger",
24
+ path: "myTriggerInput",
25
+ },
26
+ },
27
+ })
28
+ .then(stepC)
29
+ .commit();
30
+ ```
31
+
32
+ When a workflow is used as a step:
33
+
34
+ - It is automatically converted to a step using the workflow's name as the step ID
35
+ - The workflow's results are available in the parent workflow's context
36
+ - The nested workflow's steps are executed in their defined order
37
+
38
+ ## Accessing Results
39
+
40
+ Results from a nested workflow are available in the parent workflow's context under the nested workflow's name. The results include all step outputs from the nested workflow:
41
+
42
+ ```typescript
43
+ const { results } = await parentWorkflow.start();
44
+ // Access nested workflow results
45
+ const nestedWorkflowResult = results["nested-workflow"];
46
+ if (nestedWorkflowResult.status === "success") {
47
+ const nestedResults = nestedWorkflowResult.output.results;
48
+ }
49
+ ```
50
+
51
+ ## Control Flow with Nested Workflows
52
+
53
+ Nested workflows support all the control flow features available to regular steps:
54
+
55
+ ### Parallel Execution
56
+
57
+ Multiple nested workflows can be executed in parallel:
58
+
59
+ ```typescript
60
+ parentWorkflow
61
+ .step(nestedWorkflowA)
62
+ .step(nestedWorkflowB)
63
+ .after([nestedWorkflowA, nestedWorkflowB])
64
+ .step(finalStep);
65
+ ```
66
+
67
+ Or using `step()` with an array of workflows:
68
+
69
+ ```typescript
70
+ parentWorkflow.step([nestedWorkflowA, nestedWorkflowB]).then(finalStep);
71
+ ```
72
+
73
+ In this case, `then()` will implicitly wait for all the workflows to finish before executing the final step.
74
+
75
+ ### If-Else Branching
76
+
77
+ Nested workflows can be used in if-else branches using the new syntax that accepts both branches as arguments:
78
+
79
+ ```typescript
80
+ // Create nested workflows for different paths
81
+ const workflowA = new Workflow({ name: "workflow-a" })
82
+ .step(stepA1)
83
+ .then(stepA2)
84
+ .commit();
85
+
86
+ const workflowB = new Workflow({ name: "workflow-b" })
87
+ .step(stepB1)
88
+ .then(stepB2)
89
+ .commit();
90
+
91
+ // Use the new if-else syntax with nested workflows
92
+ parentWorkflow
93
+ .step(initialStep)
94
+ .if(
95
+ async ({ context }) => {
96
+ // Your condition here
97
+ return someCondition;
98
+ },
99
+ workflowA, // if branch
100
+ workflowB, // else branch
101
+ )
102
+ .then(finalStep)
103
+ .commit();
104
+ ```
105
+
106
+ The new syntax is more concise and clearer when working with nested workflows. When the condition is:
107
+
108
+ - `true`: The first workflow (if branch) is executed
109
+ - `false`: The second workflow (else branch) is executed
110
+
111
+ The skipped workflow will have a status of `skipped` in the results:
112
+
113
+ The `.then(finalStep)` call following the if-else block will merge the if and else branches back into a single execution path.
114
+
115
+ ### Looping
116
+
117
+ Nested workflows can use `.until()` and `.while()` loops same as any other step. One interesting new pattern is to pass a workflow directly as the loop-back argument to keep executing that nested workflow until something is true about its results:
118
+
119
+ ```typescript
120
+ parentWorkflow
121
+ .step(firstStep)
122
+ .while(
123
+ ({ context }) =>
124
+ context.getStepResult("nested-workflow").output.results.someField ===
125
+ "someValue",
126
+ nestedWorkflow,
127
+ )
128
+ .step(finalStep)
129
+ .commit();
130
+ ```
131
+
132
+ ## Watching Nested Workflows
133
+
134
+ You can watch the state changes of nested workflows using the `watch` method on the parent workflow. This is useful for monitoring the progress and state transitions of complex workflows:
135
+
136
+ ```typescript
137
+ const parentWorkflow = new Workflow({ name: "parent-workflow" })
138
+ .step([nestedWorkflowA, nestedWorkflowB])
139
+ .then(finalStep)
140
+ .commit();
141
+
142
+ const run = parentWorkflow.createRun();
143
+ const unwatch = parentWorkflow.watch((state) => {
144
+ console.log("Current state:", state.value);
145
+ // Access nested workflow states in state.context
146
+ });
147
+
148
+ await run.start();
149
+ unwatch(); // Stop watching when done
150
+ ```
151
+
152
+ ## Suspending and Resuming
153
+
154
+ Nested workflows support suspension and resumption, allowing you to pause and continue workflow execution at specific points. You can suspend either the entire nested workflow or specific steps within it:
155
+
156
+ ```typescript
157
+ // Define a step that may need to suspend
158
+ const suspendableStep = new Step({
159
+ id: "other",
160
+ description: "Step that may need to suspend",
161
+ execute: async ({ context, suspend }) => {
162
+ if (!wasSuspended) {
163
+ wasSuspended = true;
164
+ await suspend();
165
+ }
166
+ return { other: 26 };
167
+ },
168
+ });
169
+
170
+ // Create a nested workflow with suspendable steps
171
+ const nestedWorkflow = new Workflow({ name: "nested-workflow-a" })
172
+ .step(startStep)
173
+ .then(suspendableStep)
174
+ .then(finalStep)
175
+ .commit();
176
+
177
+ // Use in parent workflow
178
+ const parentWorkflow = new Workflow({ name: "parent-workflow" })
179
+ .step(beginStep)
180
+ .then(nestedWorkflow)
181
+ .then(lastStep)
182
+ .commit();
183
+
184
+ // Start the workflow
185
+ const run = parentWorkflow.createRun();
186
+ const { runId, results } = await run.start({ triggerData: { startValue: 1 } });
187
+
188
+ // Check if a specific step in the nested workflow is suspended
189
+ if (results["nested-workflow-a"].output.results.other.status === "suspended") {
190
+ // Resume the specific suspended step using dot notation
191
+ const resumedResults = await run.resume({
192
+ stepId: "nested-workflow-a.other",
193
+ context: { startValue: 1 },
194
+ });
195
+
196
+ // The resumed results will contain the completed nested workflow
197
+ expect(resumedResults.results["nested-workflow-a"].output.results).toEqual({
198
+ start: { output: { newValue: 1 }, status: "success" },
199
+ other: { output: { other: 26 }, status: "success" },
200
+ final: { output: { finalValue: 27 }, status: "success" },
201
+ });
202
+ }
203
+ ```
204
+
205
+ When resuming a nested workflow:
206
+
207
+ - Use the nested workflow's name as the `stepId` when calling `resume()` to resume the entire workflow
208
+ - Use dot notation (`nested-workflow.step-name`) to resume a specific step within the nested workflow
209
+ - The nested workflow will continue from the suspended step with the provided context
210
+ - You can check the status of specific steps in the nested workflow's results using `results["nested-workflow"].output.results`
211
+
212
+ ## Result Schemas and Mapping
213
+
214
+ Nested workflows can define their result schema and mapping, which helps in type safety and data transformation. This is particularly useful when you want to ensure the nested workflow's output matches a specific structure or when you need to transform the results before they're used in the parent workflow.
215
+
216
+ ```typescript
217
+ // Create a nested workflow with result schema and mapping
218
+ const nestedWorkflow = new Workflow({
219
+ name: "nested-workflow",
220
+ result: {
221
+ schema: z.object({
222
+ total: z.number(),
223
+ items: z.array(
224
+ z.object({
225
+ id: z.string(),
226
+ value: z.number(),
227
+ }),
228
+ ),
229
+ }),
230
+ mapping: {
231
+ // Map values from step results using variables syntax
232
+ total: { step: "step-a", path: "count" },
233
+ items: { step: "step-b", path: "items" },
234
+ },
235
+ },
236
+ })
237
+ .step(stepA)
238
+ .then(stepB)
239
+ .commit();
240
+
241
+ // Use in parent workflow with type-safe results
242
+ const parentWorkflow = new Workflow({ name: "parent-workflow" })
243
+ .step(nestedWorkflow)
244
+ .then(async ({ context }) => {
245
+ const result = context.getStepResult("nested-workflow");
246
+ // TypeScript knows the structure of result
247
+ console.log(result.total); // number
248
+ console.log(result.items); // Array<{ id: string, value: number }>
249
+ return { success: true };
250
+ })
251
+ .commit();
252
+ ```
253
+
254
+ ## Best Practices
255
+
256
+ 1. **Modularity**: Use nested workflows to encapsulate related steps and create reusable workflow components.
257
+ 2. **Naming**: Give nested workflows descriptive names as they will be used as step IDs in the parent workflow.
258
+ 3. **Error Handling**: Nested workflows propagate their errors to the parent workflow, so handle errors appropriately.
259
+ 4. **State Management**: Each nested workflow maintains its own state but can access the parent workflow's context.
260
+ 5. **Suspension**: When using suspension in nested workflows, consider the entire workflow's state and handle resumption appropriately.
261
+
262
+ ## Example
263
+
264
+ Here's a complete example showing various features of nested workflows:
265
+
266
+ ```typescript
267
+ const workflowA = new Workflow({
268
+ name: "workflow-a",
269
+ result: {
270
+ schema: z.object({
271
+ activities: z.string(),
272
+ }),
273
+ mapping: {
274
+ activities: {
275
+ step: planActivities,
276
+ path: "activities",
277
+ },
278
+ },
279
+ },
280
+ })
281
+ .step(fetchWeather)
282
+ .then(planActivities)
283
+ .commit();
284
+
285
+ const workflowB = new Workflow({
286
+ name: "workflow-b",
287
+ result: {
288
+ schema: z.object({
289
+ activities: z.string(),
290
+ }),
291
+ mapping: {
292
+ activities: {
293
+ step: planActivities,
294
+ path: "activities",
295
+ },
296
+ },
297
+ },
298
+ })
299
+ .step(fetchWeather)
300
+ .then(planActivities)
301
+ .commit();
302
+
303
+ const weatherWorkflow = new Workflow({
304
+ name: "weather-workflow",
305
+ triggerSchema: z.object({
306
+ cityA: z.string().describe("The city to get the weather for"),
307
+ cityB: z.string().describe("The city to get the weather for"),
308
+ }),
309
+ result: {
310
+ schema: z.object({
311
+ activitiesA: z.string(),
312
+ activitiesB: z.string(),
313
+ }),
314
+ mapping: {
315
+ activitiesA: {
316
+ step: workflowA,
317
+ path: "result.activities",
318
+ },
319
+ activitiesB: {
320
+ step: workflowB,
321
+ path: "result.activities",
322
+ },
323
+ },
324
+ },
325
+ })
326
+ .step(workflowA, {
327
+ variables: {
328
+ city: {
329
+ step: "trigger",
330
+ path: "cityA",
331
+ },
332
+ },
333
+ })
334
+ .step(workflowB, {
335
+ variables: {
336
+ city: {
337
+ step: "trigger",
338
+ path: "cityB",
339
+ },
340
+ },
341
+ });
342
+
343
+ weatherWorkflow.commit();
344
+ ```
345
+
346
+ In this example:
347
+
348
+ 1. We define schemas for type safety across all workflows
349
+ 2. Each step has proper input and output schemas
350
+ 3. The nested workflows have their own trigger schemas and result mappings
351
+ 4. Data is passed through using variables syntax in the `.step()` calls
352
+ 5. The main workflow combines data from both nested workflows
@@ -0,0 +1,170 @@
1
+ ---
2
+ title: "Handling Complex LLM Operations | Workflows | Mastra"
3
+ description: "Workflows in Mastra help you orchestrate complex sequences of operations with features like branching, parallel execution, resource suspension, and more."
4
+ ---
5
+
6
+ # Handling Complex LLM Operations with Workflows
7
+
8
+ Workflows in Mastra help you orchestrate complex sequences of operations with features like branching, parallel execution, resource suspension, and more.
9
+
10
+ ## When to use workflows
11
+
12
+ Most AI applications need more than a single call to a language model. You may want to run multiple steps, conditionally skip certain paths, or even pause execution altogether until you receive user input. Sometimes your agent tool calling is not accurate enough.
13
+
14
+ Mastra's workflow system provides:
15
+
16
+ - A standardized way to define steps and link them together.
17
+ - Support for both simple (linear) and advanced (branching, parallel) paths.
18
+ - Debugging and observability features to track each workflow run.
19
+
20
+ ## Example
21
+
22
+ To create a workflow, you define one or more steps, link them, and then commit the workflow before starting it.
23
+
24
+ ### Breaking Down the Workflow
25
+
26
+ Let's examine each part of the workflow creation process:
27
+
28
+ #### 1. Creating the Workflow
29
+
30
+ Here's how you define a workflow in Mastra. The `name` field determines the workflow's API endpoint (`/workflows/$NAME/`), while the `triggerSchema` defines the structure of the workflow's trigger data:
31
+
32
+ ```ts filename="src/mastra/workflow/index.ts"
33
+ const myWorkflow = new Workflow({
34
+ name: "my-workflow",
35
+ triggerSchema: z.object({
36
+ inputValue: z.number(),
37
+ }),
38
+ });
39
+ ```
40
+
41
+ #### 2. Defining Steps
42
+
43
+ Now, we'll define the workflow's steps. Each step can have its own input and output schemas. Here, `stepOne` doubles an input value, and `stepTwo` increments that result if `stepOne` was successful. (To keep things simple, we aren't making any LLM calls in this example):
44
+
45
+ ```ts filename="src/mastra/workflow/index.ts"
46
+ const stepOne = new Step({
47
+ id: "stepOne",
48
+ outputSchema: z.object({
49
+ doubledValue: z.number(),
50
+ }),
51
+ execute: async ({ context }) => {
52
+ const doubledValue = context.triggerData.inputValue * 2;
53
+ return { doubledValue };
54
+ },
55
+ });
56
+
57
+ const stepTwo = new Step({
58
+ id: "stepTwo",
59
+ execute: async ({ context }) => {
60
+ const doubledValue = context.getStepResult(stepOne)?.doubledValue;
61
+ if (!doubledValue) {
62
+ return { incrementedValue: 0 };
63
+ }
64
+ return {
65
+ incrementedValue: doubledValue + 1,
66
+ };
67
+ },
68
+ });
69
+ ```
70
+
71
+ #### 3. Linking Steps
72
+
73
+ Now, let's create the control flow, and "commit" (finalize the workflow). In this case, `stepOne` runs first and is followed by `stepTwo`.
74
+
75
+ ```ts filename="src/mastra/workflow/index.ts"
76
+ myWorkflow.step(stepOne).then(stepTwo).commit();
77
+ ```
78
+
79
+ ### Register the Workflow
80
+
81
+ Register your workflow with Mastra to enable logging and telemetry:
82
+
83
+ ```ts showLineNumbers filename="src/mastra/index.ts"
84
+ import { Mastra } from "@mastra/core";
85
+
86
+ export const mastra = new Mastra({
87
+ workflows: { myWorkflow },
88
+ });
89
+ ```
90
+
91
+ The workflow can also have the mastra instance injected into the context in the case where you need to create dynamic workflows:
92
+
93
+ ```ts filename="src/mastra/workflow/index.ts"
94
+ import { Mastra } from "@mastra/core";
95
+
96
+ const mastra = new Mastra();
97
+
98
+ const myWorkflow = new Workflow({
99
+ name: "my-workflow",
100
+ mastra,
101
+ });
102
+ ```
103
+
104
+ ### Executing the Workflow
105
+
106
+ Execute your workflow programmatically or via API:
107
+
108
+ ```ts showLineNumbers filename="src/mastra/run-workflow.ts" copy
109
+ import { mastra } from "./index";
110
+
111
+ // Get the workflow
112
+ const myWorkflow = mastra.getWorkflow("myWorkflow");
113
+ const { runId, start } = myWorkflow.createRun();
114
+
115
+ // Start the workflow execution
116
+ await start({ triggerData: { inputValue: 45 } });
117
+ ```
118
+
119
+ Or use the API (requires running `mastra dev`):
120
+
121
+ // Create workflow run
122
+
123
+ ```bash
124
+ curl --location 'http://localhost:4111/api/workflows/myWorkflow/start-async' \
125
+ --header 'Content-Type: application/json' \
126
+ --data '{
127
+ "inputValue": 45
128
+ }'
129
+ ```
130
+
131
+ This example shows the essentials: define your workflow, add steps, commit the workflow, then execute it.
132
+
133
+ ## Defining Steps
134
+
135
+ The basic building block of a workflow [is a step](./steps.mdx). Steps are defined using schemas for inputs and outputs, and can fetch prior step results.
136
+
137
+ ## Control Flow
138
+
139
+ Workflows let you define a [control flow](./control-flow.mdx) to chain steps together in with parallel steps, branching paths, and more.
140
+
141
+ ## Workflow Variables
142
+
143
+ When you need to map data between steps or create dynamic data flows, [workflow variables](./variables.mdx) provide a powerful mechanism for passing information from one step to another and accessing nested properties within step outputs.
144
+
145
+ ## Suspend and Resume
146
+
147
+ When you need to pause execution for external data, user input, or asynchronous events, Mastra [supports suspension at any step](./suspend-and-resume.mdx), persisting the state of the workflow so you can resume it later.
148
+
149
+ ## Observability and Debugging
150
+
151
+ Mastra workflows automatically [log the input and output of each step within a workflow run](../../reference/observability/otel-config.mdx), allowing you to send this data to your preferred logging, telemetry, or observability tools.
152
+
153
+ You can:
154
+
155
+ - Track the status of each step (e.g., `success`, `error`, or `suspended`).
156
+ - Store run-specific metadata for analysis.
157
+ - Integrate with third-party observability platforms like Datadog or New Relic by forwarding logs.
158
+
159
+ ```
160
+
161
+ ## More Resources
162
+
163
+ - The [Workflow Guide](../guides/ai-recruiter.mdx) in the Guides section is a tutorial that covers the main concepts.
164
+ - [Sequential Steps workflow example](../../examples/workflows/sequential-steps.mdx)
165
+ - [Parallel Steps workflow example](../../examples/workflows/parallel-steps.mdx)
166
+ - [Branching Paths workflow example](../../examples/workflows/branching-paths.mdx)
167
+ - [Workflow Variables example](../../examples/workflows/workflow-variables.mdx)
168
+ - [Cyclical Dependencies workflow example](../../examples/workflows/cyclical-dependencies.mdx)
169
+ - [Suspend and Resume workflow example](../../examples/workflows/suspend-and-resume.mdx)
170
+ ```
@@ -0,0 +1,153 @@
1
+ ---
2
+ title: "Runtime variables - dependency injection | Workflows | Mastra Docs"
3
+ description: Learn how to use Mastra's dependency injection system to provide runtime configuration to workflows and steps.
4
+ ---
5
+
6
+ # Workflow Runtime Variables
7
+
8
+ Mastra provides a powerful dependency injection system that enables you to configure your workflows and steps with runtime variables. This feature is essential for creating flexible and reusable workflows that can adapt their behavior based on runtime configuration.
9
+
10
+ ## Overview
11
+
12
+ The dependency injection system allows you to:
13
+
14
+ 1. Pass runtime configuration variables to workflows through a type-safe container
15
+ 2. Access these variables within step execution contexts
16
+ 3. Modify workflow behavior without changing the underlying code
17
+ 4. Share configuration across multiple steps within the same workflow
18
+
19
+ ## Basic Usage
20
+
21
+ ```typescript
22
+ const myWorkflow = mastra.getWorkflow("myWorkflow");
23
+ const { runId, start, resume } = myWorkflow.createRun();
24
+
25
+ // Define your container's type structure
26
+ type WorkflowContainer = {
27
+ multiplier: number;
28
+ }
29
+
30
+ const container = new Container<WorkflowContainer>();
31
+ container.set("multiplier", 5);
32
+
33
+ // Start the workflow execution with container
34
+ await start({
35
+ triggerData: { inputValue: 45 },
36
+ container
37
+ });
38
+ ```
39
+
40
+ ## Using with REST API
41
+
42
+ Here's how to dynamically set a multiplier value from an HTTP header:
43
+
44
+ ```typescript filename="src/index.ts"
45
+ import { Mastra } from "@mastra/core";
46
+ import { Container } from "@mastra/core/di";
47
+ import { workflow as myWorkflow } from "./workflows";
48
+
49
+ // Define container type with clear, descriptive types
50
+ type WorkflowContainer = {
51
+ multiplier: number;
52
+ }
53
+
54
+ export const mastra = new Mastra({
55
+ workflows: {
56
+ myWorkflow,
57
+ },
58
+ server: {
59
+ middleware: [
60
+ async (c, next) => {
61
+ const multiplier = c.req.header("x-multiplier");
62
+ const container = c.get<WorkflowContainer>("container");
63
+
64
+ // Parse and validate the multiplier value
65
+ const multiplierValue = parseInt(multiplier || "1", 10);
66
+ if (isNaN(multiplierValue)) {
67
+ throw new Error("Invalid multiplier value");
68
+ }
69
+
70
+ container.set("multiplier", multiplierValue);
71
+
72
+ await next(); // Don't forget to call next()
73
+ },
74
+ ],
75
+ },
76
+ });
77
+ ```
78
+
79
+ ## Creating Steps with Variables
80
+
81
+ Steps can access container variables and must conform to the workflow's container type:
82
+
83
+ ```typescript
84
+ import { Step } from "@mastra/core/workflow";
85
+ import { z } from "zod";
86
+
87
+ // Define step input/output types
88
+ interface StepInput {
89
+ inputValue: number;
90
+ }
91
+
92
+ interface StepOutput {
93
+ incrementedValue: number;
94
+ }
95
+
96
+ const stepOne = new Step({
97
+ id: "stepOne",
98
+ description: "Multiply the input value by the configured multiplier",
99
+ execute: async ({ context, container }) => {
100
+ try {
101
+ // Type-safe access to container variables
102
+ const multiplier = container.get("multiplier");
103
+ if (multiplier === undefined) {
104
+ throw new Error("Multiplier not configured in container");
105
+ }
106
+
107
+ // Get and validate input
108
+ const inputValue = context.getStepResult<StepInput>('trigger')?.inputValue;
109
+ if (inputValue === undefined) {
110
+ throw new Error("Input value not provided");
111
+ }
112
+
113
+ const result: StepOutput = {
114
+ incrementedValue: inputValue * multiplier,
115
+ };
116
+
117
+ return result;
118
+ } catch (error) {
119
+ console.error(`Error in stepOne: ${error.message}`);
120
+ throw error;
121
+ }
122
+ },
123
+ });
124
+ ```
125
+
126
+ ## Error Handling
127
+
128
+ When working with runtime variables in workflows, it's important to handle potential errors:
129
+
130
+ 1. **Missing Variables**: Always check if required variables exist in the container
131
+ 2. **Type Mismatches**: Use TypeScript's type system to catch type errors at compile time
132
+ 3. **Invalid Values**: Validate variable values before using them in your steps
133
+
134
+ ```typescript
135
+ // Example of defensive programming with container variables
136
+ const multiplier = container.get("multiplier");
137
+ if (multiplier === undefined) {
138
+ throw new Error("Multiplier not configured in container");
139
+ }
140
+
141
+ // Type and value validation
142
+ if (typeof multiplier !== "number" || multiplier <= 0) {
143
+ throw new Error(`Invalid multiplier value: ${multiplier}`);
144
+ }
145
+ ```
146
+
147
+ ## Best Practices
148
+
149
+ 1. **Type Safety**: Always define proper types for your container and step inputs/outputs
150
+ 2. **Validation**: Validate all inputs and container variables before using them
151
+ 3. **Error Handling**: Implement proper error handling in your steps
152
+ 4. **Documentation**: Document the expected container variables for each workflow
153
+ 5. **Default Values**: Provide sensible defaults when possible