Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Filesystem Tools

A Deep Agent ships with six built-in filesystem tools, plus a conditional seventh. These tools are automatically registered when you call create_deep_agent (if enable_filesystem is true, which is the default) and are dispatched through whichever backend you configure.

Creating the Tools

If you need the tool set outside of a DeepAgent (for example, in a custom graph), use the factory function:

use synaptic::deep::tools::create_filesystem_tools;
use synaptic::deep::backend::FilesystemBackend;
use std::sync::Arc;

let backend = Arc::new(FilesystemBackend::new("/workspace"));
let tools = create_filesystem_tools(backend);
// tools: Vec<Arc<dyn Tool>>
// 6 tools always: ls, read_file, write_file, edit_file, glob, grep
// + execute (only if backend.supports_execution() returns true)

The execute tool is only included when the backend reports that it supports execution. For FilesystemBackend this is always the case. For StateBackend and StoreBackend, execution is not supported and the tool is omitted.

Tool Reference

ToolDescriptionAlways present
lsList directory contentsYes
read_fileRead file contents with optional line-based paginationYes
write_fileCreate or overwrite a fileYes
edit_fileFind and replace text in an existing fileYes
globFind files matching a glob patternYes
grepSearch file contents by regex patternYes
executeRun a shell command and capture outputOnly if backend supports execution

ls

Lists files and directories at the given path.

ParameterTypeRequiredDescription
pathstringyesDirectory to list

Returns a JSON array of entries, each with name (string), is_dir (boolean), and size (integer or null) fields.

read_file

Reads the contents of a single file with line-based pagination.

ParameterTypeRequiredDescription
pathstringyesFile path to read
offsetintegernoStarting line number, 0-based (default 0)
limitintegernoMaximum number of lines to return (default 2000)

Returns the file contents as a string. When offset and limit are provided, returns only the requested line range.

write_file

Creates a new file or overwrites an existing one.

ParameterTypeRequiredDescription
pathstringyesDestination file path
contentstringyesFull file contents to write

Returns a confirmation string (e.g. "wrote path/to/file").

edit_file

Applies a targeted string replacement within an existing file.

ParameterTypeRequiredDescription
pathstringyesFile to edit
old_stringstringyesExact text to find
new_stringstringyesReplacement text
replace_allbooleannoReplace all occurrences (default false)

When replace_all is false (the default), only the first occurrence is replaced. The tool returns an error if old_string is not found in the file.

glob

Finds files matching a glob pattern.

ParameterTypeRequiredDescription
patternstringyesGlob pattern (e.g. "**/*.rs", "src/*.toml")
pathstringnoBase directory to search from (default ".")

Returns matching file paths as a newline-separated string.

grep

Searches file contents for lines matching a regular expression.

ParameterTypeRequiredDescription
patternstringyesRegex pattern to search for
pathstringnoDirectory or file to search in (defaults to workspace root)
globstringnoGlob pattern to filter which files are searched (e.g. "*.rs")
output_modestringnoOutput format: "files_with_matches" (default), "content", or "count"

Output modes control the format of results:

  • files_with_matches -- Returns one matching file path per line.
  • content -- Returns matching lines in file:line_number:line format.
  • count -- Returns match counts in file:count format.

execute

Runs a shell command in the backend's working directory. This tool is only registered when the backend supports execution (i.e. FilesystemBackend).

ParameterTypeRequiredDescription
commandstringyesThe shell command to execute
timeoutintegernoTimeout in seconds

Returns a JSON object with stdout, stderr, and exit_code fields. Commands are executed via sh -c in the backend's root directory.