Module: Clacky::Agent::MemoryUpdater
- Included in:
- Clacky::Agent
- Defined in:
- lib/clacky/agent/memory_updater.rb
Overview
Long-term memory update functionality Triggered at the end of a session to persist important knowledge.
The LLM decides:
- Which topics were discussed
- Which memory files to update or create
- How to merge new info with existing content
- What to drop to stay within the per-file token limit
Trigger condition:
- Iteration count >= MEMORY_UPDATE_MIN_ITERATIONS (avoids trivial tasks like commits)
Constant Summary collapse
- MEMORY_UPDATE_MIN_ITERATIONS =
Minimum LLM iterations for this task before triggering memory update. Set high enough to skip short utility tasks (commit, deploy, etc.)
10- MEMORIES_DIR =
File.("~/.clacky/memories")
Instance Method Summary collapse
-
#cleanup_memory_messages ⇒ Object
Clean up memory update messages from conversation history after loop ends.
-
#inject_memory_prompt! ⇒ Object
Inject memory update prompt into @messages so the main agent loop handles it.
-
#should_update_memory? ⇒ Boolean
Check if memory update should be triggered for this task.
Instance Method Details
#cleanup_memory_messages ⇒ Object
Clean up memory update messages from conversation history after loop ends. Call this once after the main loop finishes.
59 60 61 62 63 64 65 66 |
# File 'lib/clacky/agent/memory_updater.rb', line 59 def return unless @memory_prompt_injected @history.delete_where { |m| m[:memory_update] } @memory_prompt_injected = false @memory_updating = false @ui&.clear_progress end |
#inject_memory_prompt! ⇒ Object
Inject memory update prompt into @messages so the main agent loop handles it. Builds the prompt dynamically, injecting the current memory file list so the LLM doesn’t need to scan the directory itself. Returns true if prompt was injected, false otherwise.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/clacky/agent/memory_updater.rb', line 39 def inject_memory_prompt! return false unless should_update_memory? return false if @memory_prompt_injected @memory_prompt_injected = true @memory_updating = true @ui&.show_progress("Updating long-term memory…") @history.append({ role: "user", content: build_memory_update_prompt, system_injected: true, memory_update: true }) true end |
#should_update_memory? ⇒ Boolean
Check if memory update should be triggered for this task. Only triggers when the task had enough LLM iterations, skipping short utility tasks (e.g. commit, deploy).
27 28 29 30 31 32 33 |
# File 'lib/clacky/agent/memory_updater.rb', line 27 def should_update_memory? return false unless memory_update_enabled? return false if @is_subagent # Subagents never update memory task_iterations = @iterations - (@task_start_iterations || 0) task_iterations >= MEMORY_UPDATE_MIN_ITERATIONS end |