| Crates.io | agentfs |
| lib.rs | agentfs |
| version | 0.2.0 |
| created_at | 2025-11-25 10:02:22.05066+00 |
| updated_at | 2025-11-26 12:48:11.878389+00 |
| description | Agent Persistence |
| homepage | https://github.com/cryptopatrick/agentfs |
| repository | https://github.com/cryptopatrick/agentfs |
| max_upload_size | |
| id | 1949504 |
| size | 528,652 |
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 AgentFS โข Features โข Architecture โข How To Use โข Documentation โข License
agentfs provides a high-level filesystem abstraction for AI agents, offering POSIX-like file operations, key-value storage, and tool call auditing. It enables agents to persist state, store generated files, and maintain audit trails across sessions.
Built on top of the agentdb abstraction layer and agentsql SQL backends, AgentFS provides a complete storage solution for AI agents with zero vendor lock-in.
agentfs provides three high-level APIs for AI agent storage with production-grade features:
POSIX-like Interface:
Advanced Features:
Simple API:
Use Cases:
Workflow-Based API:
Single-Shot API:
Analytics:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Layer โ
โ โข Agent frameworks (Rig, LangChain, custom) โ
โ โข Multi-agent systems โ
โ โข CLI tools and services โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentFS APIs โ
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ โ
โ โ FileSystem โ KvStore โ ToolRecorder โ โ
โ โ โ โ โ โ
โ โ โข mkdir โ โข set โ โข start โ โ
โ โ โข write_file โ โข get โ โข success โ โ
โ โ โข read_file โ โข delete โ โข error โ โ
โ โ โข readdir โ โข scan โ โข record โ โ
โ โ โข remove โ โข exists โ โข statistics โ โ
โ โ โข stat โ โ โข recent โ โ
โ โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentDB Trait Interface โ
โ โข Database-agnostic operations โ
โ โข put, get, delete, scan, query โ
โ โข Transaction support โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentSQL (SQLx) โ
โ โข Connection pooling โ
โ โข Migration system โ
โ โข Type-safe SQL โ
โ โข Multi-backend support โ
โโโโโฌโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ โโโโโโโผโโโโโโโ
โ SQLite โ โ PostgreSQL โ โ MySQL โ
โ Local โ โ Production โ โ Cloud โ
โโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FileSystem API Calls โ
โ mkdir("/docs") write_file("/docs/a.txt") โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Path Resolution โ
โ โข Normalize paths (remove .., .) โ
โ โข Validate against mount point (/agent) โ
โ โข Split into parent + name components โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Inode Operations โ
โ โข Lookup parent directory inode โ
โ โข Create new inode for file/dir โ
โ โข Update metadata (size, mtime, permissions) โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Dentry Operations โ
โ โข Insert (parent_ino, name, ino) entry โ
โ โข UNIQUE constraint ensures no duplicates โ
โ โข Enables path-to-inode lookup โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Data Storage (for files) โ
โ โข Store file content in fs_data table โ
โ โข Chunk large files by offset โ
โ โข Link to inode via foreign key โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SQLite / PostgreSQL / MySQL โ
โ โข fs_inode: metadata (size, times, mode) โ
โ โข fs_dentry: name resolution โ
โ โข fs_data: file contents โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Agent Calls Tool (e.g., web_search) โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ tools.start("web_search", params) โ
โ โข Generate UUID for tool call โ
โ โข Store: name, params, started_at โ
โ โข Status: "pending" โ
โ โข Returns: call_id โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
โ โ
โโโโโโโโผโโโโโโโโโโโ โโโโโโโโโโโผโโโโโโโโโโโ
โ Tool Succeeds โ โ Tool Fails โ
โโโโโโโโฌโโโโโโโโโโโ โโโโโโโโโโโฌโโโโโโโโโโโ
โ โ
โโโโโโโโผโโโโโโโโโโโโโโโโโโโ โโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โ tools.success(id, res) โ โ tools.error(id, err) โ
โ โข Update completed_at โ โ โข Update completed_at โ
โ โข Store result JSON โ โ โข Store error message โ
โ โข Status: "success" โ โ โข Status: "error" โ
โ โข Calculate duration_ms โ โ โข Calculate duration_ms โ
โโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Persisted in tool_calls table โ
โ โข Query by name, status, time range โ
โ โข Generate statistics (success rate, avg duration) โ
โ โข Audit trail for debugging and compliance โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentFS Instance โ
โ โข agent_name: "my-agent" โ
โ โข mount_point: "/agent" โ
โ โข db: Box<dyn AgentDB> โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ FileSystem Component โ โ
โ โ Uses: fs_inode, fs_dentry, fs_data tables โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ KvStore Component โ โ
โ โ Uses: kv_store table โ โ
โ โ Prefix: "kv:{agent_name}:" โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ToolRecorder Component โ โ
โ โ Uses: tool_calls table โ โ
โ โ All calls tagged with agent_name โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Database Backend โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ fs_inode: ino, mode, size, times โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ fs_dentry: parent_ino, name, ino โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ fs_data: ino, offset, size, data (BLOB) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ kv_store: key, value, timestamps โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ tool_calls: id, name, params, result, ... โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Add to your Cargo.toml:
[dependencies]
agentfs = "0.1"
agentsql = { version = "0.1", features = ["sqlite"] }
# For PostgreSQL:
# agentsql = { version = "0.1", features = ["postgres"] }
# For MySQL:
# agentsql = { version = "0.1", features = ["mysql"] }
Or install with cargo:
cargo add agentfs
cargo add agentsql --features sqlite
use agentfs::{AgentFS, FileSystem, KvStore, ToolRecorder};
use agentsql::SqlBackend;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create AgentFS with SQLite backend
let backend = SqlBackend::sqlite("agent.db").await?;
let agent_fs = AgentFS::new(Box::new(backend), "my-agent", "/agent").await?;
// Filesystem operations
agent_fs.fs.mkdir("/output").await?;
agent_fs.fs.write_file("/output/report.txt", b"Hello, World!").await?;
let content = agent_fs.fs.read_file("/output/report.txt").await?.unwrap();
println!("File content: {}", String::from_utf8_lossy(&content));
// List directory
let entries = agent_fs.fs.readdir("/output").await?;
for entry in entries {
println!("{}: {} bytes", entry.name, entry.size);
}
// Key-value store
agent_fs.kv.set("config:theme", b"dark").await?;
let theme = agent_fs.kv.get("config:theme").await?.unwrap();
println!("Theme: {}", String::from_utf8_lossy(&theme));
// Tool call auditing
let id = agent_fs.tools.start("web_search", Some(serde_json::json!({
"query": "Rust async programming"
}))).await?;
// Simulate search...
agent_fs.tools.success(id, Some(serde_json::json!({
"results": 10,
"duration_ms": 123
}))).await?;
// Get statistics
let stats = agent_fs.tools.statistics("web_search").await?;
println!("Success rate: {:.1}%", stats.success_rate * 100.0);
Ok(())
}
use agentfs::AgentFS;
use agentsql::SqlBackend;
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 backend = SqlBackend::postgres(database_url).await?;
let agent_fs = AgentFS::new(Box::new(backend), "prod-agent", "/agent").await?;
// Same API as SQLite!
agent_fs.fs.write_file("/logs/app.log", b"System started").await?;
// Scan KV store
agent_fs.kv.set("session:user123", b"active").await?;
let sessions = agent_fs.kv.scan("session:").await?;
println!("Found {} active sessions", sessions.len());
Ok(())
}
use agentfs::AgentFS;
use agentsql::SqlBackend;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to MySQL (e.g., AWS Aurora)
let backend = SqlBackend::mysql(
"mysql://user:pass@aurora-cluster.region.rds.amazonaws.com/agentfs"
).await?;
let agent_fs = AgentFS::new(Box::new(backend), "cloud-agent", "/agent").await?;
// Multi-agent coordination
agent_fs.fs.mkdir("/shared").await?;
agent_fs.fs.write_file("/shared/status.json", b"{\"status\":\"ready\"}").await?;
// List recent tool calls across all agents
let recent = agent_fs.tools.recent(10).await?;
for call in recent {
println!("{}: {} ({})", call.name, call.status, call.duration_ms);
}
Ok(())
}
The repository includes three comprehensive examples demonstrating different backends and use cases:
See examples/basic.rs for a complete example demonstrating:
Run with:
cargo run --example basic
See examples/postgres.rs for:
Run with:
export DATABASE_URL="postgres://user:password@localhost/agentfs_demo"
cargo run --example postgres --features postgres
See examples/mysql.rs for:
Run with:
export DATABASE_URL="mysql://user:password@localhost/agentfs_demo"
cargo run --example mysql --features mysql
Run the comprehensive test suite:
# Run all tests (SQLite)
cargo test
# Run tests with output
cargo test -- --nocapture
# Run with all backends
cargo test --all-features
# Test specific backend
cargo test --features postgres
cargo test --features mysql
The test suite includes:
Comprehensive documentation is available at docs.rs/agentfs, including:
| Feature | AgentFS | Other Solutions |
|---|---|---|
| Backend Choice | SQLite, PostgreSQL, MySQL | Vendor-specific |
| Open Source | โ MIT Licensed | โ ๏ธ Varies |
| Self-Hosted | โ Yes | โ Cloud-only |
| Tool Auditing | โ Built-in | โ Not included |
| Zero Cost | โ Yes | โ Usage-based pricing |
| Local Development | โ SQLite | โ ๏ธ Requires cloud account |
| POSIX-like API | โ Yes | โ ๏ธ Limited |
| Multi-Agent | โ Native support | โ ๏ธ Requires workarounds |
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.