Skip to content

JohnnyFiv3r/Core-Memory

Core Memory

Apache-2.0 License Python 3.10+

Causal memory for AI agents.
Structured memory objects + causal trace over durable events β€” so agents can recall why, not just what.

Install Β· Fastest Paths Β· Service Mode Β· Current Status Β· Architecture Β· Public Surface Β· Contributing Β· Maintainers


Reviewer Quick Path

  1. core-memory --root ./memory setup init
  2. CORE_MEMORY_CANONICAL_SEMANTIC_MODE=degraded_allowed PYTHONPATH=. python3 examples/canonical_5min.py
  3. PYTHONPATH=. python3 examples/proof_carry_forward.py
  4. PYTHONPATH=. python3 -m eval.reviewer_quick_value_v2 --root ./memory --strict

Optional follow-up telemetry (proxy-style, not full strategy replay benchmark):

  • PYTHONPATH=. python3 -m eval.dreamer_behavior_eval --root ./memory --since 30d
  • PYTHONPATH=. python3 -m eval.longitudinal_benchmark_v2 --root ./memory --since 30d

Then use:

Current Status

  • Canonical surfaces: process_turn_finalized(turns=[...]) / process_session_start / process_flush + search / trace / execute
  • Adapter helper ingress: emit_turn_finalized(...) remains supported for bridge/integration adapters
  • Compatibility surfaces: archived or non-primary docs/modules retained for migration/history only
  • Experimental areas: optional adapters and evaluation harnesses that are useful but not yet hard product contract
  • Not yet integrated: ideas/proposals not represented in canonical docs or adapter references are intentionally out of current contract scope

Product Contract (Plain English)

If you're new here, this is the shortest trust contract for what is stable now:

  • Required (core product):
    • write memory with process_turn_finalized(turns=[...])
    • read memory with memory search|trace|execute (or Python equivalents)
  • Recommended for most users:
    • keep CORE_MEMORY_CANONICAL_SEMANTIC_MODE=degraded_allowed on base installs
    • install core-memory[semantic] when you want strict semantic retrieval behavior
  • Compatibility (supported, not primary):
    • direct MemoryStore workflows
    • legacy CLI aliases like recall ...
  • Experimental / adapter-specific:
    • optional integrations and eval harnesses that are not listed as canonical surfaces

If a feature is not in this contract or docs/public_surface.md, treat it as non-primary.

30-second tier map (mandatory vs optional)

  • Required
    • base install: pip install core-memory
    • canonical write boundary: process_turn_finalized(turns=[...])
    • canonical retrieval: memory search|trace|execute (or Python equivalents)
  • Recommended
    • semantic extras: pip install "core-memory[semantic]"
    • strict semantic retrieval mode (CORE_MEMORY_CANONICAL_SEMANTIC_MODE=required) when you need hard semantic guarantees
  • Compatibility (supported, not primary)
    • MemoryStore direct workflows
    • adapter helper ingress emit_turn_finalized(...)
  • Experimental / optional extensions
    • Neo4j shadow adapter (visualization/inspection)
    • eval harnesses under eval/

Plain-English glossary for first-touch terms

  • canonical semantic mode β†’ strict semantic retrieval mode
  • degraded_allowed β†’ allow lexical fallback if semantic backend is missing
  • companion service β†’ optional HTTP service mode
  • hydration β†’ load source details after selecting retrieval results

Live Demo

Core Memory live demo (click to watch on YouTube)

Watch the Core Memory live demo on YouTube


What Is Core Memory?

Most agent memory systems store what happened. Core Memory stores why it happened.

It records structured memory events called beads β€” decisions, lessons, outcomes, evidence, context β€” and the causal links between them. When an agent asks β€œwhy did we change strategy?”, Core Memory retrieves a decision chain, not just keyword matches.

Why use it?

Approach Failure Mode Core Memory
Chat log replay Context window explodes Bounded rolling window with compaction
Vector similarity β€œSimilar” β‰  β€œrelevant” Semantic-first anchors + causal trace over explicit bead links
Tool call logs No reasoning structure Explicit bead β†’ bead associations

Core local write flow has zero required runtime dependencies beyond Python. Query-based anchor lookup in canonical mode requires semantic backend support (or explicit degraded mode opt-in). Optional extras exist for HTTP service mode and integration-specific workflows.


Install

From PyPI

pip install core-memory

From source

git clone https://github.com/JohnnyFiv3r/Core-Memory.git
cd Core-Memory
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .

Optional extras

Semantic backend extras (recommended for canonical query path):

pip install "core-memory[semantic]"

If you want provider-backed semantic embeddings, install the matching client library in the same Python environment. For example, OpenAI-backed semantic retrieval needs:

pip install openai

HTTP companion service:

pip install "core-memory[http]"

PydanticAI adapter:

pip install "core-memory[pydanticai]"

Neo4j shadow graph adapter (visualization/inspection only):

pip install "core-memory[neo4j]"

Developer/test extras:

pip install "core-memory[dev]"

Fastest Paths

1) Friendliest Python path

Use capture for observed conversation writes and recall for single-query reads. capture is the quick-start helper for the canonical process_turn_finalized(turns=[...]) boundary; recall currently delegates to memory_execute(...). See docs/concepts/turn_schema.md for the multi-speaker turn schema and migration notes.

from core_memory import capture, recall

root = "./memory"

capture(
    root=root,
    session_id="quickstart",
    turn_id="t1",
    user="Why did we choose Postgres?",
    assistant="Decision: choose Postgres because JSONB lowers integration risk.",
)

out = recall("why did we choose Postgres?", root=root)
print(out.get("ok"), len(out.get("results") or []))

remember(...) is intentionally not part of this surface yet; that future verb is reserved for declarative user-authored memory writes (tracked separately in TODO #21 / future PRD work).

2) Smallest believable product path (5 minutes)

No adapters, no direct MemoryStore calls, canonical boundaries only.

core-memory --root ./memory setup init

# Base install path (no semantic extras)
export CORE_MEMORY_CANONICAL_SEMANTIC_MODE=degraded_allowed
python3 - <<'PY'
from core_memory import process_turn_finalized, memory_execute

root = "./memory"
process_turn_finalized(
    root=root,
    session_id="five-minute",
    turn_id="t1",
    turns=[
        {"speaker": "user", "role": "user", "content": "What should we do about Redis timeouts?"},
        {"speaker": "assistant", "role": "assistant", "content": "Decision: increase pool size to 200."},
    ],
)
out = memory_execute(
    request={"raw_query": "why redis timeouts", "intent": "causal", "k": 5},
    root=root,
    explain=True,
)
print({
    "ok": out.get("ok"),
    "degraded": out.get("degraded", False),
    "result_count": len(out.get("results") or []),
})
PY

Expected output:

  • ok: true
  • a non-zero result_count
  • degraded: true is acceptable in this base-install path

If you want strict canonical semantic mode instead:

pip install "core-memory[semantic]"
unset CORE_MEMORY_CANONICAL_SEMANTIC_MODE
python3 - <<'PY'
from core_memory import process_turn_finalized, memory_execute

root = "./memory"
process_turn_finalized(
    root=root,
    session_id="five-minute",
    turn_id="t1",
    turns=[
        {"speaker": "user", "role": "user", "content": "What should we do about Redis timeouts?"},
        {"speaker": "assistant", "role": "assistant", "content": "Decision: increase pool size to 200."},
    ],
)
out = memory_execute(
    request={"raw_query": "why redis timeouts", "intent": "causal", "k": 5},
    root=root,
    explain=True,
)
print({
    "ok": out.get("ok"),
    "degraded": out.get("degraded", False),
    "result_count": len(out.get("results") or []),
})
PY

Source-checkout equivalent example script:

PYTHONPATH=. python3 examples/canonical_5min.py

3) Canonical Python runtime/retrieval path

from core_memory import process_turn_finalized, memory_execute

root = "./memory"

process_turn_finalized(
 root=root,
 session_id="s1",
 turn_id="t1",
 turns=[
  {"speaker": "user", "role": "user", "content": "Why did Redis fail?"},
  {"speaker": "assistant", "role": "assistant", "content": "Decision: increase Redis pool to 200 to prevent exhaustion."},
 ],
)

out = memory_execute(
 request={"raw_query": "why redis", "intent": "causal", "k": 5},
 root=root,
 explain=True,
)

print(out.get("ok"), len(out.get("results") or []))

4) CLI retrieval surface

Once memory exists, canonical retrieval CLI is:

core-memory --root ./memory memory search --query "redis pool"
core-memory --root ./memory memory trace --query "why redis pool"
core-memory --root ./memory memory execute --request '{"raw_query":"why redis","intent":"causal","k":5}'

5) Compatibility store API (advanced / direct persistence)

MemoryStore remains available for direct persistence workflows and migrations, but it is not the primary canonical runtime path.

See:

  • examples/store_compat_quickstart.py

Service Mode (SpringAI / HTTP)

For JVM, JS/TS-adjacent, or service-oriented architectures, run Core Memory as a companion HTTP service.

Start the service

python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[http]"
python3 -m core_memory.integrations.http.server

Equivalent startup command:

python3 -m uvicorn core_memory.integrations.http.server:app --host 0.0.0.0 --port 8000

Optional auth:

export CORE_MEMORY_HTTP_TOKEN="change-me"

Verify the service

curl http://localhost:8000/healthz
curl -X POST http://localhost:8000/v1/memory/execute \
 -H "Content-Type: application/json" \
 -d '{
 "request": {
 "raw_query": "why did we change strategy?",
 "intent": "causal",
 "k": 5
 },
 "explain": true
 }'

SpringAI write path

Send finalized assistant turns to:

  • POST /v1/memory/turn-finalized

Minimum useful fields:

  • session_id
  • turn_id
  • turns β€” list of {speaker, role, content} objects

Session lifecycle boundaries:

  • POST /v1/memory/session-start (explicit session-start snapshot boundary)
  • POST /v1/memory/session-flush (session-end flush boundary)
  • GET /v1/memory/continuity (pure-read continuity payload; no implicit writes)

SpringAI runtime path

Preferred single-call endpoint:

  • POST /v1/memory/execute

This is the best fit for service-oriented orchestration where a backend needs one deterministic memory call instead of multiple client-side routing steps.

See also:


Integrations

Canonical ingress port

from core_memory import process_turn_finalized

Adapter/helper ingress remains available for bridge code:

from core_memory.integrations.api import emit_turn_finalized

Available integration surfaces

  • OpenClaw bridge
  • PydanticAI native adapter
  • SpringAI / HTTP companion service
  • LangChain (CoreMemory, CoreMemoryRetriever)
  • Neo4j shadow graph adapter (projection-only visualization/inspection)

Good starting points


How It Works

Core Memory Architecture β€” Retrieval and Write sides

Core Memory separates retrieval from writes, connected through session-scoped bead storage. Each agent turn follows the same loop:

  1. Inject β€” build a bounded context packet
  2. Execute β€” run the agent turn
  3. Extract β€” capture structured events as beads
  4. Store β€” append to durable session/event surfaces
  5. Compact β€” preserve important causal memory, compress the rest
  6. Recall β€” retrieve causal chains when the agent needs them

Core Concepts

Beads

A bead is a structured memory event: decision, lesson, outcome, evidence, context, or another typed unit of recall.

Associations

Associations are explicit links between beads and remain queryable even as memory compacts.

Retrieval Pipeline

Canonical retrieval surfaces:

  • search (anchor retrieval)
  • trace (causal traversal)
  • execute (single orchestration entrypoint)

Semantic mode behavior:

  • CORE_MEMORY_CANONICAL_SEMANTIC_MODE=required (default) fails closed for query-based anchor lookup when semantic backend is unavailable.
  • CORE_MEMORY_CANONICAL_SEMANTIC_MODE=degraded_allowed allows explicit degraded lexical fallback with markers.

Semantic backend deployment guidance:

  • faiss-* local index is development/single-process oriented (single-writer).
  • qdrant and pgvector are the recommended distributed-safe production backends.
  • For multi-worker production deployments, avoid relying on local FAISS write paths.
  • backend selection is explicit via CORE_MEMORY_VECTOR_BACKEND (local-faiss|qdrant|pgvector|chromadb).

See docs/semantic_backend_modes.md for backend mode details.

Hydration is explicit post-selection source recovery (turn/tools/adjacent), not a general retrieval mode.

Deep recall exists as a separate capability and is not the same thing as canonical hydration.

Retrieval is deterministic from indexed state.


Repo Map

core_memory/
β”œβ”€β”€ persistence/
β”œβ”€β”€ schema/
β”œβ”€β”€ retrieval/
β”œβ”€β”€ graph/
β”œβ”€β”€ write_pipeline/
β”œβ”€β”€ runtime/
β”œβ”€β”€ association/
β”œβ”€β”€ integrations/
β”œβ”€β”€ policy/
└── cli.py

Other useful folders:

  • examples/ runnable examples
  • tests/ behavioral and regression coverage
  • docs/ architecture, integration guides, and contracts
  • plugins/ OpenClaw bridge assets
  • demo/ live demo app and assets

Contributing

git clone https://github.com/JohnnyFiv3r/Core-Memory.git
cd Core-Memory
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e ".[dev]"
core-memory --help
python3 -c "import core_memory; print('core_memory import ok')"
pytest

Useful docs:


Inspiration

Inspired in part by Steve Yegge’s writing on beads and memory systems: https://github.com/steveyegge/beads


Maintainers

Core Memory is maintained by:

For bugs and feature requests, please open an issue. For anything else related to the project, feel free to reach out to the maintainers directly.


Apache-2.0 License Β· Code of Conduct Β· Changelog

About

Drop-in causal memory for AI agents. Append-only event store with associations and bounded memory injection.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages