Memory Management¶
Memories are the core primitive of Cognibrain — durable, scoped facts that coding agents can recall before acting.
What Is a Memory?¶
A memory is any piece of engineering knowledge worth preserving across sessions:
- Corrections: "Use
npm test, notpnpm test" - Conventions: "All API routes require auth middleware"
- Procedures: "Run
npm run buildbefore releasing" - Preferences: "Use single quotes in TypeScript"
- Evidence: "The auth refactor was completed on 2026-06-01"
- Facts: "The database schema uses UUID primary keys"
Creating Memories¶
From the CLI¶
npx cognibrain memories add "This repo uses npm test before release."
npx cognibrain memories add "Never edit generated files in dist/" --scope repo
From Agent Corrections¶
When an operator corrects an agent:
From Connector Events¶
Connectors can automatically create memories from external events (e.g., a merged PR that changes conventions).
Memory Scopes¶
Memories are scoped to control where they're recalled:
| Scope | Recalled when |
|---|---|
repo | Working in the associated repository |
user | Working as the associated user (any repo) |
global | Always available |
task | Relevant to specific task types |
npx cognibrain memories add "Deploy requires VPN" --scope repo
npx cognibrain memories add "I prefer verbose error messages" --scope user
Retrieving Memories¶
Context Pack¶
Get a curated set of memories for a specific task:
The context pack uses relevance scoring to return the most useful memories within a token budget.
Coding Context¶
Get corrections and conventions for specific files:
List All¶
Memory Lifecycle¶
stateDiagram-v2
[*] --> Active: Created
Active --> Active: Recalled / Reinforced
Active --> Stale: Not recalled for N days
Stale --> Active: Recalled again
Stale --> Review: Dream cycle flags
Review --> Active: Operator confirms
Review --> Archived: Operator removes
Archived --> [*] Memories follow a natural lifecycle:
- Active — recently created or recalled, participates in context packs
- Stale — not recalled for an extended period, candidate for review
- Under Review — flagged by a dream cycle for operator attention
- Archived — removed by operator, no longer recalled
Token Budgets¶
When requesting context, you can control how much memory is returned:
Cognibrain ranks memories by relevance and fills the budget with the most useful items. This prevents context windows from being overwhelmed with low-value recall.
Conflict Resolution¶
When memories contradict each other, Cognibrain uses:
- Recency — newer memories take precedence
- Source authority — operator corrections outrank auto-ingested facts
- Scope specificity — repo-scoped memories outrank global for in-repo work
- Dream cycle resolution — contradictions are surfaced for operator review
Best Practices¶
Be specific
"Use npm test" is better than "Run tests". Specific memories are easier to match and recall.
Include context
"In the auth module, always validate JWT expiry before refresh" beats "Validate JWT expiry".
Let agents self-correct
Configure your agent to call cognibrain correction whenever it receives human feedback. This builds memory organically.
Don't store secrets
Never store API keys, tokens, or passwords as memories. Use environment variables and reference them by name.