Filesystem Tools¶
File operations tools.
Available Functions¶
| Function | Description |
|---|---|
read_file |
Read file contents |
write_file |
Write/overwrite file |
append_file |
Append to file |
list_directory |
List directory contents |
file_info |
Get file metadata |
delete_file |
Delete file |
move_file |
Move/rename file |
copy_file |
Copy file |
Quick Example¶
from mamba_agents.tools import (
read_file,
write_file,
list_directory,
file_info,
)
# Read file
content = read_file("config.json")
# Write file
write_file("output.txt", "Hello!")
# List directory
entries = list_directory("/project", recursive=True)
# Get file info
info = file_info("README.md")
print(f"Size: {info.size}")
Security¶
from mamba_agents.tools.filesystem import FilesystemSecurity
security = FilesystemSecurity(
sandbox_mode=True,
base_directory="/safe/path",
allowed_extensions=[".txt", ".json"],
)
# Use with tools
content = read_file("data.txt", security=security)
API Reference¶
read_file
¶
Read contents of a file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the file to read.
TYPE:
|
encoding
|
Character encoding (default: utf-8).
TYPE:
|
security
|
Optional security context for path validation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The file contents as a string. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the file does not exist. |
PermissionError
|
If access is denied or path is outside sandbox. |
Source code in src/mamba_agents/tools/filesystem/read.py
write_file
¶
write_file(
path: str,
content: str,
encoding: str = "utf-8",
create_parents: bool = False,
security: FilesystemSecurity | None = None,
) -> str
Write or overwrite a file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the file to write.
TYPE:
|
content
|
Content to write to the file.
TYPE:
|
encoding
|
Character encoding (default: utf-8).
TYPE:
|
create_parents
|
Create parent directories if they don't exist.
TYPE:
|
security
|
Optional security context for path validation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The path of the written file. |
| RAISES | DESCRIPTION |
|---|---|
PermissionError
|
If access is denied or path is outside sandbox. |
FileNotFoundError
|
If parent directory doesn't exist and create_parents is False. |
Source code in src/mamba_agents/tools/filesystem/write.py
list_directory
¶
list_directory(
path: str,
recursive: bool = False,
max_depth: int = 2,
security: FilesystemSecurity | None = None,
) -> list[dict[str, Any]]
List contents of a directory.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the directory to list.
TYPE:
|
recursive
|
Whether to list recursively.
TYPE:
|
max_depth
|
Maximum depth for recursive listing.
TYPE:
|
security
|
Optional security context for path validation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict[str, Any]]
|
List of dictionaries with file/directory information. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the directory does not exist. |
NotADirectoryError
|
If the path is not a directory. |
PermissionError
|
If access is denied or path is outside sandbox. |
Source code in src/mamba_agents/tools/filesystem/directory.py
file_info
¶
Get file or directory metadata.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the file or directory.
TYPE:
|
security
|
Optional security context for path validation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary with file metadata including: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the file does not exist. |
PermissionError
|
If access is denied or path is outside sandbox. |