A governed memory layer for Python agents. AgentDB stores agent memories with provenance, applies optional write policies, ranks retrieved records, tracks conflicts, and provides adapters for feeding governed context into agent runtimes.
AgentDB is a local Python library backed by SQLite. It complements an agent runtime; it is not a hosted service, a vector database, or a replacement for the model provider.
Scope: AgentDB is a focused memory and context-selection library: it stores, ranks, and injects provenance-aware memory for agents.
The current storage implementation is embedded SQLite. There is no Postgres/cloud backend or HTTP MCP transport. The gateway dispatcher is in-memory; the audit log is stored separately in SQLite.
python3 -m venv .venv source .venv/bin/activate python -m pip install -e '.[dev,mcp]' Optional extras (the distribution name is agentdatabase):
python -m pip install 'agentdatabase[local-embed]' # local sentence-transformer embeddings python -m pip install 'agentdatabase[mcp]' # stdio MCP server python -m pip install 'agentdatabase[providers]' # Anthropic provider client python -m pip install 'agentdatabase[notifications]' # Slack notifications Email notifications use the Python standard library. The notifications extra is needed for Slack.
Pass a memory_dir or path when constructing the client:
from agentdb import AgentDB # Creates config/, database/, and other workspace directories as needed. db = AgentDB(memory_dir="./agentdb-memory") record = db.write( key="memory/working/response_style", value="Prefer concise bullet points.", origin="agent_inferred", agent_id="assistant", ) result = db.retrieve("How should I format the response?", agent_id="assistant") print([record.value for record in result.records]) The default workspace configuration is written to config/memory.yaml. Set AGENTDB_MEMORY_DIR or AGENTDB_HOME to choose a workspace through the environment.
Provide permissions_path to enable write/delete checks:
db = AgentDB( memory_dir="./agentdb-memory", permissions_path="./permissions.yaml", ) Example policy:
default_policy: deny human_zone_prefixes: - "memory/org/" # All bots registered by default: any agent_id not listed under `agents:` # gets this scope. Remove it for strict deny-by-default. default_agent_scope: can_write: - "memory/working/" - "memory/episodic/" cannot_write: - "memory/org/" can_read: - "memory/working/" - "memory/episodic/" agents: # Disable a specific bot (deny all its memory writes/reads): retired_bot: disabled: true # An explicit entry overrides the default scope for one agent: assistant: can_write: - "memory/working/" cannot_write: - "memory/org/" default_agent_scope makes all bot identities registered by default — an unlisted agent_id is granted that scope, so a new bot works without a manual per-bot entry. Disable a bot with an explicit agents: : { disabled: true }. Omit default_agent_scope for strict deny-by-default (every identity must be listed).
memory.yaml uses a named profile with optional overrides. Built-in profiles are budget_optimized, full_storage, and research:
profile: name: budget_optimized agents: assistant: retrieval: retrieve_limit: 10 # Embeddings are off unless enabled or supplied through the constructor. embeddings: enabled: true # model: sentence-transformers/all-MiniLM-L6-v2 Embeddings can also be enabled with AgentDB(local_embed=True) or a custom embed_fn(text) -> list[float]. They enable semantic ranking and embedding-based conflict checks. Local embeddings require the local-embed extra; embedding support is disabled by default.
Retrieval returns RetrievalResult with records, conflicts, authority override instructions, a token estimate, a truncation flag, and an optional trace (pass trace=True) exposing candidate sources, exclusions, and per-candidate ranking evidence. Candidates are the union of lexical and (optional) semantic matches, ranked by the existing multi-signal ranker and packed within a rendered-token budget that skips oversized records rather than stopping. retrieve_by_entities() uses the same eligibility filters, ranking, and budget policy. Semantic matching requires embeddings; without them, retrieval uses the lexical path and the other non-semantic signals. Set embeddings.semantic_candidates: false to force lexical-only retrieval even when embeddings are configured.
Consolidation produces a derived derived_canonical record with full source lineage; the original source records are never overwritten (only archived from default selection), and a canonical is invalidated when its sources change. Only equivalent or compatible-complementary values are merged — contradictory values (including negations and mutually-exclusive values) and scope-incompatible facts stay separate. validate_canonicals() reports invalid canonicals non-destructively. Concurrent/repeated consolidation is idempotent (a stable source fingerprint prevents duplicate active canonicals).
By default consolidation is dedup-only (cluster_copy): the canonical value is a verbatim copy of the highest-confidence source in a cluster. To synthesize a new summary instead (cluster_synthesis), pass an llm_fn to consolidate() / end_session(run_consolidation=True, ...):
db.consolidate(agent_id="my-agent", llm_fn=my_llm_fn) Signature: llm_fn(prompt: str) -> str — receives one synthesis prompt, returns the synthesized text. It is a plain callable / API argument only (not settable in memory.yaml).
Optional: when llm_fn is None, consolidation still runs and produces cluster_copy (verbatim copy of the top source), not a synthesized summary. Model-call errors are caught and fall back to cluster_copy.
Helper (recommended): instead of hand-rolling the chat-completions call, use build_llm_fn, which constructs an OpenAI-compatible client from a model id + connection params and returns a ready llm_fn:
from agentdb.providers.consolidation import build_llm_fn llm_fn = build_llm_fn( model="meta-llama/Meta-Llama-3.1-8B-Instruct", base_url="https://api.deepinfra.com/v1/openai", api_key="...", # placeholder ok for local servers # max_tokens=..., temperature=..., timeout=... (all optional) ) db.consolidate(agent_id="my-agent", llm_fn=llm_fn) build_llm_fn needs the openai package: install it with pip install 'agentdatabase[llm]'.
Structured know-how: when llm_fn is supplied, the package asks the model for a JSON object — {"know_how", "workspace_id", "repository_id", "task_type", "environment", "confidence"} — so the canonical is reusable, workspace-scoped know-how (not a session narrative) and carries metadata used for scoped retrieval. A plain-text answer is still accepted (treated as know_how). Metadata the model omits is inherited from the top source. After consolidation, retrieval returns the distilled canonical in place of its archived raw sources (raw is re-surfaced only when it holds a query detail the canonical dropped).
Compaction summaries and checkpoints default to agent_inferred provenance. A bare origin="human_approved" is asserted (not verified) authority. Verified human authority requires a host-configured authority_verifier and an affirmative decision through approve_authority(); it is bound to a versioned content/scope fingerprint (edits invalidate it) and can be removed via revoke_authority() with an audit trail. AgentDB does not defend against a malicious host process with full code/DB access — the enforceable boundary is between ordinary agent APIs and the host-configured trusted approval pathway.
AgentDBMiddleware (from agentdb.adapters import AgentDBMiddleware) provides prepare_turn / finalize_turn and run_turn, plus async variants. The async preparation path can inject workspace information and recent work context according to RunnerCapabilities; the synchronous path prepares memory context.
AgentDBClaudeRuntime supports synchronous model clients and an async Claude SDK client factory. AgentDBClaudeMiddleware remains available as a backward-compatible import. The adapter exposes a PreToolUse hook map through get_sdk_hooks(); the integrating application is responsible for registering that hook with its SDK/runtime.
AgentDBHermesProvider implements Hermes's MemoryProvider interface. It supplies retrieval, turn persistence, and lifecycle hooks. Governance applies to AgentDB records; a post-write Hermes hook cannot veto a write already made to Hermes-native storage.
No dedicated deepagents, LangGraph, CrewAI, OpenAI Agents, Google ADK, or AutoGen adapter is included. Use AgentDBBackend where the framework supports a pluggable key/value backend, or integrate AgentDBMiddleware at the runtime's own control points.
See docs/integrations/README.md for integration guides.
python -m pytest -q See docs/context/testing-strategy.md for focused test commands and docs/context/architecture-principles.md for the design constraints. The repository uses a src/ layout and package imports such as from agentdb import AgentDB.
Both files in this release have provenance metadata.
GNU Affero General Public License v3 (AGPL-3.0)
dev mcp local-embed notifications providers llm
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Both files in this release have been uploaded with provenance metadata.
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.
Nov 21, 2026 2 release files Full provenance
Nov 20, 2026 2 release files Full provenance
Nov 19, 2026 2 release files Full provenance
Oct 23, 2026 2 release files Full provenance
Oct 10, 2026 2 release files Full provenance
Oct 4, 2026 2 release files Full provenance




