Overview

Split agent memory into two tiers: a small curated file the agent reads at every session start, and a large raw record it searches only when needed. Cap the curated tier hard. Hermes Agent limits MEMORY.md to 2,200 characters (about 800 tokens) and USER.md to 1,375; Claude Code loads the first 200 lines or 25KB of its auto-memory MEMORY.md. Everything else, such as full transcripts and daily notes, stays on disk behind a search tool. Memory is model-readable text, so it carries the same injection risk as any retrieved document. The persona files that sit beside it are in agent-persona-files.

Keep the always-loaded tier small and curated

The curated file is paid for on every turn and competes with the task for the context-window. OpenClaw describes its MEMORY.md as a compact layer, “not a raw transcript, daily log, or exhaustive archive.” Hold durable facts and decisions there: environment quirks, project conventions, a choice and its reason. Push detail down a tier.

TierOpenClawHermes AgentLoaded
Curated factsMEMORY.mdMEMORY.md (2,200 chars)Every session
Person profileUSER.md (4,000 chars)USER.md (1,375 chars)Every session
Working notesmemory/YYYY-MM-DD.mdnoneToday and yesterday on a new session
Full recordIndexed notes and sessionsSQLite with FTS5 searchOn demand by tool

Search the raw record instead of loading it

Give the agent a search tool over everything it has seen. OpenClaw’s memory_search combines vector similarity with keyword matching, so it finds both paraphrases and exact IDs; Hermes stores every session in SQLite with full-text search and returns the stored messages verbatim. The pattern is ordinary retrieval (rag-retrieval) over your own history.

Write directives, and replace them in place

  • Write the current rule, not its history: “Use pnpm, not npm,” not “On March 3 we switched to pnpm.” OpenClaw’s docs ask for USER.md entries as “current directives without date/status metadata.”
  • Replace a changed preference instead of appending a second one. Two contradictory lines leave the model guessing which is current.
  • Date only what expires, and add the expiry: “Staging DB is read-only until 2026-12-01.”
  • Keep the person’s profile in USER.md and the agent’s own learnings in MEMORY.md, so a profile edit never deletes a project fact.

Consolidate before the cap, not after

Hermes does not auto-compact: a write that would exceed the cap fails, and the agent must remove or shorten entries in one batch. Its docs advise consolidating past 80 percent usage. Run the same rule by hand on any memory file: merge duplicates, delete stale entries, and move detail to the log tier.

Save before the context is compacted

When a session’s history is summarized, anything not written to disk is gone. OpenClaw runs a silent turn before compaction that asks the agent to save important context, appending only to the daily note. In Claude Code, write the state to a file before running /compact (claude-code-context).

Expect a fresh write to show up next session

Hermes injects memory as a frozen snapshot at session start; a write made mid-session is saved at once but enters the system prompt only in the next session, which keeps the prompt cache valid. Read the file through a tool if the current session needs the new value.

Treat memory as untrusted input

An agent that reads a web page and saves a “fact” from it has let that page write into every future prompt. Defend the write path:

  • Scan writes. Hermes rejects memory entries matching injection, credential-exfiltration, and invisible-Unicode patterns.
  • Require approval for writes in shared or production agents. Hermes ships write_approval off by default; turn it on.
  • Never store secrets in memory files.
  • Version the memory directory in Git so a poisoned entry can be found and reverted (prompt-injection-defense).

Memory states facts; it does not enforce rules. OpenClaw’s docs say memory “does not enforce policy,” so put hard limits in permissions and approval gates.