Agents/Agent memory
agentdb
The Archivist
One trait for agent storage, whatever database sits behind it.
Downloads per day
Last 90 days · 15 total · peak 14
Dossier
What agentdb does.
Gives AI agents a single storage trait so the same agent code runs on SQLite, PostgreSQL or MySQL.
From the crate: “Interface for agent persistence.”
- Codename
- The Archivist
- Role
- Storage abstraction
- Character
- Speaks only in interfaces and never says which database it trusts. Calm, neutral, and deeply allergic to vendor lock-in.
- Domain
- Agent memory
- Enlisted
- 8 October 2026
- Last release
- v0.2.0, 8 October 2026
- Keywords
agents,ai,database
Use cases
Put it to work.
- Write agent code once and choose SQLite in development, PostgreSQL in production.
- Put a stable interface between agent logic and storage so backends can change later.
- Implement the trait for a new backend and every agent using
agentdbgets it.
Getting started
Call it in.
Add it to a Rust project, then follow the example. The full API is on docs.rs.
Install
cargo add agentdb
Example
┌────────────────────────────────────────────────────┐
│ AgentFS High-Level APIs │
│ (FileSystem, KvStore, ToolRecorder) │
└───────────────────────┬────────────────────────────┘
│
┌───────────────────────▼────────────────────────────┐
│ AgentDB Trait │
│ • put(key, value) → Result<()> │
│ • get(key) → Result<Option<Value>> │
│ • delete(key) → Result<()> │
│ • scan(prefix) → Result<ScanResult> │
│ • query(sql, params) → Result<QueryResult> │
│ • capabilities() → &dyn Capabilities │
└───────────────────────┬────────────────────────────┘
│
┌───────────────┼───────────────┐
│ │ │
┌───────▼──────┐ ┌──────▼──────┐ ┌─────▼──────┐
│ AgentSQL │ │ AgentKV │ │ AgentGraph │
│ (SQLx) │ │ (Future) │ │ (Future) │
└───────┬──────┘ └─────────────┘ └────────────┘
│
┌───────┼────────┬────────────┐
│ │ │ │
▼ ▼ ▼ ▼
SQLite Postgres MySQL MariaDBMore
┌──────────────────────────────────────────────┐
│ Application calls AgentDB::put() │
└────────────────────┬─────────────────────────┘
│
┌────────▼────────┐
│ AgentDB Trait │
│ Dispatches to │
│ Implementation│
└────────┬────────┘
│
┌───────────────┼───────────────┐
│ │ │
┌────▼─────┐ ┌──────▼──────┐ ┌────▼──────┐
│ SQLite │ │ PostgreSQL │ │ MySQL │
│ Backend │ │ Backend │ │ Backend │
└────┬─────┘ └──────┬──────┘ └────┬──────┘
│ │ │
└───────────────┼───────────────┘
│
┌────────▼────────┐
│ Actual Storage │
│ (Database) │
└─────────────────┘More
┌────────────────────────────────────────────────┐
│ AgentDB Trait │
│ • Core database operations │
│ • Required for all implementations │
└────────────────────┬───────────────────────────┘
│
┌───────────────┴───────────────┐
│ │
┌────▼──────────────┐ ┌────────────▼──────────┐
│ Capabilities │ │ Transaction │
│ • Runtime flags │ │ • commit() │
│ • Feature detect │ │ • rollback() │
└───────────────────┘ └───────────────────────┘More
use agentdb::{AgentDB, Capabilities};
async fn example(db: impl AgentDB) -> Result<(), Box<dyn std::error::Error>> {
// Check capabilities
if db.capabilities().supports_transactions() {
println!("✓ Transactions supported");
}
// Key-value operations
db.put("user:123", b"Alice".to_vec().into()).await?;
if let Some(value) = db.get("user:123").await? {
println!("User: {}", String::from_utf8_lossy(value.as_bytes()));
}
// Scan with prefix
let result = db.scan("user:").await?;
println!("Found {} users", result.keys.len());
// SQL query (if supported)
let query_result = db.query(
"SELECT * FROM users WHERE active = 1",
vec![]
).await?;
for row in query_result.rows {
// Process rows...
}
Ok(())
}Build with a prompt
Add the Rust crate `agentdb` (version 0.2.0) to this project with `cargo add agentdb`. I want to use it for this: Gives AI agents a single storage trait so the same agent code runs on SQLite, PostgreSQL or MySQL. Before writing code, read its README at https://crates.io/crates/agentdb and the API docs at https://docs.rs/agentdb. Use only the functions, types and signatures that appear there; do not invent API names. Write a minimal working example and one test that runs it.
Paste this into Claude Code or another coding agent.
Specs
- Version
- 0.2.0
- License
- MIT
- Edition
- Rust 2024
- Size
- 230 lines of code, 0 of comments
- Package
- 9.5 KB compressed
- Dependencies
- async-trait
- Used by
- 2 crates on crates.io
- Docs
- docs.rs, built
- Repository
- cryptopatrick/agentdb · 0★ · 0 forks · 0 open issues · pushed 26 Nov 2025
Release history
| Version | Date | Downloads |
|---|---|---|
| 0.2.0 | 8 Oct 2026 | 15 |
Documentation
The manual.
The crate's README as published on crates.io. The full API reference is on docs.rs.
Read the README
AGENTDB
Database Abstraction Layer for AI Agents
What is AgentDB • Features • Architecture • How To Use • Documentation • License
🛎 Important Notices
- This is a trait-based abstraction layer, not a complete database
- Requires concrete implementations (see agentsql)
- Designed for AI agent persistence needs
📌 Table of Contents
Table of Contents
🤔 What is AgentDB
agentdb is a unified database abstraction layer that provides a common interface for AI agent storage operations across multiple backend families (SQL, Key-Value, Graph databases). It serves as the middleware between high-level agent operations and concrete database implementations.
Built to enable database flexibility without code changes, AgentDB provides a single trait that works seamlessly across SQLite, PostgreSQL, MySQL, and future backends.
Use Cases
- Multi-Backend Support: Write agent code once, deploy on any supported backend
- Database Flexibility: Switch between SQLite, PostgreSQL, MySQL without code changes
- Type Safety: Rust's type system ensures correctness across database operations
- Future-Proof: Easy to add new database backends without changing agent code
- Testing: Mock implementations for unit testing agent logic
- Custom Backends: Implement your own backend for specialized storage needs
📷 Features
agentdb provides a complete abstraction layer for database operations with type safety and flexibility:
🔧 Core Traits
AgentDB Trait
- CRUD Operations: Put, get, delete, and scan key-value pairs
- Query Interface: Execute SQL queries with result sets
- Transaction Support: Optional transactional operations
- Capability Discovery: Runtime feature detection
- Async-First: All operations use async/await
Capabilities Trait
- Transaction Support: Check if transactions are available
- Index Support: Determine if indexes are supported
- Backend Family: Identify backend type (SQL, KV, Graph)
- Feature Flags: Query specific backend capabilities
Transaction Trait
- ACID Guarantees: Atomic commit and rollback operations
- Nested Transactions: Support for savepoints (backend-dependent)
- Error Handling: Comprehensive error types
💾 Value System
- Type-Safe Values: Strong typing with
Valuewrapper - Byte-Level Storage: Efficient binary data handling
- Zero-Copy Operations: Minimize allocations where possible
- Conversion Traits: Easy conversion to/from Rust types
🔒 Error Handling
- Unified Error Types: Single error type across all backends
- Context Preservation: Detailed error messages with context
- Result Type: Standard Rust
Result<T, AgentDbError> - Backend Errors: Wrapped backend-specific errors
📐 Architecture
- 🏛 Overall Architecture
┌────────────────────────────────────────────────────┐
│ AgentFS High-Level APIs │
│ (FileSystem, KvStore, ToolRecorder) │
└───────────────────────┬────────────────────────────┘
│
┌───────────────────────▼────────────────────────────┐
│ AgentDB Trait │
│ • put(key, value) → Result<()> │
│ • get(key) → Result<Option<Value>> │
│ • delete(key) → Result<()> │
│ • scan(prefix) → Result<ScanResult> │
│ • query(sql, params) → Result<QueryResult> │
│ • capabilities() → &dyn Capabilities │
└───────────────────────┬────────────────────────────┘
│
┌───────────────┼───────────────┐
│ │ │
┌───────▼──────┐ ┌──────▼──────┐ ┌─────▼──────┐
│ AgentSQL │ │ AgentKV │ │ AgentGraph │
│ (SQLx) │ │ (Future) │ │ (Future) │
└───────┬──────┘ └─────────────┘ └────────────┘
│
┌───────┼────────┬────────────┐
│ │ │ │
▼ ▼ ▼ ▼
SQLite Postgres MySQL MariaDB
- 🔄 Data Flow
┌──────────────────────────────────────────────┐
│ Application calls AgentDB::put() │
└────────────────────┬─────────────────────────┘
│
┌────────▼────────┐
│ AgentDB Trait │
│ Dispatches to │
│ Implementation│
└────────┬────────┘
│
┌───────────────┼───────────────┐
│ │ │
┌────▼─────┐ ┌──────▼──────┐ ┌────▼──────┐
│ SQLite │ │ PostgreSQL │ │ MySQL │
│ Backend │ │ Backend │ │ Backend │
└────┬─────┘ └──────┬──────┘ └────┬──────┘
│ │ │
└───────────────┼───────────────┘
│
┌────────▼────────┐
│ Actual Storage │
│ (Database) │
└─────────────────┘
- 💾 Trait System
┌────────────────────────────────────────────────┐
│ AgentDB Trait │
│ • Core database operations │
│ • Required for all implementations │
└────────────────────┬───────────────────────────┘
│
┌───────────────┴───────────────┐
│ │
┌────▼──────────────┐ ┌────────────▼──────────┐
│ Capabilities │ │ Transaction │
│ • Runtime flags │ │ • commit() │
│ • Feature detect │ │ • rollback() │
└───────────────────┘ └───────────────────────┘
🚙 How to Use
Installation
Add agentdb to your Cargo.toml:
[dependencies]
agentdb = "0.1"
# Also add a concrete implementation:
agentsql = "0.1"
Or install with cargo:
cargo add agentdb
cargo add agentsql
Basic Example
use agentdb::{AgentDB, Capabilities};
async fn example(db: impl AgentDB) -> Result<(), Box<dyn std::error::Error>> {
// Check capabilities
if db.capabilities().supports_transactions() {
println!("✓ Transactions supported");
}
// Key-value operations
db.put("user:123", b"Alice".to_vec().into()).await?;
if let Some(value) = db.get("user:123").await? {
println!("User: {}", String::from_utf8_lossy(value.as_bytes()));
}
// Scan with prefix
let result = db.scan("user:").await?;
println!("Found {} users", result.keys.len());
// SQL query (if supported)
let query_result = db.query(
"SELECT * FROM users WHERE active = 1",
vec![]
).await?;
for row in query_result.rows {
// Process rows...
}
Ok(())
}
Advanced: Implementing a Custom Backend
use agentdb::{AgentDB, Capabilities, QueryResult, Row, ScanResult, Value};
use async_trait::async_trait;
struct MyCustomBackend {
// Your backend state...
}
#[async_trait]
impl AgentDB for MyCustomBackend {
fn capabilities(&self) -> &dyn Capabilities {
// Return your capabilities
unimplemented!()
}
async fn put(&self, key: &str, value: Value) -> agentdb::Result<()> {
// Implement put operation
unimplemented!()
}
async fn get(&self, key: &str) -> agentdb::Result<Option<Value>> {
// Implement get operation
unimplemented!()
}
async fn delete(&self, key: &str) -> agentdb::Result<()> {
// Implement delete operation
unimplemented!()
}
async fn scan(&self, prefix: &str) -> agentdb::Result<ScanResult> {
// Implement scan operation
unimplemented!()
}
async fn query(&self, sql: &str, params: Vec<Value>) -> agentdb::Result<QueryResult> {
// Implement query operation
unimplemented!()
}
// ... implement other required methods
}
🧪 Examples
See the agentsql and agentfs crates for complete examples of using AgentDB in practice.
🧪 Testing
Run the test suite:
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
📚 Documentation
Comprehensive documentation is available at docs.rs/agentdb, including:
- Complete API reference for all traits and types
- Guide to implementing custom backends
- Error handling best practices
- Performance optimization tips
🖊 Author
Keybase Verification: https://keybase.io/cryptopatrick/sigs/8epNh5h2FtIX1UNNmf8YQ-k33M8J-Md4LnAN
🐣 Support
Leave a ⭐ if you think this project is cool.
🗄 License
This project is licensed under MIT. See LICENSE for details.
Resources
Same unit