DEV Community

AgentBrain.ch
AgentBrain.ch

Posted on • Originally published at agentbrain.ch

Why we built a 7-layer cognitive memory for AI agents

Every AI agent framework has the same blind spot: memory.

You can give your agent tools, planning capabilities, and access to APIs. But between sessions, it forgets everything. The next conversation starts from zero. Context is gone. Preferences are gone. Learned behaviors are gone.

The common fix is RAG — store text as vector embeddings, retrieve by similarity. It works for document search. But it's not memory.

Real memory has priority. It has emotion. It has decay. Things that don't matter fade away. Things that matter get reinforced. Similar experiences merge into generalized knowledge. And sometimes, connections appear between things you never explicitly linked.

We built Agent Brain to bring these properties to AI agents.

The problem with current approaches

Most AI memory systems do one thing: store embeddings and retrieve them by cosine similarity. Some add metadata filtering. Some add a reranking step. But fundamentally, they treat every piece of information as equally important, store it permanently, and retrieve it through a single mechanism.

This creates three problems:

Noise accumulation. Everything gets stored. After thousands of interactions, the memory fills with low-value data that degrades retrieval quality.

Flat recall. Retrieval is one-dimensional — similarity. There's no concept of urgency, emotional significance, or how recently something was accessed.

No learning. The memory is static. It doesn't consolidate, generalize, or find patterns. It's a database, not a cognitive system.

7 layers inspired by cognitive science

Agent Brain implements 7 layers modeled on how human memory actually works.

Layer 1: Perception Gate

Before anything enters memory, it passes through the Perception Gate. Every input gets scored on four axes:

  • Emotion (-1 to +1): How emotionally significant is this?
  • Novelty (0 to 1): How new or surprising is it?
  • Urgency (0 to 1): How time-sensitive?
  • Source Trust (0 to 1): How reliable is the source?

This is modeled on thalamic gating — most sensory data never reaches conscious processing.

response = requests.post("https://api.agentbrain.ch/memory/store", headers={
    "X-API-Key": "YOUR_KEY"
}, json={
    "workspace_id": "YOUR_WS",
    "content": "User prefers dark mode",
    "agent_id": "assistant-1",
    "source_trust": 0.9
})
Enter fullscreen mode Exit fullscreen mode

Layer 2: Working Memory

Based on Miller's Law (1956), working memory holds exactly 7 items. When the buffer is full, the lowest-scoring item gets evicted.

Layer 3: Episodic Memory

Long-term memories with pgvector similarity search. Unlike a plain vector DB, recall is ranked by semantic similarity + recency + emotional weight + access frequency.

response = requests.post("https://api.agentbrain.ch/memory/recall", headers={
    "X-API-Key": "YOUR_KEY"
}, json={
    "workspace_id": "YOUR_WS",
    "query": "user interface preferences",
    "limit": 5
})
Enter fullscreen mode Exit fullscreen mode

Layer 4: Knowledge Graph

Entities extracted via spaCy get linked into a relationship graph. Recalling one concept activates related concepts — spreading activation theory.

Layer 5: Procedural Memory

Detects repeated patterns after 3+ occurrences. Stores successful action sequences as procedures. Your agent builds institutional intuition.

Layer 6: Predictive Engine

Runs every 60 minutes. Tracks temporal patterns and generates probability-scored alerts: "87% chance of heating issue for Property X within 30 days."

Layer 7: Dream Cycle

A nightly batch process (default: 2 AM) that performs three operations:

Ebbinghaus Decay. Every memory has a strength score that decays over time. Frequently accessed or emotionally significant memories decay slower. Below threshold = pruned.

Consolidation. Near-duplicate memories merge into unified, stronger representations.

Creative Synthesis. Non-obvious connections between memories that share entities but weren't explicitly linked. Mirrors REM sleep.

No LLM required

Agent Brain makes zero LLM API calls.

  • Embeddings: sentence-transformers (local, 384 dimensions)
  • Entity extraction: spaCy (local)
  • Similarity search: pgvector in PostgreSQL
  • Decay and consolidation: Pure math

Memory operations need to be fast, cheap, and deterministic.

Self-host or managed

Open source under AGPLv3:

git clone https://github.com/kaderosio/agent-brain
cd agent-brain
docker build -t agent-brain .
docker run -p 8000:8000 --env-file .env agent-brain
Enter fullscreen mode Exit fullscreen mode

Managed hosting: CHF 29/mo. Swiss hosted.

For comparison: Mem0 Pro $249/mo, Zep Pro ~$50/mo, Letta Cloud $200/mo.

Try it now

If you're building AI agents and want memory that actually behaves like memory, give Agent Brain a look.


Built by Valtis AG, Zürich

Top comments (0)