agentkit-tool-fs 0.2.2

Filesystem tools and session-scoped filesystem policies for agentkit.
Documentation

agentkit-tool-fs

Filesystem tools and session-scoped policies for agentkit.

This crate provides seven tools that let an agent interact with the local filesystem, plus a policy layer that can enforce rules like "read before write."

Tools

Tool name Description
fs.read_file Read a UTF-8 file, optionally a line range
fs.write_file Write UTF-8 text, creating parent dirs if needed
fs.replace_in_file Find-and-replace exact text in a file
fs.move Move or rename a file or directory
fs.delete Delete a file or directory
fs.list_directory List entries in a directory
fs.create_directory Create a directory (and parents)

Quick start

Get a ToolRegistry containing all filesystem tools with a single call:

use agentkit_tool_fs::registry;

let reg = registry();
assert_eq!(reg.specs().len(), 7);

Policy configuration

FileSystemToolResources tracks which paths each session has inspected. Combined with FileSystemToolPolicy, you can require that the agent reads a file before it writes, replaces, moves, or deletes it:

use agentkit_tool_fs::{registry, FileSystemToolPolicy, FileSystemToolResources};

let resources = FileSystemToolResources::new()
    .with_policy(
        FileSystemToolPolicy::new()
            .require_read_before_write(true),
    );

// Pass `resources` as the ToolResources in your ToolContext so the
// filesystem tools can enforce the policy at invocation time.
let _ = resources;

Using individual tools

Each tool struct implements Default and the Tool trait, so you can also register only the tools you need:

use agentkit_tool_fs::{ReadFileTool, WriteFileTool};
use agentkit_tools_core::{Tool, ToolRegistry};

let reg = ToolRegistry::new()
    .with(ReadFileTool::default())
    .with(WriteFileTool::default());

assert_eq!(reg.specs().len(), 2);