mastra-ai/mastra · error
Memory is not configured on this AgentController
Error message
Memory is not configured on this AgentController
What it means
resolveMemory reads this.config.memory and throws immediately when it is undefined. Memory is required for this code path but the controller was built without any memory configuration.
Source
Thrown at packages/core/src/agent-controller/agent-controller.ts:2278
},
},
abortSignal: session.run.getAbortSignal(),
emitEvent: event => session.emit(event),
getSubagentModelId: params => session.subagents.model.get(params ?? {}),
};
requestContext.set('controller', controllerContext);
return requestContext;
}
/**
* Resolve memory from config — handles both static instances and dynamic factory functions.
*/
private async resolveMemory(session: Session<TState>): Promise<MastraMemory> {
const mem = this.config.memory;
if (!mem) {
throw new Error('Memory is not configured on this AgentController');
}
if (typeof mem !== 'function') {
return mem;
}
const requestContext = await this.buildRequestContext(session);
const resolved = await Promise.resolve(mem({ requestContext }));
if (!resolved) {
throw new Error('Dynamic memory factory returned empty value');
}
return resolved;
}
// ===========================================================================
// Token Usage
// ===========================================================================
private async persistTokenUsage(session: Session<TState>): Promise<void> {
const threadId = session.thread.getId();View on GitHub (pinned to 75dd419e61)
Solutions
- Set config.memory to a Memory instance: memory: new Memory({ storage })
- Or set config.memory to a factory function ({ requestContext }) => Memory
- If memory is legitimately optional, route around APIs that call resolveMemory or check config first
Example fix
// before
new AgentController({ storage });
// after
new AgentController({ storage, memory: new Memory({ storage }) }); Defensive patterns
Strategy: validation
Validate before calling
if (!controller.config.memory) throw new Error('This API requires config.memory'); Type guard
function hasMemory<T extends { config: { memory?: unknown } }>(c: T): c is T & { config: { memory: NonNullable<T['config']['memory']> } } {
return !!c.config.memory;
} Try / catch
try {
return await memoryDependentApi();
} catch (e) {
if (e instanceof Error && e.message === 'Memory is not configured on this AgentController') {
// degrade gracefully or rethrow a domain-specific error
}
throw e;
} Prevention
- Always configure memory alongside storage as a paired default
- Gate memory-dependent features behind a config flag that also requires memory
- Fail fast with a startup assertion instead of per-request failures
When it happens
Trigger: Any code path calling resolveMemory (e.g. cloneThread, memory-dependent flows) on a controller whose config.memory is not set — neither a MastraMemory instance nor a factory function.
Common situations: Constructing AgentController with only storage, then calling an API that goes through resolveMemory (which requires config.memory specifically); environment-specific config that omits memory; typo'd config key.
Related errors
- sendStateSignal requires Mastra memory
- Storage is not configured on this AgentController
- Storage does not have a memory domain configured
- Dynamic memory factory returned empty value
- Memory is not configured on this AgentController
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/fa0a21c89cf86919.
Report an issue: GitHub.