Skip to main content
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.
local_file_system_tools.py
"""
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,
    # )

Run the Example

1

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2

Install dependencies

uv pip install -U agno openai
3

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4

Run the example

Save the code above as local_file_system_tools.py, then run:
python local_file_system_tools.py
Full source: cookbook/91_tools/local_file_system_tools.py