Back to articles

How I structured a multi-agent workflow with Mastra AI for daily planning

Ai Agents Communicating

Published on 9/11/2025

In the Sarion project, a personal AI assistant, I developed an advanced daily planning system using Mastra AI, an open-source TypeScript framework for creating intelligent agents. Mastra makes orchestrating complex workflows easy thanks to its modular architecture and advanced state management.

What is Mastra AI?

Mastra AI Screenshot

Mastra AI is a platform designed for building complex AI applications, offering tools for agent management, workflow orchestration, integration with language models, and memory management. Its workflow-based structure allows you to define sequences of conditional operations, validate data, and manage states efficiently.

The “Plan My Day” workflow

The “Plan My Day” workflow was designed to gather data, generate a daily plan, refine the plan through iterations, and translate it into the user’s preferred language. This process is divided into two main workflows: data collection and loop management, and the generation and refinement flow.

I chose to divide and specialize different agents in order to optimize costs and execution times.

Using a single agent brings several drawbacks, such as unpredictable execution times (and related costs), a higher prompt complexity that could become unmanageable over time, the need to use a single, powerful but expensive LLM instead of several smaller and potentially specialized LLMs, and the difficulty in scaling just those flows that need it.

1. Data collection and loop management

The first step is to collect the information needed to create a daily plan. The following code defines the workflow for this phase:

export const planMyDayWorkflow = createWorkflow({
  id: "planMyDayWorkflow",
  inputSchema,
  outputSchema,
})
  .then(gatherData)
  .dowhile(refinePlan, async ({ inputData }) => {
    return !inputData.isPlanRefined && inputData.repetition < MAX_REPETITIONS;
  })
  .map(async ({ inputData }) => {
    return {
      response: inputData.dayPlan,
    };
  })
  .then(translateDayPlan)
  .commit();

In this workflow, data such as daily activities, unfinished tasks from previous days, journal entries from the past six months, general tasks, and personal notes are collected and then sent as input data to the "refinePlan" flow, which will be iterated either until the maximum number of repetitions is reached or the plan is considered refined.

2. Plan refinement flow

Once data is collected, the plan is refined to improve its quality and feasibility. The following code defines the workflow for this phase:

export const refinePlan = createWorkflow({
  id: "refinePlanWorkflow",
  inputSchema: inputSchemaRefinePlan,
  outputSchema: outputSchemaRefinePlan,
})
  .branch([
    [
      async ({ inputData: { refinementSuggestions } }) =>
        !refinementSuggestions,
      generateTaskList,
    ],
    [
      async ({ inputData: { refinementSuggestions } }) =>
        !!refinementSuggestions,
      correctTaskList,
    ],
  ])
  .map(async ({ inputData }) => {
    const {
      "correct-task-list": correctTaskList,
      "generate-task-list": generateTaskList,
    } = inputData;
  })
  .branch([
    [
      async ({ inputData: { refinementSuggestions } }) =>
        !refinementSuggestions,
      generateDayPlan,
    ],
    [
      async ({ inputData: { refinementSuggestions } }) =>
        !!refinementSuggestions,
      correctDayPlan,
    ],
  ])
  .map(async ({ inputData }) => {
    const {
      "generate-day-plan": generateDayPlan,
      "correct-day-plan": correctDayPlan,
    } = inputData;
  })
  .then(evaluateRefinement)
  .commit();

In this phase, the system evaluates the quality of the plan, corrects any errors, and further refines the plan based on the feedback received.

The structure I chose is therefore as follows:

Workflow schema

Main features

  • Contextual awareness: Uses historical data to make more informed planning decisions.
  • Iterative refinement: Continuously improves the plan based on feedback received.
  • Self-correction: Automatically identifies and corrects potential problems in the plan.
  • Multilingual support: Translates the final plan into the user’s preferred language.
  • Error management: Complete logging at every step and error handling to prevent infinite loops.

Conclusions

Using Mastra AI, I’ve built a highly personalized and adaptive daily planning system that can learn from past interactions and continually improve. This approach, based on modular workflows and intelligent agents, offers a scalable and flexible solution for managing daily tasks.

If you’re interested in further exploring what Mastra AI can do, I invite you to try the Sarion application available at getsarion.com.

Sarion leverages the power of Mastra to provide a smart, personalized planning experience.

Tell me about your idea

Do you have an idea you want to turn into reality? Contact me to discuss how I can help you build your MVP.

Contact me