Agents gain persistent memory backed by n8n database

Memory backends now describe themselves via a new introspection API, enabling N8nMemory to persist agent conversations in the n8n database — no configuration required.
Agents previously relied on eval-based reconstruction from source strings to restore memory backends from saved schemas — an approach that was fragile and incompatible with secure sandboxes. Memory backends now implement a describe() method that returns a structured descriptor containing the backend name, constructor, and serializable connection parameters. This enables schema-driven reconstruction via a memoryRegistry of factory functions instead of string evaluation.
N8nMemory is a new TypeORM-backed service that persists threads, messages, and working memory in three database tables (agents_resources, agents_threads, agents_messages). It replaces SQLite and PostgreSQL as the default recommended storage for all agents generated by the system. The sandbox exposes an N8nMemoryMarker stub that only implements describe() — sufficient for schema serialization — while the host runtime resolves the real N8nMemory service through dependency injection. Code generation has been updated to build memory chains from schema fields directly rather than emitting source strings.
These changes touch the agents module in the CLI package, affecting sandbox runtime wiring, code generation prompts, and schema serialization. The work lays groundwork for further memory backend expansion.
View Original GitHub Description
Summary
1. MemorySchema — richer structured fields
Replaces storage: 'memory' | 'custom' with name, constructorName, and connectionParams fields sourced from BuiltMemory.describe(). Adds semanticRecall.scope, workingMemory.scope, and titleGeneration fields. source is kept temporarily during migration.
2. No source code for memory reconstruction
fromSchema no longer eval-reconstructs backends from the source string. Instead, FromSchemaOptions.memoryRegistry maps backend names to async factory functions. All memory options (semanticRecall, workingMemory, titleGeneration) are reconstructed from schema fields directly. Code generation in generate-agent-code.ts follows the same approach via buildMemoryChain() and MemoryImportMap.
3. BaseMemory abstract class
New storage/base-memory.ts provides a default describe() implementation. SqliteMemory and PostgresMemory both extend it. PostgresMemory gains a credential-based constructor path that resolves connection config at runtime without embedding secrets in connectionParams.
4. N8nMemory — default persistent backend
New TypeORM-backed N8nMemory service persists threads, messages, and working memory in the n8n database via a new migration (agents_resources, agents_threads, agents_messages). A sandbox-side N8nMemoryMarker stub is exposed as N8nMemory in @n8n/agents-utils — it only implements describe() so schemas serialise correctly; the host maps 'n8n' in memoryRegistry to the real DI service. N8nMemory is now the default recommended storage in all code generation prompts.
Review / Merge checklist
- PR title and summary are descriptive. (conventions) <!-- **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** -->
- Docs updated or follow-up ticket created.
- Tests included. <!-- A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. -->
- PR Labeled with
Backport to Beta,Backport to Stable, orBackport to v1(if the PR is an urgent fix that needs to be backported)