Filesystem Tool
~3 min read
Concept & How It Works
Why Does It Exist?
Many agent tasks involve manipulating files: editing code, reading configs, generating reports. Filesystem tools provide structured file access.
Real-World Analogy
A filesystem tool is giving the agent a desk with labeled folders — they can open, edit, and save documents, but not leave the office.
Visual Workflows
What is Filesystem Tool?
Example
Scenario
A coding agent reads src/auth.ts, applies a fix for the bug, writes the updated file, and runs tests via a terminal tool.
Solution
In Tool Calling & Function Calling, apply Filesystem Tool to this scenario: A coding agent reads src/auth. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Practice Task
Do this before moving to the next module — reading alone is not enough.
Open the Code Walkthrough below and run it locally. Change one parameter related to Filesystem Tool (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.
Code Walkthrough
Highlighted lines show where Filesystem Tool happens in the code.
1import os # import dependencies2
3WORKSPACE = "/workspace"4
5def read_file(path): # define a reusable function6 full = os.path.join(WORKSPACE, os.path.normpath(path).lstrip("/"))7 if not full.startswith(WORKSPACE):8 raise PermissionError("Path outside workspace")9 with open(full) as f:10 return f.read() # return the result11
12def write_file(path, content): # define a reusable function13 full = os.path.join(WORKSPACE, os.path.normpath(path).lstrip("/"))14 if not full.startswith(WORKSPACE):15 raise PermissionError("Path outside workspace")16 os.makedirs(os.path.dirname(full), exist_ok=True)17 with open(full, "w") as f:18 f.write(content)Commands to Remember
Commands to Remember
client.chat.completions.create(..., tools=[...]) # pass tool schemas to APIjson.loads(response.choices[0].message.tool_calls[0].function.arguments) # parse tool argspip install pydantic # validate tool inputs with schemas
Common Mistakes
- Treating Filesystem Tool as a black box without evaluation
- Ignoring cost and latency in production
- Skipping error handling for filesystem tool
Cheat Sheet
Quick recap — the most important points from this module.
Cheat Sheet
quick ref- •Filesystem Tool
- •Sandbox
- •Workspace Root
- •Grep