What You Can Do
Use this toolkit to give your agent the ability to:- Perform Atomic Operations: Safely modify multiple files at once with automatic rollback on failure.
- Manage Files & Directories: Create, read, update, delete, and list files and directories.
- Search the Filesystem: Find files by name (
glob) or content (grep). - Run in Secure Environments: Choose between local, in-memory, and sandboxed backends to match your security needs.
Core Concepts
FilesystemToolkit: This is the main entry point. It bundles a collection of file-related tools (read_file,write_file, etc.) that are ready to be used by an agent.FileOperator(Backend): This is the engine that performs the actual file operations. You can choose from three backends:LocalFileOperator: For high-performance access to the local filesystem.InMemoryFileOperator: For fast, isolated testing in a virtual filesystem.SandboxFileOperator: For secure execution in an isolated container, ideal for handling untrusted code.
Quick Start
Key Feature: Atomic Transactions
For complex tasks like code generation, you often need to modify multiple files. If one step fails, you risk leaving the project in a broken state. Transactions solve this by ensuring that all file operations succeed or none of them do. If any operation insidewithTransaction fails, all changes are automatically rolled back.
For more advanced transaction control, see the API Reference.
Core Operations
Here are the most common operations you can perform with the toolkit.Writing and Creating Files
Thewrite_file tool creates a new file or overwrites an existing one. It automatically creates parent directories if they don’t exist.
Reading Files
Theread_file tool reads the entire content of a specified file.
Editing Files
Theedit_file tool performs a search-and-replace on a file’s content. It’s useful for making targeted changes.
Listing Directory Contents
Thels tool lists the files and subdirectories within a given path.
Finding Files by Pattern (Glob)
Theglob tool finds all files and directories matching a specific pattern, which is useful for discovering files before processing them.
Searching File Content (Grep)
Thegrep tool searches for a specific text pattern (including regex) within files in a given directory. It’s perfect for finding where a function is called or locating specific comments.
For detailed input/output schemas of all tools, see the API Reference.
Workflow Example: Agent Integration
Integrate theFilesystemToolkit directly into your agent to give it powerful file manipulation capabilities.