Memory System
How AGH stores persistent memory, injects memory indexes into prompts, and exposes memory files through CLI and API surfaces.
- Audience
- Operators running durable agent work
- Focus
- Memory guidance shaped for scanability, day-two clarity, and operator context.
AGH memory is persistent Markdown that survives across sessions. It is designed for durable facts that future agents should be able to discover without replaying every old transcript.
The current implementation is intentionally small:
- memory is file-based, not stored in SQLite
- there are two scopes: global and workspace
- each scope has a
MEMORY.mdindex - only indexes are injected into startup prompts
- full memory files are read on demand with
agh memory read
Runtime Flow
Rendering diagram...
Memory is not streamed into an already-running process. When a session starts, AGH loads the global and workspace indexes, prepends them to the agent prompt, and hands that assembled prompt to the ACP subprocess. New memory written during the session becomes visible to the next session.
Four Memory Types
Every memory file has one of four types. The type also determines the default write scope when you
do not pass --scope.
| Type | Default scope | Use it for | Example |
|---|---|---|---|
user | global | Stable user preferences, working style, or recurring personal context. | "Prefer concise PR summaries with risk and test notes." |
feedback | global | Repeated corrections, review guidance, and quality signals that apply across work. | "Do not weaken tests to match broken behavior." |
project | workspace | Decisions, constraints, active architecture, and local project facts. | "This repo keeps docs site pages under packages/site/content/runtime/." |
reference | workspace | External references, runbooks, links, or system facts worth re-reading on demand. | "Production logs live in the hosted provider console, not local files." |
The taxonomy is closed. Unsupported types are rejected.
Memory File Format
Memory files are Markdown files with strict YAML frontmatter.
Required fields:
| Field | Required | Meaning |
|---|---|---|
name | yes | Human-readable title shown in list output and useful in index entries. |
type | yes | One of user, feedback, project, or reference. |
description | no for the store, required by the CLI writer | One concise discovery sentence. |
agent_name | no | Optional producer hint for team memory and audits. |
Example user memory:
---
name: Review Style
description: User wants concise review findings with file references first
type: user
---
When reviewing code, put blocking findings first and cite the file path and symbol. Keep summaries
short unless the user asks for deeper explanation.Example feedback memory:
---
name: Test Integrity
description: Production bugs must be fixed instead of weakening tests
type: feedback
---
If a test reveals incorrect behavior, fix the production code. Do not relax assertions just to make
the suite green.Example project memory:
---
name: Runtime Docs Location
description: Runtime documentation pages live in the Fumadocs runtime collection
type: project
agent_name: codex
---
AGH runtime docs are authored under `packages/site/content/runtime/` and build to `/runtime/*`.
Protocol pages live in a separate `/protocol/*` collection.Example reference memory:
---
name: Session Events API
description: Stored session events are available through the stream endpoint
type: reference
---
Use `GET /api/sessions/:id/stream` for persisted SSE replay. Use `agh session events <id>` when
working from the CLI.MEMORY.md Indexes
Each scope can include a MEMORY.md file next to the memory documents:
~/.agh/memory/
MEMORY.md
review-style.md
test-integrity.md
<workspace>/.agh/memory/
MEMORY.md
runtime-docs-location.md
session-events-api.mdThe index is the prompt-safe table of contents. AGH reads it at session start and injects it into the prompt. A useful index entry is short and points to one file:
- [Review Style](review-style.md) - User wants concise review findings with file references first.
- [Runtime Docs Location](runtime-docs-location.md) - Runtime docs live under `packages/site/content/runtime/`.Index behavior:
| Behavior | Current implementation |
|---|---|
Missing MEMORY.md | AGH synthesizes an index from memory-file frontmatter for that scope and can warn when an existing index is stale. |
| Prompt limits | Loaded indexes are capped at 200 lines and 25 KB before injection. |
| Write behavior | agh memory write validates the memory file, writes it, and synchronizes the scope index so new entries become discoverable. |
| Delete behavior | Deleting a memory file also removes index lines that link to that filename. |
| Full file content | Not injected. Agents read full files on demand with agh memory read <filename>. |
Dream consolidation is the normal way to tighten memory files over time. Manual writes and deletes still keep the index synchronized so the next session can discover changed memories.
Operator Visibility
Memory has two operator-facing visibility surfaces:
| Surface | Use it for |
|---|---|
agh memory health | Inspect enabled/configured state, global and workspace file counts, catalog health, recent operation counts, and dream consolidation state. |
agh memory history | Inspect recent memory writes, deletes, searches, and reindex operations with scope, workspace, filename, and redacted summaries. |
The same typed data is available through GET /api/memory/health and
GET /api/memory/history. History output is intentionally bounded and redacted before it is
returned to CLI or API clients.
These visibility surfaces do not change prompt assembly. Runtime prompts still receive only the startup memory index snapshot described above; future context-reference and provider-hook support will be integrated by a separate runtime task.
Prompt Injection
When memory is enabled, AGH prepends a # Persistent Memory section to the startup prompt. That
section can include:
- Global
MEMORY.mdindex - Workspace
MEMORY.mdindex - The four-type taxonomy
- A short command guide for
agh memory list,agh memory read, andagh memory write - A staleness warning policy
This memory block is assembled before the agent's AGENT.md body. The skills catalog is appended
after the base prompt when skills are enabled, so memory gives the agent durable context before it
starts applying reusable skills.
Basic Workflow
Write a global preference:
agh memory write review-style.md \
--type user \
--description "User wants concise review findings with file references first" \
--content "Put blocking findings first. Cite file paths and symbols."Write a workspace decision:
agh memory write runtime-docs-location.md \
--type project \
--description "Runtime docs live in the Fumadocs runtime collection" \
--content 'Runtime docs are authored under `packages/site/content/runtime/` and build to `/runtime/*`.'List memories:
agh memory listRead the full file when an index entry looks relevant:
agh memory read runtime-docs-location.md --scope workspaceRelated Pages
- Scopes explains global and workspace storage rules.
- Dream Consolidation explains automatic cleanup and index tightening.
- Memory Best Practices gives concrete writing and hygiene guidance.
- Memory CLI Reference lists every generated memory command.