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
1import { createWorkflow, createStep } from '@mastra/core/workflows';
2import { z } from 'zod';
3
4const waitStep = createStep({
5 id: 'wait',
6 description: 'Waits for 5 seconds before proceeding',
7 inputSchema: z.object({}),
8 outputSchema: z.object({ done: z.boolean() }),
9 execute: async () => {
10 return { done: true };
11 },
12});
13
14const workflow = createWorkflow({
15 id: 'sleepWorkflow',
16 inputSchema: z.object({}),
17 outputSchema: z.object({ done: z.boolean() }),
18 steps: [waitStep],
19})
20 .then(waitStep)
21 .sleep(5000)
22 .commit();
sleepUntil
1import { createWorkflow, createStep } from '@mastra/core/workflows';
2import { z } from 'zod';
3
4const stepOne = createStep({
5 id: 'step-one',
6 description: 'Return step',
7 inputSchema: z.object({}),
8 outputSchema: z.object({ step: z.string() }),
9 execute: async () => {
10 return { step: 'one' };
11 },
12});
13
14const stepTwo = createStep({
15 id: 'step-two',
16 description: 'Return ste',
17 inputSchema: z.object({ step: z.string() }),
18 outputSchema: z.object({ success: z.boolean() }),
19 execute: async () => {
20 return { success: true };
21 },
22});
23
24const workflow = createWorkflow({
25 id: 'sleepUntilWorkflow',
26 inputSchema: z.object({}),
27 outputSchema: z.object({ success: z.boolean() }),
28 steps: [stepOne, stepTwo],
29})
30 .then(stepOne)
31 .sleepUntil(new Date(Date.now() + 1000))
32 .then(stepTwo)
33 .commit();
waitForEvent
1import { createWorkflow, createStep } from '@mastra/core/workflows';
2import { z } from 'zod';
3
4const stepOne = createStep({
5 id: 'step-one',
6 description: 'Return step 1',
7 inputSchema: z.object({}),
8 outputSchema: z.object({ step: z.string() }),
9 execute: async () => {
10 return { step: 'one' };
11 },
12});
13
14const stepTwo = createStep({
15 id: 'step-two',
16 description: 'Return step 2',
17 inputSchema: z.object({ step: z.string() }),
18 outputSchema: z.object({ step: z.string() }),
19 execute: async () => {
20 return { step: 'two' };
21 },
22});
23
24const stepThree = createStep({
25 id: 'step-three',
26 description: 'Return success',
27 inputSchema: z.object({ step: z.string() }),
28 outputSchema: z.object({ success: z.boolean() }),
29 execute: async () => {
30 return { success: true };
31 },
32});
33
34const workflow = createWorkflow({
35 id: 'waitForEventWorkflow',
36 inputSchema: z.object({}),
37 outputSchema: z.object({ success: z.boolean() }),
38 steps: [stepOne, stepTwo, stepThree],
39})
40 .then(stepOne)
41 .waitForEvent('my-event-name', stepTwo)
42 .then(stepThree)
43 .commit();
When executing the workflow the step waits for an event to be received.
1const workflow = mastra.getWorkflow('waitForEventWorkflow')
2
3const run = await workflow.createRun()
4
5run.start({})
6
7// Elsewhere, you can execute sendEvent to activate the step
8setTimeout(() => {
9 run.sendEvent('my-event-name', {
10 step: 'three',
11 })
12}, 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:
1import { Agent } from '@mastra/core/agent';
2import { z } from 'zod';
3
4const memory = new Memory({
5 options: {
6 workingMemory: {
7 enabled: true,
8 schema: z.object({
9 theme: z.string(),
10 notifications: z.boolean().default(false),
11 language: z.string(),
12 })
13 },
14 },
15 })
16
17const agent = new Agent({
18 name: 'MemoryAgent',
19 instructions: 'You remember user preferences and task states.',
20 memory: memory
21});
22
23// Example: Store user preferences
24await agent.generate('I want my theme to be dark mode and en', {
25 resourceId: '123,
26 threadId: '234',
27});
28
29// Example: Retrieve user preferences
30const prefs = await memory.getWorkingMemory({ threadId: '234', format: 'json' });
31
32console.log('User preferences:', prefs);
33// {
34// theme: 'dark mode',
35// language: 'en',
36// notifications: false,
37// }
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.