| Crates.io | agentdb |
| lib.rs | agentdb |
| version | 0.2.0 |
| created_at | 2025-11-25 09:59:20.655881+00 |
| updated_at | 2025-11-26 12:28:11.111263+00 |
| description | Interface for agent persistence. |
| homepage | https://github.com/cryptopatrick/agentdb |
| repository | https://github.com/cryptopatrick/agentdb |
| max_upload_size | |
| id | 1949495 |
| size | 30,374 |
Author's bio: ππ Hi, I'm CryptoPatrick! I'm currently enrolled as an
Undergraduate student in Mathematics, at Chalmers & the University of Gothenburg, Sweden.
If you have any questions or need more info, then please join my Discord Channel: AiMath
What is AgentDB β’ Features β’ Architecture β’ How To Use β’ Documentation β’ License
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.
agentdb provides a complete abstraction layer for database operations with type safety and flexibility:
Value wrapperResult<T, AgentDbError>ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Application calls AgentDB::put() β
ββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
β
ββββββββββΌβββββββββ
β AgentDB Trait β
β Dispatches to β
β Implementationβ
ββββββββββ¬βββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β β β
ββββββΌββββββ ββββββββΌβββββββ ββββββΌβββββββ
β SQLite β β PostgreSQL β β MySQL β
β Backend β β Backend β β Backend β
ββββββ¬ββββββ ββββββββ¬βββββββ ββββββ¬βββββββ
β β β
βββββββββββββββββΌββββββββββββββββ
β
ββββββββββΌβββββββββ
β Actual Storage β
β (Database) β
βββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β AgentDB Trait β
β β’ Core database operations β
β β’ Required for all implementations β
ββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
β β
ββββββΌβββββββββββββββ ββββββββββββββΌβββββββββββ
β Capabilities β β Transaction β
β β’ Runtime flags β β β’ commit() β
β β’ Feature detect β β β’ rollback() β
βββββββββββββββββββββ βββββββββββββββββββββββββ
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
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(())
}
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
}
See the agentsql and agentfs crates for complete examples of using AgentDB in practice.
Run the test suite:
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
Comprehensive documentation is available at docs.rs/agentdb, including:
Keybase Verification: https://keybase.io/cryptopatrick/sigs/8epNh5h2FtIX1UNNmf8YQ-k33M8J-Md4LnAN
Leave a β if you think this project is cool.
This project is licensed under MIT. See LICENSE for details.