ant_ai.tools.builtins.filesystem_tool
FilesystemTool
pydantic-model
Bases: Tool
Tools for reading and writing files within the agent workspace.
Example
from ant_ai.agent import Agent
from ant_ai.tools.builtins.filesystem_tool import FilesystemTool
fs = FilesystemTool(workspace_root="/workspace")
agent = Agent(tools=[fs], ...)
The agent can now call:
- FilesystemTool_read_file(path="notes.txt")
- FilesystemTool_write_file(path="output.txt", content="hello")
- FilesystemTool_list_dir(path="src/")
- FilesystemTool_search(pattern="TODO", path="src/")
Notes
All paths are resolved relative to workspace_root and sandboxed within it.
Failures -- a missing file, an invalid regex, an attempt to escape the
workspace (e.g. "../etc/passwd", "/absolute/path") -- raise ToolError,
which ToolStep turns into a recoverable ERROR: ... message for the
agent and marks as an error.
Show JSON schema:
{
"description": "Tools for reading and writing files within the agent workspace.\n\nExample:\n ```python\n from ant_ai.agent import Agent\n from ant_ai.tools.builtins.filesystem_tool import FilesystemTool\n\n fs = FilesystemTool(workspace_root=\"/workspace\")\n agent = Agent(tools=[fs], ...)\n ```\n\n The agent can now call:\n\n - FilesystemTool_read_file(path=\"notes.txt\")\n - FilesystemTool_write_file(path=\"output.txt\", content=\"hello\")\n - FilesystemTool_list_dir(path=\"src/\")\n - FilesystemTool_search(pattern=\"TODO\", path=\"src/\")\n\nNotes:\n All paths are resolved relative to `workspace_root` and sandboxed within it.\n Failures -- a missing file, an invalid regex, an attempt to escape the\n workspace (e.g. \"../etc/passwd\", \"/absolute/path\") -- raise `ToolError`,\n which `ToolStep` turns into a recoverable `ERROR: ...` message for the\n agent and marks as an error.",
"properties": {
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Tool name.",
"title": "Name"
},
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Tool description. Is used by the LLM to decide whether to call or not the specific tool.",
"title": "Description"
},
"parameters": {
"anyOf": [
{
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"default": null,
"description": "The parameters needed by the tool. This is a self-constructed field.",
"title": "Parameters"
},
"workspace_root": {
"default": ".",
"format": "path",
"title": "Workspace Root",
"type": "string"
}
},
"title": "FilesystemTool",
"type": "object"
}
Fields:
-
name(str | None) -
description(str | None) -
parameters(dict[str, Any] | None) -
__namespace_methods__(list[str]) -
workspace_root(Path) -
_ignore_spec(PathSpec | None)
Validators:
-
_set_defaults
Source code in src/ant_ai/tools/builtins/filesystem_tool.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
read_file
read_file(path: str) -> str
Read the full contents of a file. Path is relative to /workspace.
Source code in src/ant_ai/tools/builtins/filesystem_tool.py
63 64 65 66 67 68 69 70 71 72 | |
write_file
write_file(path: str, content: str) -> str
Write content to a file, overwriting if it exists. Creates parent directories as needed. Path is relative to /workspace.
Source code in src/ant_ai/tools/builtins/filesystem_tool.py
74 75 76 77 78 79 80 81 82 83 84 | |
list_dir
list_dir(path: str = '.', depth: int = 4) -> list[str]
List files and directories recursively at the given path, up to depth levels deep. Path is relative to /workspace. Defaults to workspace root.
Source code in src/ant_ai/tools/builtins/filesystem_tool.py
86 87 88 89 90 91 92 93 94 95 96 97 98 | |
search
search(
pattern: str, path: str = ".", depth: int = 4
) -> str
Search for a regex pattern recursively within path, up to depth levels deep. Path is relative to /workspace. Returns matching lines in the format 'file:lineno: content'.
Source code in src/ant_ai/tools/builtins/filesystem_tool.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |