LTM 02: Memory Update & Delete
Este conteúdo não está disponível em sua língua ainda.
The memory update and delete stage handles model-initiated modifications or removals of existing persistent memories using the integer identifier shown in prompt context.
Flow and ownership
Section titled “Flow and ownership”When the model detects an outdated, inaccurate, or redundant memory, it invokes update_long_term_memory managed by UpdateLongTermMemoryTool in src/tools/functionCalls/updateLongTermMemoryTool.ts.
The tool distinguishes between updates and deletions based on the provided content:
- Update:
memory_contentprovides replacement text. The tool sanitizes braces usingsanitizeUnknownTemplatePlaceholders()and validates length viavalidateMemoryContent(). - Deletion:
memory_contentis empty or whitespace-only after sanitization.
Scope determination and resolution
Section titled “Scope determination and resolution”Target scope depends on the presence of the target_user argument:
- Server scope: when
target_useris absent, the tool updates or deletes records in theserver_memoriestable scoped to(server_id, persona_lineage_id). - Personal scope: when
target_useris provided,resolveUserTarget()(src/utils/discord/targetResolver.ts) matches the display name.- Bridge users reject personal updates with an error because bridge users only support server-wide memories.
- Personal updates targeting the bot itself return an error.
- The resolved user must belong to the current guild or direct message channel.
- For updates, if the target user has
PrivacyLevel.PARTIALorPrivacyLevel.FULL, the update halts with a privacy error. Deletions remain permitted.
Database operations and notifications
Section titled “Database operations and notifications”Following parameter and scope checks, execution routes to the matching repository:
- Database execution:
- Server update:
serverMemoryRepository.updateByIdWithLineage()updates content inserver_memories. - Server deletion:
serverMemoryRepository.removeByIdWithLineage()removes the row and returns its prior content. - Personal update:
personalMemoryRepository.updateByIdForUserAndLineage()updates content inpersonal_memories. - Personal deletion:
personalMemoryRepository.removeByIdForUserAndLineage()removes the row and returns its prior content. Content-changing updates from either the tool or memory panels delete every embedding family in the same transaction while preserving decay metadata. Model edits leavemanually_writtenunchanged. Every successful edit-form save through/memoriesor/personal memoriessets it to true in the content-update transaction, including channel-only, tag-only, and unchanged-content saves. This protects the memory from automatic eviction while allowing it to become dormant. Unchanged content keeps its vectors. Deleting a memory cascades to its vectors; post-turn fill rebuilds edited content only when it is visible to recall.
- Server update:
- Cache invalidation:
- Server operations call
invalidateTomoriStateCache(serverDiscId)immediately after successful database execution. - Personal operations call
invalidateUserCache(targetUserId)immediately after successful database execution.
- Server operations call
- Discord embed confirmation:
- Updates dispatch an amber notice embed using
sendMemoryEmbedWithExpand(). - Deletions dispatch a red notice embed displaying the deleted memory content for user confirmation.
- Updates dispatch an amber notice embed using
The tool returns a successful ToolResult detailing the outcome.
Constraints and rationale
Section titled “Constraints and rationale”- Lineage protection: all repository updates and deletes enforce
persona_lineage_idmatching, preventing one character persona from mutating or deleting memories belonging to another. - Accidental deletion transparency: deletion operations fetch the memory text prior to row removal, allowing the confirmation notice to display the exact content that was removed.
- Cache freshness guarantee: cache invalidation occurs immediately after database success, so subsequent context builds reload fresh records directly from the database.
Source pointers
Section titled “Source pointers”src/tools/functionCalls/updateLongTermMemoryTool.ts:UpdateLongTermMemoryToolparameter handling, scope routing, and execution flow.src/utils/db/repositories/ServerMemoryRepository.ts: queries for updating and removing server memories with lineage checks.src/utils/db/repositories/PersonalMemoryRepository.ts: queries for updating and removing personal memories with lineage checks.src/utils/cache/tomoriStateCache.tsandsrc/utils/cache/userCache.ts: cache invalidation functions.