Blog

Mastra Changelog 2025-06-20

Jun 20, 2025

What a week at Mastra. Co-founders united in SF, we gave out books at YC Startup School, and the team keeps shipping…

Let’s dive into this week’s updates.

Workflow Sleep Methods

We added .sleep() and .sleepUntil() methods to workflows, so you can pause execution for a specified duration or until a specific time:

sleep

import { createWorkflow, createStep } from '@mastra/core/workflows';
import { z } from 'zod';

const waitStep = createStep({
  id: 'wait',
  description: 'Waits for 5 seconds before proceeding',
  inputSchema: z.object({}),
  outputSchema: z.object({ done: z.boolean() }),
  execute: async () => {
    return { done: true };
  },
});

const workflow = createWorkflow({
  id: 'sleepWorkflow',
  inputSchema: z.object({}),
  outputSchema: z.object({ done: z.boolean() }),
  steps: [waitStep],
})
  .then(waitStep)
  .sleep(5000)
  .commit();

sleepUntil

import { createWorkflow, createStep } from '@mastra/core/workflows';
import { z } from 'zod';

const stepOne = createStep({
  id: 'step-one',
  description: 'Return step',
  inputSchema: z.object({}),
  outputSchema: z.object({ step: z.string() }),
  execute: async () => {
    return { step: 'one' };
  },
});

const stepTwo = createStep({
  id: 'step-two',
  description: 'Return ste',
  inputSchema: z.object({ step: z.string() }),
  outputSchema: z.object({ success: z.boolean() }),
  execute: async () => {
    return { success: true };
  },
});

const workflow = createWorkflow({
  id: 'sleepUntilWorkflow',
  inputSchema: z.object({}),
  outputSchema: z.object({ success: z.boolean() }),
  steps: [stepOne, stepTwo],
})
  .then(stepOne)
  .sleepUntil(new Date(Date.now() + 1000))
  .then(stepTwo)
  .commit();

waitForEvent

import { createWorkflow, createStep } from '@mastra/core/workflows';
import { z } from 'zod';

const stepOne = createStep({
  id: 'step-one',
  description: 'Return step 1',
  inputSchema: z.object({}),
  outputSchema: z.object({ step: z.string() }),
  execute: async () => {
    return { step: 'one' };
  },
});

const stepTwo = createStep({
  id: 'step-two',
  description: 'Return step 2',
  inputSchema: z.object({ step: z.string() }),
  outputSchema: z.object({ step: z.string() }),
  execute: async () => {
    return { step: 'two' };
  },
});

const stepThree = createStep({
  id: 'step-three',
  description: 'Return success',
  inputSchema: z.object({ step: z.string() }),
  outputSchema: z.object({ success: z.boolean() }),
  execute: async () => {
    return { success: true };
  },
});

const workflow = createWorkflow({
  id: 'waitForEventWorkflow',
  inputSchema: z.object({}),
  outputSchema: z.object({ success: z.boolean() }),
  steps: [stepOne, stepTwo, stepThree],
})
  .then(stepOne)
  .waitForEvent('my-event-name', stepTwo)
  .then(stepThree)
  .commit();

When executing the workflow the step waits for an event to be received.

const workflow = mastra.getWorkflow('waitForEventWorkflow')

const run = await workflow.createRun()

run.start({})

// Elsewhere, you can execute sendEvent to activate the step
setTimeout(() => {
    run.sendEvent('my-event-name', {
        step: 'three',
    })
}, 5000)

Structured Memory

Agents can now store and retrieve objects / JSON in working memory, not just conversation messages. They can also store complex user characteristics and preferences:

import { Agent } from '@mastra/core/agent';
import { z } from 'zod';

const memory = new Memory({
    options: {
      workingMemory: {
        enabled: true,
        schema: z.object({ 
	        theme: z.string(), 
	        notifications: z.boolean().default(false),
	        language: z.string(),
	      })
      },
    },
  })

const agent = new Agent({
  name: 'MemoryAgent',
  instructions: 'You remember user preferences and task states.',
  memory: memory
});

// Example: Store user preferences
await agent.generate('I want my theme to be dark mode and en', {
  resourceId: '123,
  threadId: '234',
});

// Example: Retrieve user preferences
const prefs = await memory.getWorkingMemory({ threadId: '234', format: 'json' });

console.log('User preferences:', prefs);
// {
//  theme: 'dark mode',
//  language: 'en',
//  notifications: false,
// }

Other Updates

  • New Gladia STT provider. Gladia is a French audio transcription API used by AI companies like 11x (#4459)
  • Enhanced Agent Context: We added thread metadata support to agent.stream() and ≈agent.generate() for better conversation management (#5108)
  • LaTeX Document Support: RAG now correctly chunks LaTeX documents with proper separator handling (#4882)
  • PostgreSQL 15 Compatibility: We fixed memory retrieval issues with explicit query aliases (#5182)
  • Workflow Polling API: We added a new API endpoint for checking workflow execution results programmatically (#5061)
  • MCP Connection Stability: We shipped multiple improvements to streamable HTTP connections (#5088, #5089)

Find the full release log here.

Share

Stay up to date