Skip to content

MuLIAICHI/cogdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CogDB β€” A Cognitive Database for AI Agents

License: MIT Python 3.10+ Status: v0.4.0 PRs Welcome

A second brain for AI agents β€” episodic, semantic, and procedural memory in one engine.

Quick Start Β· Architecture Β· Why CogDB Β· Roadmap Β· Research


🧠 The Problem

Every AI agent framework treats memory as someone else's problem.

You bolt on a vector database. Then a graph DB for relationships. Then SQLite for structured stuff. Now you're maintaining three backends that don't talk to each other. When two agents update the same fact at the same time, things break silently.

CogDB is a single database that gives AI agents a complete memory system. One install, one interface, one data store.

🌱 What CogDB Does Differently

CogDB unifies the three types of memory that map to how human cognition actually works:

🟒 Episodic

What happened

Timestamped records of agent interactions, observations, and tool calls. Stored as vector embeddings with full metadata. Agents search by similarity β€” "find me situations like this one."

🟒 Semantic

What is known

A temporal knowledge graph where facts have lifecycles. Facts get superseded automatically when newer ones contradict them. Confidence scores, validity windows, provenance links.

🟒 Procedural

How to do things

Learned workflows captured from successful agent task completions. Reusable templates with success tracking. This memory type basically doesn't exist in any other system.

⚑ Why CogDB

Capability Mem0 Zep Letta MemPalace CogDB
Episodic memory βœ“ βœ“ βœ“ βœ“ βœ“
Semantic / knowledge graph βœ“ βœ“ βœ“ βœ“ βœ“
Procedural memory ⚠️ βœ— ⚠️ βœ— βœ“
Token-aware retrieval βœ— βœ— βœ— ⚠️ βœ“
Multi-agent memory scopes scoped per-user shared per-agent 4 formal scopes
Single unified engine βœ— βœ— βœ— βœ— βœ“
MCP server βœ— βœ— βœ— βœ“ βœ“
AutoGen + LangGraph adapters partial βœ— βœ— βœ— βœ“
CrewAI adapter βœ— βœ— βœ— βœ— βœ“
OpenAI Agents SDK adapter βœ— βœ— βœ— βœ— βœ“
Semantic Kernel adapter βœ— βœ— βœ— βœ— βœ“
LlamaIndex adapter βœ— βœ— βœ— βœ— βœ“
Schema migration tooling βœ— βœ— βœ— βœ— βœ“

πŸ— Architecture

CogDB Architecture

Four layers, one engine:

  • Layer 1 β€” Agent Interface. Drop-in adapters for AutoGen, LangGraph, CrewAI, OpenAI Agents SDK, Semantic Kernel, and LlamaIndex. MCP server so any MCP-compatible agent can connect. Native Python SDK.
  • Layer 2 β€” Query Planner. Token-aware retrieval routes queries across stores and packs results into the budget you set. Highest importance first, nothing wasted.
  • Layer 3 β€” Cognitive Pipeline. Encoding, storage, consolidation, retrieval, and decay. Memories don't just sit there β€” they evolve.
  • Layer 4 β€” Tri-Memory Store. Episodic (vector embeddings), semantic (temporal knowledge graph), procedural (workflow templates). Three stores, one query interface.

πŸš€ Quick Start

pip install git+https://github.com/MuLIAICHI/cogdb.git
from cogdb import CognitiveDB

db = CognitiveDB(db_path="./agent_memory")

# 🟒 Store an episodic memory
db.remember(
    "Deployed v2.3 to production. CORS error on /users endpoint.",
    agent_id="devops-agent",
    importance=0.9,
)

# 🟒 Store a semantic fact (gets superseded automatically when contradicted)
db.learn(
    subject="api_service",
    predicate="version",
    object="v2.3",
    agent_id="devops-agent",
    confidence=1.0,
)

# 🟒 Store a procedural workflow
db.learn_procedure(
    name="fix_cors_error",
    steps=[
        {"action": "check_nginx_config", "tool": "cat /etc/nginx/conf.d/api.conf"},
        {"action": "add_cors_headers", "tool": "sed"},
        {"action": "reload_nginx", "tool": "systemctl reload nginx"},
        {"action": "verify", "tool": "curl -I"},
    ],
    agent_id="devops-agent",
    applicable_contexts=["cors", "nginx", "api"],
)

# 🟒 Recall with a token budget
memories = db.recall(
    "How do we fix CORS errors?",
    agent_id="devops-agent",
    token_budget=500,
)

# 🟒 Get progressive context (L0 β†’ L3)
context = db.get_context(
    agent_id="devops-agent",
    level=2,
    task_hint="API gateway returning 403 on preflight",
    token_budget=800,
)

πŸ”Œ Integrations

🟒 AutoGen

from cogdb.adapters.autogen import CogDBMemory
from autogen_agentchat.agents import AssistantAgent

memory = CogDBMemory(db_path="./memory")
agent = AssistantAgent(
    name="assistant",
    memory=[memory],
)

Drop-in replacement for AutoGen's basic ListMemory.

🟒 LangGraph

from cogdb.adapters.langgraph import (
    CogDBCheckpointer,
    CogDBStore,
)

graph = StateGraph(State).compile(
    checkpointer=CogDBCheckpointer(...),
    store=CogDBStore(...),
)

Native BaseCheckpointSaver and BaseStore implementations.

🟒 MCP Server

cogdb-mcp --db-path ./memory

Exposes 6 tools β€” remember, recall, learn, learn_procedure, get_context, forget β€” to any MCP-compatible agent (Claude Code, Cursor, Windsurf).

🟒 CrewAI

from cogdb.adapters.crewai import CogDBCrewAIStorage

memory = CogDBCrewAIStorage(
    agent_id="my-crew-agent",
    db_path="./memory",
)
# Pass to CrewAI agent via memory_config

Drop-in Storage implementation for CrewAI agents.

🟒 OpenAI Agents SDK

from cogdb.adapters.openai_agents import (
    CogDBAgentMemory,
    make_memory_tools,
)

mem = CogDBAgentMemory(agent_id="my-agent")
tools = make_memory_tools(mem)
# Add tools to your Agent

Exposes remember, recall, and get_context as agent tools.

🟒 Semantic Kernel

from cogdb.adapters.semantic_kernel import CogDBMemoryStore

store = CogDBMemoryStore(
    agent_id="sk-agent",
    db_path="./memory",
)
# Use as SK MemoryStoreBase

Full async MemoryStoreBase implementation.

🟒 LlamaIndex

from cogdb.adapters.llamaindex import CogDBChatMemory

memory = CogDBChatMemory.from_defaults(
    agent_id="li-agent",
    db_path="./memory",
)
# Use as LlamaIndex BaseMemory

BaseMemory + CogDBVectorIndex for chat and retrieval agents.

🟒 Schema Migration

from cogdb.schema.migration import SchemaMigration
from cogdb.schema import FieldSchema

migration = (
    SchemaMigration(agent_id="my-agent",
                    from_version=1, to_version=2)
    .add_field("priority", FieldSchema(type="int"), default=0)
    .rename_field("tags", "labels")
)
db.migrate_schema(migration)

Safe versioned schema evolution with metadata backfill.

πŸ“Š Token-Aware Retrieval

This is the part that took the most iteration. Most memory systems dump a wall of context into the LLM and hope for the best. CogDB does it in tiers:

β”Œβ”€ Token Budget: 500 ──────────────────────────────────┐
β”‚                                                       β”‚
β”‚  L0  Identity              ~50 tokens     [filled]    β”‚
β”‚  L1  Critical facts       ~200 tokens     [filled]    β”‚
β”‚  L2  Task-relevant        ~250 tokens     [filled]    β”‚
β”‚  L3  Deep search             0 tokens     [skipped]   β”‚
β”‚                                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Set a budget, CogDB fills it from the top with the highest-importance memories that fit. The agent gets exactly what it needs and nothing it doesn't β€” which means faster responses, lower API costs, and no context window blowouts.

πŸ‘₯ Multi-Agent Memory Scopes

When you have multiple agents working together, they need different levels of memory access. CogDB has four formal scopes with consistency guarantees:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  🟒 Organization      All agents read       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  🟒 Team        Group read-write    β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚    β”‚
β”‚  β”‚  β”‚  🟒 Private   Single agent  β”‚    β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  🟒 Session  Ephemeral, auto-deleted        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Contradiction detection runs at write time. Conflict resolution handles concurrent writes. No silent data loss when agents collaborate.

πŸ—Ί Roadmap

  • βœ… Phase 0 β€” Python PoC v0.2.0 β€” Tri-memory engine, pipeline, AutoGen + LangGraph + MCP adapters.
  • βœ… Phase 1 β€” Rust Engine v0.3.0 β€” Purpose-built storage with HNSW, WAL, crash recovery, PyO3 bindings.
  • βœ… Phase 2 β€” ML Retrieval v0.4.0 β€” Learned importance model, HNSW rank blending, tokenised procedure search. Suite 1 benchmark: 90.7 / 100.
  • βœ… Phase 3A β€” Typed Schemas β€” Dynamic metadata schemas, per-agent validation, strict/non-strict modes.
  • βœ… Phase 3C β€” Schema Migration β€” Versioned add/rename/drop/change_type with metadata backfill. db.migrate_schema().
  • βœ… Adapters expansion β€” CrewAI, OpenAI Agents SDK, Semantic Kernel, LlamaIndex. 6 framework adapters total.
  • πŸ”„ Phase 3B β€” Metadata Indexing (next) β€” SQLite indexes on queried metadata keys (requires Rust store changes).
  • πŸ“‹ Phase 4 β€” Distributed β€” Clustered WAL replication, multi-node deployment.

πŸ“š Research

CogDB is grounded in academic research on cognitive architectures, learned database systems, and multi-agent memory:

  • CoALA (Sumers, Yao et al., 2024) β€” Cognitive Architectures for Language Agents
  • JEPA (LeCun, 2022) β€” A Path Towards Autonomous Machine Intelligence
  • Learned Index Structures (Kraska et al., 2018) β€” Neural networks replacing B-Trees
  • Multi-Agent Memory Architecture (UCSD, 2026) β€” Cache coherence for agent memory

Full landscape analysis covering 15+ existing systems β†’ docs/research.md

🀝 Contributing

CogDB is in early development and contributions are welcome across:

  • Framework adapters β€” LlamaIndex plugins, custom integrations
  • Benchmarks β€” LongMemEval, comparison vs Mem0/Zep
  • Core engine β€” Memory consolidation, importance scoring, retrieval
  • Research β€” New memory system analyses, academic paper reviews

See CONTRIBUTING.md to get started.

πŸ“„ License

MIT β€” see LICENSE.

πŸ“– Citation

If you use CogDB in research or production:

@software{cogdb2026,
  title  = {CogDB: A Cognitive Database for AI Agents},
  author = {Mustapha Liaichi},
  year   = {2026},
  url    = {https://github.com/MuLIAICHI/cogdb}
}

Built by Mustapha Liaichi Β· AYAutomate

If CogDB saves you from stitching together three databases, ⭐ the repo.

About

CogDB is a single database that gives AI agents a complete memory system. One install, one interface, one data store.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors