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.3.tar.gz (118.3 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.3-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.3-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.3-cp312-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.12+Windows x86-64

agent_gear-0.1.3-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.3-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.3-cp312-abi3-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

agent_gear-0.1.3-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.3.tar.gz.

File metadata

  • Download URL: agent_gear-0.1.3.tar.gz
  • Upload date:
  • Size: 118.3 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.3.tar.gz
Algorithm Hash digest
SHA256 84199e1ef0139a511c02487fd57bb2f0be269f93cebdc7200744c964cac6b3eb
MD5 a1dd122c1db7d12699bf932b0624f798
BLAKE2b-256 15fc5850c14ac9023e0bc445b2993a9f1e943a3c5ba26e2a4903595818cfad05

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3.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.3-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.3-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a73f4152246a4d503f3ac2356be157698112c6bb1d702d9af92ed419a19a38e2
MD5 af6cf7b4677b5b86ac704cc003662f81
BLAKE2b-256 bcf18c8c457924d6edbc57966a92daf1dcb061d8a75c6c29e307d4a7834806f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3-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.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1ae01acd324459dabd3f00a6ef3c39936e81f6e13e708a9128dc9f2afe0b2cd3
MD5 b0eb96d01f81c0121a81d81f846548e0
BLAKE2b-256 88246a10e5dbb73a6c27d6525cddf1709ac6561e4e96ae8c7b371af18c24bb50

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3-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.3-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: agent_gear-0.1.3-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.3-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2f53ea342a1b7074231f3df379f713d7426d745fe5ef80d1abab6dee15a3a02b
MD5 d0023e3256dacc1aabcf66d434e0793c
BLAKE2b-256 f77b9065dd581ca7a5c00edec5065e0b3185d7fb45c307027cbcfbfbce686ddb

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3-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.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c29a5bedae41a3bd3c58ab8722c844fac567a973b983cf0a6ba1411c68656a9
MD5 012973c3cbd82425f04ee7174f5ff00c
BLAKE2b-256 e5caef93f3da3c7cff6c1e1c4a0f7f2e9fe7fc40bfa0dfe3fe9074e7fd689a55

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3-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.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 29f5b44c7549d92d493ed158329d71f53d220b104707989f4721c15efc6c4abf
MD5 a5cf7231b2770d4aa321d783f754d143
BLAKE2b-256 eeba25669113f72f5a781abf4b2b76779169d4b00d800a3415a0318aca83136d

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3-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.3-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.3-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e889b884a50803b1a3246cb2427bad1ee9dbbe17b8b14ce8d57cc964b400d1e4
MD5 fb2052f5e94a902aa959720f8e756594
BLAKE2b-256 d58f8e33d86e4cd7d61063186ed7457b88b326dd5dd21b84fc8fb89a8ecd149c

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3-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.3-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agent_gear-0.1.3-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b1d3bb3c546cd1852c9d694cf6cfbc1d49f373b51e36bd97e3a953964c7b3553
MD5 14366c281572d61ee027eb84a60ddf9c
BLAKE2b-256 7862fa94a205d6ddaf946a86d3d16b6bc39859808b8b739adc170e09abba6c08

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_gear-0.1.3-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