Overview
The "Smart Memory" node provides configuration-driven memory management for chatbot sessions. It allows storing, retrieving, and clearing chat messages associated with unique session IDs. This is useful in scenarios where a chatbot needs to maintain conversational context over multiple interactions, such as customer support bots, virtual assistants, or any interactive dialogue system.
For example, you can insert new user or bot messages into the memory, retrieve the recent conversation history limited by a configurable window size, or clear the stored memory when a session ends or resets.
Properties
| Name | Meaning |
|---|---|
| Session ID | Unique identifier for the chat session. Required to identify which conversation's memory to operate on. |
| Message Content | Text content of the message to insert into memory. Required for the Insert operation. |
| Memory Window Size | Number of messages to keep in memory (minimum 5, maximum 70). Controls how much recent conversation history is retained. Applies to Insert and Get operations. |
| Storage Backend | Where to store the memory. Currently supports only "In-Memory" storage. |
| Insert Mode | How to insert the message during Insert operation: either "Append" to add to existing memory or "Replace Memory" to overwrite the current memory with the new message. |
| Message Settings | Collection of optional settings related to the message being inserted: • Chat ID (defaults to Session ID) • Chat Type (private, group, supergroup, channel) • Chat Name • Message ID • Reply To Message • Include Reply Context (boolean) • Include Reply Display Name (boolean) • Include Reply Username (boolean) • Include Reply Message (boolean) • Include Reply Message ID (boolean) |
| Identity Settings | Collection defining identity metadata for the message: • Is Bot Response (boolean) • User Role (string, e.g., "user") • Assistant Role (string, e.g., "assistant") • ID (unique identifier) • Display Name • Username |
| Memory Settings | Collection controlling output details for Insert and Get operations: • Include Timestamp (boolean) • Include Token Estimate (boolean) |
Output
The node outputs JSON objects representing the state of the memory or operation results:
For Insert Message operation: returns the updated memory containing:
chatInfo: Information about the chat (ID, type, name).messages: Array of stored messages with their metadata.messageCount: Number of messages currently stored.- Optionally, if enabled, a
tokenEstimatefield estimating the token count of the stored memory.
For Get Memory operation: returns the current memory snapshot with the same structure as above.
For Clear Memory operation: returns a simple confirmation message
{ message: "Memory cleared" }.If no memory exists for a session during Get, an error object
{ error: "No memory found for this session" }is returned.
The node does not output binary data.
Dependencies
- The node uses an internal in-memory storage backend for storing messages.
- No external API keys or services are required.
- Configuration is done entirely via node parameters.
- The node relies on utility modules for normalization and output cleaning internally.
Troubleshooting
- Empty Session ID: The node requires a non-empty Session ID. If empty, it throws an error
"Session ID is required and cannot be empty". - Unsupported Storage Backend: Only "In-Memory" storage is supported. Selecting another backend will cause an error indicating unsupported backend.
- Invalid Memory Window Size: Values outside the allowed range (5 to 70) may be ignored or reset to defaults.
- Missing Message Content on Insert: The Insert operation requires message content; omitting it will cause errors.
- No Memory Found: When performing Get operation on a session with no stored messages, the node returns an error message in the output JSON.
- Error Handling: Any unexpected errors during execution are caught and returned as JSON with an
errorfield describing the issue.
To resolve issues, ensure all required fields are correctly set, use supported options, and verify that the session ID matches expected values.
Links and References
- n8n Documentation
- General concepts of chatbot memory management and conversational context handling
- Token estimation methods for text processing (approximate tokens = string length / 4)