Mastra adds memory hooks to inspect and edit what agents remember

Mastra has added hooks to its memory system, giving developers a way to watch observation and reflection cycles or change what the Observer and Reflector see and store. The company also shipped skillResultRedactor(), a ready-made transform hook for keeping bulky skill files out of memory.
- Mastra's memory system now supports lifecycle hooks and transform hooks around observation and reflection cycles.
- Lifecycle hooks can log token usage per cycle or help trace why an agent forgot something.
- Transform hooks can remove noisy tool output and internal reasoning or redact secrets and PII.
- skillResultRedactor() replaces a skill's full file contents in tool results with a placeholder, while the agent still remembers the skill.
- The feature requires @mastra/[email protected] or later and a storage adapter.
Two types of hooks
According to Mastra, there are two kinds of memory hooks. Lifecycle hooks (onObservationStart, onObservationEnd, onReflectionStart, onReflectionEnd) let developers report on a cycle externally. Mastra gives two examples: catching a cost spike by logging token usage per cycle, and tracing why an agent has forgotten something.
Transform hooks (beforeObservation, afterObservation, beforeReflection, afterReflection) let developers intercept and modify the actual memory data. Mastra says they can be used to pare or remove noisy tool output and internal reasoning, or to redact secrets and PII.
Before hooks, Mastra says, observational memory offered no levers to affect what happened during an observation or reflection cycle, other than filtering messages before they reached memory. The hooks now sit inside the cycle itself.
A ready-made redactor for skills
Alongside the hooks, Mastra shipped skillResultRedactor(), a prebuilt version of a transform hook. The problem it addresses: when an agent uses a Skill, the tool result contains the skill's entire file contents, and the Observer sees that content every time. The redactor replaces the content with a placeholder. According to Mastra, the agent still remembers the skill.
Setting it up
Developers need to install @mastra/memory and a storage adapter, which is required for Observational Memory. The adapter can be set up on the Memory instance or on the main Mastra instance. The feature requires @mastra/[email protected] or later, added in PR #23167 and PR #24220.
In Mastra's example, a trip planner agent is configured with a Memory instance using LibSQLStore for storage and google/gemini-2.5-flash as the observational memory model. Hooks are then added under the hooks key of the observational memory options.
The lifecycle example logs when a cycle starts and, when it ends, either the error or the number of input tokens used. The transform example defines a 2000-character size threshold and, in beforeObservation, replaces any oversized tool result with the placeholder text "[search results omitted from memory]" before the Observer sees it. Other hooks in the example redact observations before they are persisted, strip internal notes before the Reflector condenses text, and sync the output to an external store after reflection.
What it means for developers
Mastra states that transform hooks are always awaited on every path: manual observe() and reflect() calls, turn-synchronous observation, and async buffering. Returning void from any of them passes the input through unchanged, so a hook only changes data when it explicitly returns a replacement.
For teams running agents with persistent memory, the hooks offer a way to track the cost of each memory cycle, debug missing memories, and keep sensitive or oversized content out of stored observations. Full configuration options are documented in Mastra's pages on observational memory hooks, skill result redaction and the Observational Memory overview.
Mastra: Introducing Memory Hooks | Mastra Blog


