Skip to main content

axor-memory-sqlite

CI PyPI Python License: MIT

SQLite memory provider for axor-core.

Persistent cross-session memory for governed agents. Zero extra dependencies — uses Python's built-in sqlite3.


Installation

pip install axor-memory-sqlite

Requires axor-core >= 0.5.0, < 0.6.


Quick Start

import axor_claude
from axor_core import AgentDefinition, AgentDomain, FragmentValue, MemoryFragment
from axor_memory_sqlite import SQLiteMemoryProvider

provider = SQLiteMemoryProvider("~/.axor/memory.db")

session = axor_claude.make_session(
    api_key="sk-ant-...",
    agent_def=AgentDefinition(
        name="my-agent",
        domain=AgentDomain.CODING,
        personality="You are an expert Python engineer.",
        memory_namespaces=("my-agent",),   # loaded at every session start
    ),
    memory_provider=provider,
)

result = await session.run("refactor the auth module")

# save what you want to remember next time
await provider.save([
    MemoryFragment(
        namespace="my-agent",
        key="auth_module_status",
        content="Auth module refactored to use JWT. Entry point: auth/jwt.py.",
        value=FragmentValue.KNOWLEDGE,
    ),
])

FragmentValue — what gets remembered how

Every MemoryFragment has a value that controls how the compressor treats it when it appears in ContextView:

Value Compressor behavior Typical use
PINNED Never touched — survives all turns User preferences, system rules, agent personality
KNOWLEDGE Dedup + error collapse only — no truncation Project docs, domain context, API specs
WORKING Normal compression pipeline Task findings, recent tool results
EPHEMERAL Aggressive compression — evicted first Debug output, one-turn scratch

Eviction priority: EPHEMERAL → WORKING → KNOWLEDGE → PINNED (never evicted).


API

SQLiteMemoryProvider(db_path)

from axor_memory_sqlite import SQLiteMemoryProvider

provider = SQLiteMemoryProvider("~/.axor/memory.db")  # persistent
provider = SQLiteMemoryProvider(":memory:")            # in-memory, tests only
provider = SQLiteMemoryProvider("~/.axor/memory.db", suppress_errors=True)  # best effort

All methods are async. SQLite calls are serialized behind a process-local lock and run on the current thread to keep sqlite connections thread-affine.

By default, database errors are raised so callers can detect corruption or permission problems. Set suppress_errors=True only for best-effort memory.

save(fragments)

Upsert by (namespace, key) — existing fragments are overwritten:

await provider.save([
    MemoryFragment(
        namespace="my-agent",
        key="project_stack",
        content="FastAPI + async SQLAlchemy + PostgreSQL",
        value=FragmentValue.PINNED,
        tags=["stack", "tech"],
    ),
])

load(query)

from axor_core import MemoryQuery, FragmentValue

# load all from namespace, pinned first
fragments = await provider.load(MemoryQuery(
    namespaces=("my-agent",),
    max_results=20,
))

# filter by value
pinned = await provider.load(MemoryQuery(
    namespaces=("my-agent",),
    values=(FragmentValue.PINNED, FragmentValue.KNOWLEDGE),
    max_results=10,
))

Results are ordered by priority (PINNED first) then by accessed_at descending.

delete(namespace, keys)

n = await provider.delete("my-agent", ["stale_key_1", "stale_key_2"])
print(f"deleted {n} fragments")

evict(namespace, values, max_age_seconds)

Remove stale fragments by value and/or age:

# evict all ephemeral fragments
await provider.evict("my-agent", values=(FragmentValue.EPHEMERAL,))

# evict working fragments older than 24 hours
await provider.evict(
    "my-agent",
    values=(FragmentValue.WORKING,),
    max_age_seconds=86400,
)

namespaces()

ns = await provider.namespaces()
# ["my-agent", "shared", "project-x"]

close()

await provider.close()

Call on shutdown. The provider can be used as an async context manager in tests:

async with SQLiteMemoryProvider(":memory:") as provider:
    await provider.save([...])

Namespaces

Namespaces are logical groupings — they do not require explicit creation. A namespace exists as soon as you save a fragment with that name.

Recommended pattern:

Namespace Content
{agent-name} Agent-specific memory — not shared
shared Shared across all agents in a project
project:{name} Project-specific facts
user:{id} Per-user preferences
# agent reads from its own namespace + shared
agent = AgentDefinition(
    name="billing-agent",
    memory_namespaces=("billing-agent", "shared"),
)

Schema

CREATE TABLE memory_fragments (
    namespace    TEXT    NOT NULL,
    key          TEXT    NOT NULL,
    content      TEXT    NOT NULL,
    value        TEXT    NOT NULL DEFAULT 'working',
    token_count  INTEGER NOT NULL DEFAULT 0,
    tags         TEXT    NOT NULL DEFAULT '[]',   -- JSON array
    created_at   TEXT    NOT NULL,
    accessed_at  TEXT    NOT NULL,
    metadata     TEXT    NOT NULL DEFAULT '{}',   -- JSON object
    PRIMARY KEY (namespace, key)
);

The database file is a standard SQLite file — readable with any SQLite tool.


Testing

Use :memory: for tests — no file created, no cleanup needed:

import pytest
from axor_memory_sqlite import SQLiteMemoryProvider
from axor_core import MemoryFragment, FragmentValue, MemoryQuery

@pytest.mark.asyncio
async def test_memory():
    p = SQLiteMemoryProvider(":memory:")

    await p.save([
        MemoryFragment(namespace="test", key="k1",
                       content="hello", value=FragmentValue.WORKING),
    ])
    results = await p.load(MemoryQuery(namespaces=("test",), max_results=5))
    assert len(results) == 1
    assert results[0].content == "hello"

    await p.close()

Requirements

  • Python 3.11+
  • axor-core >= 0.5.0
  • No extra dependencies — uses stdlib sqlite3 + asyncio

Ecosystem

Package Role
axor-core Governance kernel — defines MemoryProvider protocol
axor-cli Governed terminal runtime — uses this package for /memory
axor-langchain LangChain middleware — AxorMiddleware(memory_provider=...)
axor-claude Claude / Claude Code adapter
axor-classifier-simple ML task signal derivation (optional)
axor-classifier-llm LLM verifier for gray-zone escalation (optional)
axor-telemetry Privacy-preserving governance feedback
axor-benchmarks Governance proof layer

License

MIT

Metadata

Release files for axor-memory-sqlite 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for axor-memory-sqlite 0.3.0
File Size Uploaded Provenance Actions
axor_memory_sqlite-0.3.0.tar.gz 10.1 kB With provenance Details for axor_memory_sqlite-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for axor-memory-sqlite 0.3.0
File Interpreter ABI Platform Actions
axor_memory_sqlite-0.3.0-py3-none-any.whl Python 3 none any Details for axor_memory_sqlite-0.3.0-py3-none-any.whl

Total release size: 18.5 kB

Release files / axor_memory_sqlite-0.3.0.tar.gz

Download URL axor_memory_sqlite-0.3.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
23127cdc26c5c88ecb15ed50414dc401723821c0d1f25397f740f2e30a283530
BLAKE2b-256 checksum
How to use checksums
5ad6d7dd6735be5abe23177b4f480c303632cde72d610a68706f1b453c743a28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 25, 2026.

Transparency log

Release files / axor_memory_sqlite-0.3.0-py3-none-any.whl

Download URL axor_memory_sqlite-0.3.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
684db2e50b5f196a8f28423ecfa11df31ea65d1e4bfa14b7effefb9b037c7db2
BLAKE2b-256 checksum
How to use checksums
2e2c186d133b5c9170039ad4e99157a20c8e36f9d49ff0aa4db296a52947248d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 25, 2026.

Transparency log

Security for axor-memory-sqlite 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for axor_memory_sqlite-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page