STM Sub-Pipeline
The short-term memory (STM) sub-pipeline maintains working memory across recent conversation turns. It stores recent dialogue in an in-process cache and records model-generated summaries and structured categories in the database.
The sub-pipeline provides two write paths:
| Stage | Trigger | Written state | Persistence |
|---|---|---|---|
| 01: Passive Capture | Post-turn, generation finished | Recent dialogue turns up to MAX_MESSAGES_PER_CHANNEL | In-process cache only; ensures scope identity row in database |
| 02: Summary Upgrade | Tool loop, update_short_term_memory call | Distilled summary text or structured category key-value pairs | In-process cache and durable short_term_memories table |
Key design facts
Section titled “Key design facts”- Hybrid persistence: crude messages exist only in the in-process cache, while summaries, categories, and cadence state are stored in the
short_term_memoriestable. Following a process restart, durable entries are hydrated with an empty crude message list, and message history repopulates as turns occur. - Dual-key scoping: writes index into both user-scoped (
shortterm:user:userId:channelId[:personaId]) and server-scoped (shortterm:server:serverId:channelId[:personaId]) keys. Direct message sessions create only the user-scoped entry. - Summary priority: same-channel context favors categories or summary text. Other-channel context can include raw messages alongside distilled content according to render mode. Passive capture preserves existing summaries.
- Single upgrade per turn:
streamingContext.disableShortTermMemoryUpdateis set totrueafter the first successful upgrade, preventing the model from invokingupdate_short_term_memorymultiple times in one tool loop. - Deletion ownership: channel resets through
/refreshcallclearShortTermMemoryForChannel(), and user memory purges callclearShortTermMemoryForUser(). Both helpers evict the in-memory cache and delete rows from theshort_term_memoriestable in the background.
Cross-references
Section titled “Cross-references”- Intent detection gate: Memory Pipeline explains how explicit memory intent suppresses the STM upgrade tool.
- Context assembly consumer: Short-Term Memory Context formats cached messages and summaries for prompt injection.
- Tool-loop caller: Execute Tool Call dispatches tool invocations that trigger summary upgrades.
- Post-turn effects caller: Run Generation Turn: Post-Turn Effects triggers passive turn capture.