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_read_file(path="big.log", offset=201, limit=50)
- FilesystemTool_write_file(path="output.txt", content="hello")
- FilesystemTool_edit_file(path="app.py", old_string="a - b", new_string="a + b")
- 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_read_file(path=\"big.log\", offset=201, limit=50)\n - FilesystemTool_write_file(path=\"output.txt\", content=\"hello\")\n - FilesystemTool_edit_file(path=\"app.py\", old_string=\"a - b\", new_string=\"a + b\")\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
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
read_file
read_file(
path: str, offset: int = 1, limit: int | None = None
) -> str
Read a file. Path is relative to /workspace. Without offset and limit the whole file is returned; for a long file, pass offset (first line, counting from 1 as search does) and limit (number of lines) to read only that part.
Source code in src/ant_ai/tools/builtins/filesystem_tool.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
edit_file
edit_file(
path: str,
old_string: str,
new_string: str,
replace_all: bool = False,
) -> str
Replace old_string with new_string in a file, leaving the rest unchanged. Path is relative to /workspace. old_string must appear exactly once, so include enough surrounding text to make it unique; set replace_all to replace every occurrence.
Source code in src/ant_ai/tools/builtins/filesystem_tool.py
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 | |
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
130 131 132 133 134 135 136 137 138 139 140 141 | |
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
143 144 145 146 147 148 149 150 151 152 153 154 155 | |
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
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |