AgentFS Python SDK - A filesystem and key-value store for AI agents
Project description
AgentFS Python SDK
A filesystem and key-value store for AI agents, powered by SQLite and pyturso.
Installation
pip install agentfs-sdk
Quick Start
import asyncio
from agentfs_sdk import AgentFS, AgentFSOptions
async def main():
# Open an agent filesystem
agent = await AgentFS.open(AgentFSOptions(id='my-agent'))
# Use key-value store
await agent.kv.set('config', {'debug': True, 'version': '1.0'})
config = await agent.kv.get('config')
print(f"Config: {config}")
# Use filesystem
await agent.fs.write_file('/data/notes.txt', 'Hello, AgentFS!')
content = await agent.fs.read_file('/data/notes.txt')
print(f"Content: {content}")
# Track tool calls
call_id = await agent.tools.start('search', {'query': 'Python'})
await agent.tools.success(call_id, {'results': ['result1', 'result2']})
# Get statistics
stats = await agent.tools.get_stats()
for stat in stats:
print(f"{stat.name}: {stat.total_calls} calls, {stat.avg_duration_ms:.2f}ms avg")
# Close the database
await agent.close()
if __name__ == '__main__':
asyncio.run(main())
Features
Key-Value Store
Simple key-value storage with JSON serialization:
# Set a value
await agent.kv.set('user:123', {'name': 'Alice', 'age': 30})
# Get a value
user = await agent.kv.get('user:123')
# List by prefix
users = await agent.kv.list('user:')
# Delete a value
await agent.kv.delete('user:123')
Filesystem
POSIX-like filesystem operations:
# Write a file (creates parent directories automatically)
await agent.fs.write_file('/data/config.json', '{"key": "value"}')
# Read a file
content = await agent.fs.read_file('/data/config.json')
# Read as bytes
data = await agent.fs.read_file('/data/image.png', encoding=None)
# List directory
entries = await agent.fs.readdir('/data')
# Get file stats
stats = await agent.fs.stat('/data/config.json')
print(f"Size: {stats.size} bytes")
print(f"Modified: {stats.mtime}")
print(f"Is file: {stats.is_file()}")
# Delete a file
await agent.fs.delete_file('/data/config.json')
Tool Calls Tracking
Track and analyze tool/function calls:
# Start a tool call
call_id = await agent.tools.start('search', {'query': 'Python'})
# Mark as successful
await agent.tools.success(call_id, {'results': [...]})
# Or mark as failed
await agent.tools.error(call_id, 'Connection timeout')
# Record a completed call
await agent.tools.record(
'search',
started_at=1234567890,
completed_at=1234567892,
parameters={'query': 'Python'},
result={'results': [...]}
)
# Query tool calls
calls = await agent.tools.get_by_name('search', limit=10)
recent = await agent.tools.get_recent(since=1234567890)
# Get statistics
stats = await agent.tools.get_stats()
for stat in stats:
print(f"{stat.name}: {stat.successful}/{stat.total_calls} successful")
Configuration
Using Agent ID
Creates a database at .agentfs/{id}.db:
agent = await AgentFS.open(AgentFSOptions(id='my-agent'))
Using Custom Path
Specify a custom database path:
agent = await AgentFS.open(AgentFSOptions(path='./data/mydb.db'))
Using Both
You can specify both for clarity:
agent = await AgentFS.open(AgentFSOptions(id='my-agent', path='./data/mydb.db'))
Context Manager Support
Use AgentFS with async context managers:
async with await AgentFS.open(AgentFSOptions(id='my-agent')) as agent:
await agent.kv.set('key', 'value')
# Database is automatically closed when exiting the context
Development
Setup
# Install dependencies
uv sync --group dev
# Run tests
uv run pytest
# Format code
uv run ruff format agentfs_sdk tests
# Check code
uv run ruff check agentfs_sdk tests
License
MIT License - see LICENSE file for details.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentfs_sdk-0.4.0rc10.tar.gz.
File metadata
- Download URL: agentfs_sdk-0.4.0rc10.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74ac7ab09a241509fbea10e2834a96058d3136155c9660e7e09c5cc16db3c2d2
|
|
| MD5 |
cb104bb5a09cbe1a39622bf49518db11
|
|
| BLAKE2b-256 |
cbc5fa6deb3bea432891e88719f921515ffc5aaa0f78a99c1dc0d10b767609d2
|
File details
Details for the file agentfs_sdk-0.4.0rc10-py3-none-any.whl.
File metadata
- Download URL: agentfs_sdk-0.4.0rc10-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22867a3b694152ea9bb440239ada9e32a8d5941d80b1c6369e47f9431cdc6647
|
|
| MD5 |
f5d220c40704764b1d41a5ecf43b8b19
|
|
| BLAKE2b-256 |
7224f569e2afdac788c5384452e2bd40a02c445d0bec19b25468bc167db01637
|