CryptoPatrick / code

Code · Agents

AgentFS

A filesystem, key-value store and tool-call audit log for AI agents, on SQLite, PostgreSQL or MySQL.

What it is

Agents need somewhere to put things: files they produce, settings they keep, and a record of the tools they called. AgentFS gives an agent a POSIX-like workspace with three parts:

  • fs: files and directories (mkdir, write_file, read_file, readdir, …),
  • kv: a key-value store for state and configuration,
  • tools: an audit log of tool calls with their inputs, outputs, outcome and statistics.

Everything is stored in a database. AgentFS is built on agentdb, a database-independent interface, and agentsql, which implements it for SQLite, PostgreSQL and MySQL.

Using it

use agentfs::AgentFS;
use agentsql::SqlBackend;

let backend = SqlBackend::sqlite("agent.db").await?;
let agent_fs = AgentFS::new(Box::new(backend), "my-agent", "/agent").await?;

agent_fs.fs.mkdir("/output").await?;
agent_fs.fs.write_file("/output/report.txt", b"Hello, World!").await?;

agent_fs.kv.set("config:theme", b"dark").await?;

let id = agent_fs.tools.start("web_search", Some(serde_json::json!({"q": "rust mcp"}))).await?;
agent_fs.tools.success(id, Some(serde_json::json!({"hits": 12}))).await?;
let stats = agent_fs.tools.statistics("web_search").await?;

Ideas for using it

  • An audit trail for AI tools: which model called which tool with what input, and what came back. Useful when AI output has to be reviewed later.
  • Shared workspace for several agents: one writes a draft, another reviews it, both through the same filesystem.
  • Swap storage without code changes: SQLite on a laptop, PostgreSQL in production.

Status

Prototype.