Skip to content

Memory Manager

Header: claw_memory.h

Common fields in claw_memory_config_t:

FieldMeaningbasic_demo default
session_root_dirRoot for session history files/fatfs/sessions
memory_root_dirLong-term memory directory (claw_memory manages MEMORY.md and all structured memory files under this directory)/fatfs/memory
max_session_messagesMax messages kept per session20
max_message_charsMax characters per message1024
enable_async_extract_stage_noteEnable async extract-stage notes for structured memorytrue in full mode

max_session_messages and max_message_chars together bound history size to avoid unbounded growth on flash and oversized history in prompts.

claw_memory connects via multiple Context Providers and Callback:

Context Providers (registered after claw_core_init):

  • claw_memory_profile_provider: inject editable profile/persona files (user.md / soul.md / identity.md).
  • claw_memory_long_term_provider (full mode): inject only the long-term summary-tag catalog, not the full memory text.
  • claw_memory_long_term_lightweight_provider (lightweight mode): inject MEMORY.md text directly.
  • claw_memory_session_history_provider: inject recent turns for the current session.

Write-back Callback:

  • claw_memory_append_session_turn_callback: passed as claw_core_config_t.append_session_turn; after each Agent turn, user/assistant text is appended to the session file.
  • Full mode also enables on_request_start and collect_stage_note for structured-memory auto-extraction.

basic_demo uses claw_memory_init to create required memory files under /fatfs/memory/:

  • Directoryfatfs/
    • Directorymemory/
      • memory_records.jsonl Structured memory records
      • memory_index.json Summary-tag and keyword index
      • memory_digest.log Memory-operation digest log
      • MEMORY.md Human-readable memory view (read-only)
      • user.md User profile
      • soul.md Persona
      • identity.md Identity