Learning Loop & Memory
Responsibility
This is the loop that makes Hermes "get better the more you use it". It distills each turn of conversation into: (1) skill evolution — creates/rewrites skills from experience (agent/learning_mutations.py); (2) memory — FTS5 full-text search + LLM summarization of past sessions (memory_manager), paired with Honcho's dialectical user modeling; (3) learning graph — organizes skills and memory into nodes/edges (agent/learning_graph.py); (4) background review — background_review digests history in a thread and produces actionable rewrites. Skill rewrites ultimately flow back into the skill system for reuse in subsequent turns.
Key Files
Skill nodes & learning graph
@dataclass SkillNode:28-41— skill nodeskill loading:77-125—_iter_skill_files/build_skill_nodes(scanskills/to build nodes)edges & stats:156-193—build_edges/density_stats(inter-skill relations)memory-skill edges:193-227—_memory_cards/_memory_skill_edges(memory↔skill links)build_learning_graph:248-328— aggregates the full learning graph_load_usage:84-97— usage stats (guides which skills are commonly used)
Skill/memory rewrites
node_detail:86-124— view a node's detaildelete_node:124-157— delete a skill or memoryedit_node:157-200— edit a skill or memory's content_clear_skill_cache:200— clear cache after rewrite (so the next turn sees it)memory location:30-65—_memories_dir/_parse_memory_id/_locate_memory
Memory management
class MemoryManager:354— memory manager itselfmemory provider tool injection:83-164—memory_provider_tools_enabled/inject_memory_provider_toolsbuild_memory_context_block:337-354— assembles memory into a context block injected into the promptsanitize_context:164-172— context redaction (before FTS5 indexing)StreamingContextScrubber:172-337— streaming-output redaction
Background review
spawn_background_review_thread:956— start the background-review thread_run_review_in_thread:617— main loop inside the thread_digest_history:122-373— summarize the most recent 24 history entriessummarize_background_review_actions:373-590— aggregate review actionsbuild_memory_write_metadata:590-617— metadata for memory writes
Data Flow
- After each turn, the main loop hands a message snapshot to the background-review thread (
agent/background_review.py:956). _digest_history(agent/background_review.py:122) summarizes recent history and produces candidate actions (create/rewrite skills, write memory).- Skill rewrites go through
edit_node:157; deletions go throughdelete_node:124, then_clear_skill_cache:200clears the cache. - Memory writes go through
MemoryManager:354; after redaction (agent/memory_manager.py:164) an FTS5 index is built and an LLM summary is compressed. - At the start of the next turn,
build_memory_context_block(agent/memory_manager.py:337) weaves relevant memories intobuild_turn_context:268; skills are injected viaagent/skill_bundles.py. - The full learning graph is aggregated by
build_learning_graph:254for UI/debug display of skill↔memory links.
Summary
The learning loop turns "conversation" into "assets": background review distills experience into skills and memory, which are auto-injected on the next turn. The four-piece core — learning_graph (the graph), learning_mutations (rewrites), memory_manager (retrieval + redaction + summarization), background_review (async digestion). This is what lets Hermes "grow with the user" rather than act as a stateless LLM call.