M
Mastraβ€’4w ago
Neeman

Nested Branching

Does anyone have a good example of how to do nested branching? I am seeing (probably old) info out there that says to create nested workflows, but its not working at all and I spent a good deal of my afternoon on this. My flow is simple and I would think this would be simple too. Agent calls tool that wraps a workflow. First step as an A or B path. If A it needs to run another tool and then it has another A B branch. .branch([ [async ({ inputData }: { inputData: { intent: string } }) => inputData.intent === 'create', fullStep], [async ({ inputData }: { inputData: { intent: string } }) => inputData.intent === 'refine', individualStep], ]); Basically i fullStep to branch again. I may be bleary-eyed from staring at this, but its just not making sense right now.. Thanks!
2 Replies
Kartik
Kartikβ€’4w ago
You can use workflows in the place that you are using step inside the branch. It would be something like:
const furtherBranchingWorkflow = createWorkflow(...).branch([[() => ..., fullStep],[()=>..., anotherStep]]).commit();


originalWorkflow.branch([
[async ({ inputData }: { inputData: { intent: string } }) => inputData.intent === 'create', furtherBranchingWorkflow],
[async ({ inputData }: { inputData: { intent: string } }) => inputData.intent === 'refine', individualStep],
]);
const furtherBranchingWorkflow = createWorkflow(...).branch([[() => ..., fullStep],[()=>..., anotherStep]]).commit();


originalWorkflow.branch([
[async ({ inputData }: { inputData: { intent: string } }) => inputData.intent === 'create', furtherBranchingWorkflow],
[async ({ inputData }: { inputData: { intent: string } }) => inputData.intent === 'refine', individualStep],
]);
Mastra Triager
Mastra Triagerβ€’4w ago
πŸ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10153 πŸ” If you're experiencing an error, please provide a minimal reproducible example to help us resolve it quickly. πŸ™ Thank you @Neeman for helping us improve Mastra!
GitHub
Nested Branching Β· Issue #10153 Β· mastra-ai/mastra
This issue was created from Discord post 1439767057217486960: Does anyone have a good example of how to do nested branching? I am seeing (probably old) info out there that says to create nested wor...
Stack Overflow
How to create a Minimal, Reproducible Example - Help Center
Stack Overflow | The World’s Largest Online Community for Developers

Did you find this page helpful?