n8n-io/n8n · error · Error

Invalid memory configuration. Use: new Memory() for in-proce

Error message

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.

What it means

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.

Source

Thrown at packages/@n8n/agents/src/sdk/agent.ts:369

	/** Set the memory configuration. Accepts a MemoryConfig, Memory builder, or bare BuiltMemory. */
	memory(m: MemoryConfig | Memory | BuiltMemory): this {
		if (m instanceof Memory) {
			// Memory builder — call build()
			this.memoryConfig = m.build();
		} else if ('memory' in m) {
			// MemoryConfig — validate the same invariants as the builder path
			this.memoryConfig = normalizeMemoryConfig(m);
		} else if (
			typeof m === 'object' &&
			m !== null &&
			typeof m.getMessages === 'function' &&
			typeof m.saveMessages === 'function'
		) {
			// Bare BuiltMemory — wrap in minimal config
			this.memoryConfig = { memory: m };
		} else {
			throw new Error(
				'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.',
			);
		}
		return this;
	}

	/** Observe observational-memory background task lifecycle (observer/reflector). */
	memoryTaskObserver(observer: (event: ScopedMemoryTaskEvent) => void): this {
		this.onMemoryTaskEvent = observer;
		return this;
	}

	/** Inject the host store that hydrates file-reference content parts before LLM calls. */
	fileStore(store: BuiltFileStore): this {
		this.fileStoreValue = store;
		return this;

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Use new Memory() for in-process memory and pass the builder directly.
  2. Use new Memory().storage(myBuiltMemoryBackend) for persistent storage, then pass the builder.
  3. If passing a config object, ensure it has a 'memory' key containing a BuiltMemory.
  4. If passing a bare backend, ensure it implements both getMessages and saveMessages.

Example fix

// before
agent.memory({ backend: myStore }); // no 'memory' key
// after
agent.memory(new Memory().storage(myStore));
Defensive patterns

Strategy: type-guard

Validate before calling

function isValidMemoryConfig(m: unknown): boolean {
  if (m instanceof Memory) return true;
  if (typeof m === 'object' && m !== null && 'memory' in m) return true;
  if (typeof m === 'object' && m !== null &&
      typeof (m as any).getMessages === 'function' &&
      typeof (m as any).saveMessages === 'function') return true;
  return false;
}
if (!isValidMemoryConfig(value)) {
  value = new Memory();
}

Type guard

function isMemoryBuilder(m: unknown): m is Memory {
  return m instanceof Memory;
}
function isBuiltMemory(m: unknown): m is BuiltMemory {
  return typeof m === 'object' && m !== null &&
    typeof (m as any).getMessages === 'function' &&
    typeof (m as any).saveMessages === 'function';
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/86c46a0f849e55c2. Report an issue: GitHub.