{"record":{"id":"86c46a0f849e55c2","repo":"n8n-io/n8n","slug":"invalid-memory-configuration-use-new-memory-fo","errorCode":null,"errorMessage":"Invalid memory configuration. Use: new Memory() for in-process memory, or new Memory().storage(myBuiltMemoryBackend) for a persistent backend. See the Memory class documentation for all options.","messagePattern":"Invalid memory configuration\\. Use: new Memory\\(\\) for in-process memory, or new Memory\\(\\)\\.storage\\(myBuiltMemoryBackend\\) for a persistent backend\\. See the Memory class documentation for all options\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/sdk/agent.ts","lineNumber":369,"sourceCode":"\n\t/** Set the memory configuration. Accepts a MemoryConfig, Memory builder, or bare BuiltMemory. */\n\tmemory(m: MemoryConfig | Memory | BuiltMemory): this {\n\t\tif (m instanceof Memory) {\n\t\t\t// Memory builder — call build()\n\t\t\tthis.memoryConfig = m.build();\n\t\t} else if ('memory' in m) {\n\t\t\t// MemoryConfig — validate the same invariants as the builder path\n\t\t\tthis.memoryConfig = normalizeMemoryConfig(m);\n\t\t} else if (\n\t\t\ttypeof m === 'object' &&\n\t\t\tm !== null &&\n\t\t\ttypeof m.getMessages === 'function' &&\n\t\t\ttypeof m.saveMessages === 'function'\n\t\t) {\n\t\t\t// Bare BuiltMemory — wrap in minimal config\n\t\t\tthis.memoryConfig = { memory: m };\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t'Invalid memory configuration. Use: new Memory() for in-process memory, ' +\n\t\t\t\t\t'or new Memory().storage(myBuiltMemoryBackend) for a persistent backend. ' +\n\t\t\t\t\t'See the Memory class documentation for all options.',\n\t\t\t);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/** Observe observational-memory background task lifecycle (observer/reflector). */\n\tmemoryTaskObserver(observer: (event: ScopedMemoryTaskEvent) => void): this {\n\t\tthis.onMemoryTaskEvent = observer;\n\t\treturn this;\n\t}\n\n\t/** Inject the host store that hydrates file-reference content parts before LLM calls. */\n\tfileStore(store: BuiltFileStore): this {\n\t\tthis.fileStoreValue = store;\n\t\treturn this;","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/sdk/agent.ts#L351-L387","documentation":"Thrown by the Agent's memory setter when the passed value does not match any recognized memory configuration shape: not a Memory builder instance, not a MemoryConfig object (lacking a 'memory' key), and not a bare BuiltMemory (lacking getMessages/saveMessages functions). The library requires one of these three forms to set up agent memory.","triggerScenarios":"Calling agent.memory(value) where value is a plain object without a 'memory' key, a string, a class instance that is not a Memory builder, or an object missing the getMessages/saveMessages interface. Also triggered by passing a partially-constructed memory backend.","commonSituations":"Passing a raw config object like { backend: myStore } instead of wrapping it as { memory: { backend: myStore } }. Passing a storage backend instance directly instead of wrapping it with new Memory().storage(backend). Confusing the Memory builder class with the BuiltMemory runtime object.","solutions":["Use new Memory() for in-process memory and pass the builder directly.","Use new Memory().storage(myBuiltMemoryBackend) for persistent storage, then pass the builder.","If passing a config object, ensure it has a 'memory' key containing a BuiltMemory.","If passing a bare backend, ensure it implements both getMessages and saveMessages."],"exampleFix":"// before\nagent.memory({ backend: myStore }); // no 'memory' key\n// after\nagent.memory(new Memory().storage(myStore));","handlingStrategy":"type-guard","validationCode":"function isValidMemoryConfig(m: unknown): boolean {\n  if (m instanceof Memory) return true;\n  if (typeof m === 'object' && m !== null && 'memory' in m) return true;\n  if (typeof m === 'object' && m !== null &&\n      typeof (m as any).getMessages === 'function' &&\n      typeof (m as any).saveMessages === 'function') return true;\n  return false;\n}\nif (!isValidMemoryConfig(value)) {\n  value = new Memory();\n}","typeGuard":"function isMemoryBuilder(m: unknown): m is Memory {\n  return m instanceof Memory;\n}\nfunction isBuiltMemory(m: unknown): m is BuiltMemory {\n  return typeof m === 'object' && m !== null &&\n    typeof (m as any).getMessages === 'function' &&\n    typeof (m as any).saveMessages === 'function';\n}","tryCatchPattern":null,"preventionTips":["Always construct memory via new Memory() and chain .storage(backend) if persistence is needed.","Do not pass raw storage backend instances directly to .memory().","If passing a config object, ensure it has a 'memory' key wrapping a BuiltMemory."],"tags":["memory","configuration","type-validation","agent"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}