Four-Phase Consolidation Prompt
- Entity ID:
ent-20260410-2bdcac264a5e - Type:
mechanism - Scope:
shared - Status:
active
Description
The Four-Phase Consolidation Prompt is the system prompt injected into the auto-dream subagent, built by buildConsolidationPrompt() in src/services/autoDream/consolidationPrompt.ts. It defines a four-phase workflow -- Orient, Gather Signal, Consolidate, Prune & Index -- that transforms raw session data into durable, organized memory files.
The prompt is parameterized with three arguments: memoryRoot (the auto-memory directory path), transcriptDir (the project-level session transcript directory), and extra (optional context appended at the end, such as tool constraints and session lists). The function is invoked in two contexts: the automatic background dream cycle (autoDream.ts, where extra includes read-only Bash constraints and a list of session IDs) and the manual /dream slash command (where extra is typically empty, granting normal tool permissions).
The prompt opens with a framing line: "You are performing a dream -- a reflective pass over your memory files." It then instructs the agent to synthesize recent learnings into well-organized memories so future sessions can orient quickly. The four phases are sequential by design -- each builds on the output of the previous.
Phase 1 -- Orient
The agent surveys the current state of memory before making any changes:
lsthe memory directory to see what already exists- Read
MEMORY.md(the entrypoint index) to understand the current index structure - Skim existing topic files to avoid creating duplicates
- If
logs/orsessions/subdirectories exist (the append-only-daily-logs layout used by kairos), review recent entries
This phase is read-only. Its purpose is to prevent the most common consolidation failure: creating near-duplicate topic files because the agent didn't know what already existed.
Phase 2 -- Gather Signal
Targeted search for new information worth persisting. The prompt specifies three sources in priority order:
- Daily logs (
logs/YYYY/MM/YYYY-MM-DD.md) -- the append-only stream written by KAIROS sessions - Drifted memories -- existing memory facts that now contradict what the codebase shows
- Transcript search -- narrow
grepagainst JSONL transcript files for specific context (e.g., an error message from a prior session)
The prompt explicitly warns: "Don't exhaustively read transcripts. Look only for things you already suspect matter." This is consistent with the grep-over-rag philosophy -- the dream agent greps narrowly rather than reading entire files. The transcript files are large JSONL, and the prompt tells the agent to grep -rn "<narrow term>" ... | tail -50 rather than catting them.
Phase 3 -- Consolidate
The core write phase. The agent writes or updates memory files at the top level of the memory directory, following the memory file format and type conventions from the system prompt's auto-memory section. The prompt specifies three focus areas:
- Merge, don't duplicate -- new signal goes into existing topic files rather than creating near-duplicates
- Convert relative dates -- "yesterday" and "last week" are converted to absolute dates so they remain interpretable after time passes
- Delete contradicted facts -- if today's investigation disproves an old memory, fix it at the source rather than appending a correction
The prompt delegates format decisions to the system prompt's auto-memory section rather than duplicating those rules, keeping the consolidation prompt focused on the workflow.
Phase 4 -- Prune and Index
The final phase maintains MEMORY.md as a compact index:
- Keep
MEMORY.mdunder 200 lines and under ~25KB (constantsMAX_ENTRYPOINT_LINESand size cap frommemdir.ts) - Each index entry must be one line under ~150 characters:
- [Title](file.md) -- one-line hook - Never write memory content directly into
MEMORY.md-- it is an index, not a dump - Remove pointers to stale, wrong, or superseded memories
- Demote verbose entries: if an index line exceeds ~200 chars, the detail belongs in the topic file
- Add pointers to newly important memories
- Resolve contradictions between files
Tool Constraints
When invoked by the automatic background dream (autoDream.ts), the extra parameter appends a tool constraint notice: Bash is restricted to read-only commands (ls, find, grep, cat, stat, wc, head, tail). Writes to memory files use FileEdit and FileWrite tools, scoped to the memory directory by createAutoMemCanUseTool() from extractMemories.ts. When invoked manually via /dream, these Bash restrictions are absent -- the agent runs with normal permissions.
Completion
The prompt ends with: "Return a brief summary of what you consolidated, updated, or pruned. If nothing changed (memories are already tight), say so." This summary is captured by makeDreamProgressWatcher() in autoDream.ts and, if files were touched, surfaced to the user as an inline "Improved N memories" system message via appendSystemMessage().
Key claims
- The prompt defines exactly four sequential phases: Orient (read current state), Gather Signal (search for new information), Consolidate (merge/update/delete), Prune & Index (maintain MEMORY.md under 200 lines / 25KB)
- Phase 2 explicitly prohibits exhaustive transcript reading -- grep narrowly, don't read whole JSONL files
- Phase 3 requires converting relative dates to absolute dates and deleting contradicted facts at the source
- Phase 4 enforces that MEMORY.md is an index of one-line ~150-char pointers, never a content dump
- The same prompt template is used by both automatic background dreams and manual
/dreaminvocations; only theextraparameter differs (tool constraints + session list vs. empty) - The
DIR_EXISTS_GUIDANCEconstant tells the agent the memory directory already exists and to write directly without runningmkdir
Relations
- parent-mechanism: auto-dream -- the background consolidation system that invokes this prompt via
buildConsolidationPrompt() - execution-model: dreamtask -- the task registry entry that makes the dream visible in the UI; tracks files touched and turns produced by this prompt's execution
- sibling-prompt: memory-extraction-prompt -- the per-turn extraction prompt; both share
createAutoMemCanUseTool()for tool restrictions, but extraction writes new memories while consolidation merges and prunes existing ones - infrastructure: forked-agent-pattern -- the prompt is delivered as a user message to
runForkedAgent(), which handles cache sharing and isolation - data-source: append-only-daily-logs -- Phase 2 prioritizes KAIROS's daily log files as the primary signal source
- data-target: auto-memory -- the memory directory that this prompt reads from and writes to
- design-pattern: grep-over-rag -- Phase 2's "grep narrowly, don't read whole files" instruction implements this philosophy
- constraint: kairos-autodream-contract -- when KAIROS is active,
isGateOpen()disables automatic dreaming; KAIROS uses the same prompt via its own/dreamskill - mutual-exclusion: auto-memory-auto-dream-mutual-exclusion -- extraction and dreaming do not run concurrently; both share tool restrictions via
createAutoMemCanUseTool() - index-target: memory-hierarchy -- Phase 4 maintains Layer 1 (MEMORY.md index) of the three-layer memory architecture
Sources
src-20260409-a14e9e98c3cd-- Internals: Auto-Memory, Auto-Dream, and Agent Teamssrc-20260409-037a8abb6277-- Community Deep Dive: Architecture, KAIROS, Auto-Dream- Primary source code:
src/services/autoDream/consolidationPrompt.ts(prompt template),src/services/autoDream/autoDream.ts(invocation and forking logic),src/memdir/memdir.ts(ENTRYPOINT_NAME, MAX_ENTRYPOINT_LINES, DIR_EXISTS_GUIDANCE constants)