Agents in Workflows
The ticket purchase workflow can build a quote, pause for approval, and simulate a charge. In this lesson, you'll extend it in two ways that show how tools and agents can each play a role inside a workflow, and when to reach for one over the other.
You'll add a validatePark step upfront that uses the park lookup tool to confirm the submitted park name before anything else runs. After the charge, you'll add a postPurchaseSummary step that calls the theme park agent directly — it generates a short visit brief using its tools and streams it back as part of the final output.
This matters because not every step in a workflow has the same requirements. Validation is strict and deterministic, so a tool call fits. Generating a useful visit brief needs context and judgment, so calling the agent makes sense. The workflow owns the sequence; each step uses whatever is right for that piece of work.
"A tool handles the strict lookup at the start. The agent handles the reasoning at the end. The workflow owns the sequence throughout."
— Guil Hernandez
Mentioned in the lessonDirect link to Mentioned in the lesson
Code:
Relevant Mastra docs:
Join the communityDirect link to Join the community
Ask questions:
- Discord — chat with other learners and the Mastra team
- Guil on LinkedIn — ask him questions directly
Follow Mastra:
Don’t miss the next Mastra lessons
Be notified the moment new lessons release and stay ahead of every update. We’ll email you about course improvements, new Mastra features, and upcoming live workshops. Unsubscribe anytime.