local_file_system_tools.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
local_file_system_tools.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Write and read files in a target directory with LocalFileSystemTools, including a write-only agent that disables read_file.
"""
Local File System Tools
========================
Demonstrates local file system tools for reading from and writing to files.
The agent can create files and read their contents using the local file system.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.local_file_system import LocalFileSystemTools
# ---------------------------------------------------------------------------
# Create Agents
# ---------------------------------------------------------------------------
# Example 1: Read and write files (default)
agent = Agent(
model=OpenAIResponses(id="gpt-5.5"),
tools=[LocalFileSystemTools(target_directory="tmp/local_file_system")],
markdown=True,
)
# Example 2: Write-only mode (disable read_file)
write_only_agent = Agent(
model=OpenAIResponses(id="gpt-5.5"),
tools=[
LocalFileSystemTools(
target_directory="tmp/local_file_system", enable_read_file=False
)
],
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# Write a file and then read it back
agent.print_response(
"Write a short poem about programming to a file named poem.txt, then read it back to me.",
stream=True,
)
# Write-only agent: generate code and save it to disk
# write_only_agent.print_response(
# "Write a Python function that calculates fibonacci numbers and save it to tmp/local_file_system/fib.py",
# stream=True,
# )
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
local_file_system_tools.py, then run:python local_file_system_tools.py
Was this page helpful?