Skip to main content

High-performance filesystem operations for AI agents

Project description

Agent-Gear

High-performance filesystem operations for AI agents, powered by Rust.

Features

  • Stateful Indexing: In-memory file tree with LRU-cached glob patterns
  • Batch I/O: Parallel file read/write with smart threshold optimization
  • High-Performance Search: Grep with parallel search and mmap for large files
  • Atomic Writes: Safe file modifications with temp-fsync-rename pattern
  • Fast Writes: Optional non-atomic mode for 30x faster writes
  • Large File Support: Efficient line-based reading for logs and large files
  • Async Support: Full async/await API with AsyncFileSystem
  • File Watching: Real-time filesystem monitoring with event debouncing

Installation

pip install agent-gear

For development:

git clone https://github.com/anthropics/agent-gear
cd agent-gear
pip install maturin
maturin develop --release

Quick Start

from agent_gear import FileSystem

with FileSystem("/path/to/project") as fs:
    fs.wait_ready()

    # List and glob
    all_files = fs.list("**/*")
    py_files = fs.glob("**/*.py")

    # Search with grep
    results = fs.grep("TODO", "**/*.py")
    for r in results:
        print(f"{r.file}:{r.line_number}: {r.content}")

    # Read files
    content = fs.read_file("main.py")
    batch = fs.read_batch(py_files[:10])

    # Large file: read specific lines
    lines = fs.read_lines("app.log", start_line=1000, count=100)

    # Write files
    fs.write_file("output.txt", content)      # Atomic (safe)
    fs.write_file_fast("temp.txt", content)   # Fast (30x faster)

    # Edit in place
    fs.edit_replace("config.py", "DEBUG = False", "DEBUG = True")

Async Usage

from agent_gear import AsyncFileSystem
import asyncio

async def main():
    async with AsyncFileSystem("/path/to/project") as fs:
        await fs.wait_ready()

        # All operations are async
        files = await fs.list("**/*.py")
        results = await fs.grep("TODO", "**/*.py")

        # Concurrent operations
        results = await asyncio.gather(
            fs.list("**/*.py"),
            fs.grep("def main"),
            fs.read_file("README.md"),
        )

asyncio.run(main())

API Reference

FileSystem

class FileSystem:
    def __init__(self, root: str, auto_watch: bool = True) -> None: ...

    # Listing
    def list(self, pattern: str = "**/*", only_files: bool = True) -> list[str]: ...
    def glob(self, pattern: str) -> list[str]: ...

    # Reading
    def read_file(self, path: str, encoding: str = "utf-8") -> str: ...
    def read_batch(self, paths: list[str]) -> dict[str, str]: ...
    def read_lines(self, path: str, start_line: int = 0, count: int | None = None) -> list[str]: ...
    def read_file_range(self, path: str, offset: int, limit: int) -> str: ...

    # Writing
    def write_file(self, path: str, content: str) -> bool: ...           # Atomic
    def write_file_fast(self, path: str, content: str) -> bool: ...      # Fast
    def edit_replace(self, path: str, old_text: str, new_text: str, strict: bool = True) -> bool: ...

    # Searching
    def grep(self, query: str, glob_pattern: str = "**/*",
             case_sensitive: bool = False, max_results: int = 1000) -> list[SearchResult]: ...

    # Metadata & Control
    def get_metadata(self, path: str) -> FileMetadata: ...
    def is_ready(self) -> bool: ...
    def is_watching(self) -> bool: ...
    def refresh(self) -> None: ...
    def close(self) -> None: ...

AsyncFileSystem

Same API as FileSystem, but all I/O methods are async.

Data Classes

class SearchResult:
    file: str           # Relative file path
    line_number: int    # Line number (1-indexed)
    content: str        # Matching line content

class FileMetadata:
    size: int       # File size in bytes
    mtime: float    # Modification time (Unix timestamp)
    is_dir: bool    # Is directory
    is_binary: bool # Is binary file

Performance

Benchmark on 3000 files (polyglot project, 20 repeated queries):

Operation Agent-Gear Stdlib Speedup
List all 1.75ms 3.5ms 2.0x
*Glob .py 1.84ms 5.1ms 2.8x
*Glob .ts 2.01ms 5.0ms 2.5x
Grep TODO 4.2ms 7.8ms 1.9x
Write (fast) 0.14ms 4.5ms (atomic) 33x
Async (3 ops) 3.9ms 8.0ms (seq) 2.0x

Overall: 1.9x faster | Index: ~100ms (breaks even in 1 query round)

When to Use Agent-Gear

  • Repeated queries: Index pays off after just 1-2 query rounds
  • Large codebases: 1000+ files show 1.5-3x speedup
  • Glob-heavy workflows: Cached patterns, 2-3x faster
  • Grep searches: Parallel + mmap, 2x faster
  • Async I/O: Concurrent operations with 2x speedup

Run benchmarks:

python benchmarks/benchmark.py                     # Single mode, 500 files
python benchmarks/benchmark.py --mode repeated     # Repeated queries
python benchmarks/benchmark.py --mode all --files 3000  # Full test

Architecture

agent_gear/
├── _rust_core.so      # Rust extension (PyO3)
└── __init__.py        # Python wrapper + AsyncFileSystem

src/
├── lib.rs             # PyO3 module entry
└── fs/
    ├── mod.rs         # FileSystem pyclass
    ├── index.rs       # DashMap-based file index + LRU glob cache
    ├── searcher.rs    # Parallel grep with mmap
    ├── io.rs          # Batch read/write with threshold optimization
    ├── atomic.rs      # Atomic write (temp-fsync-rename)
    └── watcher.rs     # File watching with debouncing

Development

Prerequisites

  • Python 3.12+
  • Rust 1.75+
  • maturin

Build & Test

# Development build
maturin develop --release

# Run tests
pytest tests/python -v
cargo test

# Run benchmarks
cargo bench
python benchmarks/benchmark.py

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_gear-0.1.1.tar.gz (97.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

agent_gear-0.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

agent_gear-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

agent_gear-0.1.1-cp312-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.12+Windows x86-64

agent_gear-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ x86-64

agent_gear-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

agent_gear-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

agent_gear-0.1.1-cp312-abi3-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

agent_gear-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file agent_gear-0.1.1.tar.gz.

File metadata

  • Download URL: agent_gear-0.1.1.tar.gz
  • Upload date:
  • Size: 97.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agent_gear-0.1.1.tar.gz
Algorithm Hash digest
SHA256 77eba8538fc31fdfeae891f15805eee8fe2fee4dd4c30aba73617d6138ca8045
MD5 2010c6d0f1fbe5f0399d3c872606115d
BLAKE2b-256 50190789187a4357f80b01d4e590b3c1a71b08db0e6f1b2eb6f42de93da7e304

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1.tar.gz:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_gear-0.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 698ccba2674772367f77ea8b4294043c28e0f835315f5baeef06b8df2c0d249e
MD5 c25fc2cc88b5cc46c84f4f848b4cfc1c
BLAKE2b-256 d2369a17a531ae1e42f47a156c82362e23aee25fb03271a83416b42f690ce2d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_gear-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3c2ac355df673e04b5a9a8771e16322cfa746f5e1bee9513c551106f02f40b14
MD5 12999e94394d23b3725bfc5f77077658
BLAKE2b-256 9df00dbfadf1723e9ea45f9d7382bfcb36ea07d73ae20dbdeb3e19cbe2c22a7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_gear-0.1.1-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: agent_gear-0.1.1-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agent_gear-0.1.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 45950703c6eec7e64d2416ec91f64bac72c7a6c354b8800a302fa4cee21c32f5
MD5 f145a72eb36ec0e1c3c76b161ab738c0
BLAKE2b-256 701f3fe9c37318cf60716a1f93bc846e8add94f50e9ab3a25f0524da42b921c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1-cp312-abi3-win_amd64.whl:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_gear-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a7c149637a5e17e1466cba3d6cd490f59c6e6cfe50a1457fa402b895117efd6a
MD5 ea599e0b5cb1f217449ad6ba24ff727b
BLAKE2b-256 2a5b000212f417cc6f7bb1de02d5dc00846ac294b76491fffa35f0dcda827c09

See more details on using hashes here.

File details

Details for the file agent_gear-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e26cdb808dd5a1c39ff6362d671886e4d6a5b9c648296123b6964847bc0a469
MD5 48324c367fc37ae8acd681ad6834d83e
BLAKE2b-256 883e90ce705172e137200c2cc5c0a6988575ebe501799bac5da5b1c01ae60a0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_gear-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 156ec80c064e1f2cdc7a94749e3385f1e6bb36fbb95c8056043bcb419121c0f7
MD5 8edb9b3835937facc8b68bf1c885b40c
BLAKE2b-256 7e2f75ea7246fd9f1da81d41b6a4bf03bb0b0fb0041dc8599b9c0d4abed725ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_gear-0.1.1-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7094bc03ddec5b83830fb7fdcb2a4ec25df035d63ad11d2da53fefc0504ad625
MD5 9bdf6a0b31abde2029d610de8df05cf0
BLAKE2b-256 a648a06067374915c704de6043c708e6b3e766b93866dcc0ca878035ce137397

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_gear-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3d04f4f5b0205d27c384188f346ceb195372668489078d5bd0f9541988ea194f
MD5 81d845a37c9f522f3b685d0d9f948826
BLAKE2b-256 ded4391fea4890c82c2ba623d0c40c78d1ad06b719c9879ec3837e3db0da45d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.1-cp312-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on TokenRollAI/rs-agent-gear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page