| Crates.io | agentsql |
| lib.rs | agentsql |
| version | 0.2.0 |
| created_at | 2025-11-25 09:59:12.404512+00 |
| updated_at | 2025-11-26 12:44:42.599957+00 |
| description | Interface for agent sql persistence |
| homepage | https://github.com/cryptopatrick/agentsql |
| repository | https://github.com/cryptopatrick/agentsql |
| max_upload_size | |
| id | 1949494 |
| size | 114,544 |
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 AgentSQL โข Features โข Architecture โข How To Use โข Documentation โข License
agentsql is a production-ready SQL backend implementation for AI agent persistence. It provides a unified interface for SQLite, PostgreSQL, and MySQL databases through the AgentDB trait, enabling agents to store filesystems, key-value data, and tool call audit logs with a single API.
Built with SQLx for type-safe SQL, AgentSQL handles schema migrations automatically and provides seamless switching between database backends without code changes.
agentsql provides complete SQL backend support for agent persistence with production-grade features:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentFS High-Level APIs โ
โ (FileSystem, KvStore, ToolRecorder) โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentDB Trait Interface โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentSQL (SQLx) โ
โ โข Connection pooling โ
โ โข Query builder โ
โ โข Migration system โ
โ โข Type conversions โ
โโโโโฌโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโ
โ โ โ
โโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ โโโโโโโผโโโโโโโ
โ SQLite โ โ PostgreSQL โ โ MySQL โ
โ Local โ โ Production โ โ Cloud โ
โโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SQLite / PostgreSQL / MySQL โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ fs_inode (File Metadata) โ โ
โ โ - ino (PK, AUTO_INCREMENT) โ โ
โ โ - mode (permissions) โ โ
โ โ - uid, gid โ โ
โ โ - size, atime, mtime, ctime โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ fs_dentry (Directory Entries) โ โ
โ โ - id (PK) โ โ
โ โ - name โ โ
โ โ - parent_ino (FK โ fs_inode) โ โ
โ โ - ino (FK โ fs_inode) โ โ
โ โ UNIQUE(parent_ino, name) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ fs_data (File Content) โ โ
โ โ - id (PK) โ โ
โ โ - ino (FK โ fs_inode) โ โ
โ โ - offset โ โ
โ โ - size โ โ
โ โ - data (BLOB/BYTEA) โ โ
โ โ INDEX(ino, offset) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ kv_store (Key-Value) โ โ
โ โ - key (PK) โ โ
โ โ - value (TEXT) โ โ
โ โ - created_at, updated_at โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ tool_calls (Audit Trail) โ โ
โ โ - id (PK) โ โ
โ โ - name โ โ
โ โ - parameters (JSON) โ โ
โ โ - result (JSON) โ โ
โ โ - error โ โ
โ โ - status (pending/success/error) โ โ
โ โ - started_at, completed_at โ โ
โ โ - duration_ms โ โ
โ โ INDEX(name), INDEX(started_at) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SqlBackend::new(config) โ
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโโโ
โ Detect Backend โ
โ SQLite/PG/MySQL โ
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโโโ
โ Load Migration โ
โ SQL for backend โ
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโโโ
โ Execute Schema โ
โ Multi-statement โ
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโโโ
โ Initialize Root โ
โ inode (ino=1) โ
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโโโ
โ Ready for Use! โ
โโโโโโโโโโโโโโโโโโโโโ
Add to your Cargo.toml:
[dependencies]
agentdb = "0.1"
agentsql = "0.1"
# Enable the backend(s) you need:
agentsql = { version = "0.1", features = ["sqlite"] }
# agentsql = { version = "0.1", features = ["postgres"] }
# agentsql = { version = "0.1", features = ["mysql"] }
# agentsql = { version = "0.1", features = ["sqlite", "postgres", "mysql"] }
Or install with cargo:
cargo add agentsql --features sqlite
use agentsql::SqlBackend;
use agentdb::AgentDB;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create SQLite database (file-based)
let db = SqlBackend::sqlite("agent.db").await?;
// Or use in-memory for testing
let db = SqlBackend::sqlite(":memory:").await?;
// Key-value operations
db.put("config:theme", b"dark".to_vec().into()).await?;
let theme = db.get("config:theme").await?.unwrap();
println!("Theme: {}", String::from_utf8_lossy(theme.as_bytes()));
// SQL queries
let result = db.query(
"SELECT * FROM fs_inode WHERE ino = 1",
vec![]
).await?;
println!("Root inode: {:?}", result.rows.first());
Ok(())
}
use agentsql::SqlBackend;
use agentdb::AgentDB;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to PostgreSQL
let database_url = env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://user:pass@localhost/agentfs".to_string());
let db = SqlBackend::postgres(database_url).await?;
// Same API as SQLite!
db.put("agent:status", b"running".to_vec().into()).await?;
// Execute queries
let result = db.query(
"SELECT COUNT(*) as count FROM tool_calls WHERE status = 'success'",
vec![]
).await?;
Ok(())
}
use agentsql::SqlBackend;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to MySQL (e.g., AWS Aurora)
let db = SqlBackend::mysql(
"mysql://user:pass@aurora-cluster.region.rds.amazonaws.com/agentfs"
).await?;
// Scan with prefix
let sessions = db.scan("session:").await?;
println!("Found {} active sessions", sessions.keys.len());
Ok(())
}
See the agentfs crate for complete examples demonstrating:
Run the test suite:
# Run all tests (SQLite)
cargo test
# Test with PostgreSQL
cargo test --features postgres
# Test with MySQL
cargo test --features mysql
# Run with output
cargo test -- --nocapture
Comprehensive documentation is available at docs.rs/agentsql, including:
SqlBackendKeybase 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.