Skip to main content
Lesson 12 of 16·5.5 min

How Memory Works

Memory is already enabled on the Theme Park agent. In this lesson, you'll look under the hood at what that actually means: why the model is still stateless between calls, and what Mastra is doing to make follow-ups work.

You'll trace a real follow-up prompt in Studio to see exactly what context the agent received, and look at lastMessages: the setting that controls how much recent conversation history gets included per call. Mastra persists messages to storage, then re-includes them on later turns so the model has what it needs.

This matters because memory is not magic. What you're really doing is context engineering: deciding what the model gets to see for each call. Understanding that makes it much easier to reason about agent behavior and debug it when something feels off.

"The model is still stateless. Mastra stores context, then includes it again in later calls."

— Guil Hernandez

Mentioned in the lesson
Direct link to Mentioned in the lesson

Code:

Relevant Mastra docs:

Join the community
Direct link to Join the community

Ask questions:

Follow Mastra:

  • X — follow Mastra for updates
  • YouTube — watch more tutorials
  • LinkedIn — follow for updates