LTM Sub-Pipeline
Handles persistent, database-backed memory writes initiated by the LLM via tool calls during the tool-loop. Two tools cover the full CRUD surface:
| Stage | File | Tool name | What it does |
|---|---|---|---|
01-ltm-create.md | MemoryTool | create_long_term_memory | Inserts a new server or personal memory record |
02-ltm-update-delete.md | UpdateLongTermMemoryTool | update_long_term_memory | Replaces or deletes an existing memory by its ID:N |
Key design facts
Section titled “Key design facts”- Feature-flagged — both tools require
self_teaching_enabled = trueinTomoriState.config. When disabled, the tool returns a user-reportable error without writing to the DB. - Persona-lineage scoping — all DB writes use
persona_lineage_id, notpersona_id, so memories are shared across all personas of the same character lineage (different server instances of the same persona still see each other’s memories). - Cache invalidation on success — every successful write immediately invalidates the relevant TomoriState or user cache so the next context-build reads fresh DB state.
- Dual scope — memories are either
server_wide(stored inserver_memories, keyed byserver_id + persona_lineage_id) ortarget_user(stored inpersonal_memories, keyed byuser_id + persona_lineage_id). - Template placeholders — content must use
{user}and{bot}tokens instead of hardcoded names. Both tools strip unknown brace-wrapped tokens (e.g.{bredrumb}) viasanitizeUnknownTemplatePlaceholders()before the DB write.
Cross-references
Section titled “Cross-references”- Intent gate that routes toward LTM tools: → memory pipeline README
- Tool-loop that executes these tools: → tool-loop Stage 02
executeToolCall - Read side (server memories): → context-build server-memory stage
- Read side (personal memories): → context-build personal-memory stage
- Memory ID formatting used in context: →
src/utils/memory/memoryId.ts(formatMemoryWithId)