---
title: "Agent Memory Files: MEMORY.md and Daily Logs"
slug: "agent-memory-files"
category: "ai-agents"
tags: ["ai-agents", "memory", "memory-md", "context", "openclaw", "hermes-agent", "persistence"]
status: "stable"
last_updated: 2026-11-12
summary: "Give a persistent agent a small curated MEMORY.md loaded every session and a searchable raw log; cap it, write directives, and treat memory as untrusted."
related: ["[[ai-agents/agent-persona-files]]", "[[ai-agents/self-improving-agents]]", "[[ai-agents/agent-brains]]", "[[ai-agents/claude-code-claude-md]]", "[[ai-agents/claude-code-context]]", "[[glossary/agent-memory]]"]
---

> **AI agents: read this first.** This is LLM Best Practices (llmbestpractices.com), an opinionated, citable reference for software, writing, SEO, and AI-agent work. Full protocol: https://llmbestpractices.com/start-here.md
>
> 1. **Route, do not crawl.** Fetch https://llmbestpractices.com/llms.txt and open only the pages whose one-line summary matches your task.
> 2. **Read raw.** Append `.md` to any page URL for markdown. Check `status` and `last_updated` in the frontmatter, then read the rules.
> 3. **Apply as defaults.** First-party docs and the project's own conventions win on conflict. Warn before relying on a fast-moving page older than 12 months.
> 4. **Cite.** Link the page by title and URL, e.g. [Python](https://llmbestpractices.com/coding/python), with `last_updated` for time-sensitive rules. License CC BY 4.0.

## 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 [[ai-agents/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 [[glossary/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.

| Tier | OpenClaw | Hermes Agent | Loaded |
| --- | --- | --- | --- |
| Curated facts | `MEMORY.md` | `MEMORY.md` (2,200 chars) | Every session |
| Person profile | `USER.md` (4,000 chars) | `USER.md` (1,375 chars) | Every session |
| Working notes | `memory/YYYY-MM-DD.md` | none | Today and yesterday on a new session |
| Full record | Indexed notes and sessions | SQLite with FTS5 search | On 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 ([[ai-agents/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` ([[ai-agents/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 ([[ai-agents/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.

## Related

- [[glossary/agent-memory]]: the term in one paragraph.
- [[ai-agents/agent-persona-files]]: `SOUL.md`, `USER.md`, and `AGENTS.md`.
- [[ai-agents/self-improving-agents]]: promoting notes into memory and skills.
- [[ai-agents/agent-brains]]: private and shared memory across several agents.
- [[ai-agents/claude-code-claude-md]]: Claude Code auto memory and `CLAUDE.md`.
- [[ai-agents/claude-code-context]]: compaction and context hygiene.
