Local File System

LocalFileSystemTools enables agents to read and write files on the local file system with automatic directory management.

Prerequisites

Create and activate a virtual environment, then install:

uv pip install agno openai

The Agent model uses an OpenAI key, separately from any toolkit provider credentials.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Example

The following agent can write content to local files:

from agno.agent import Agent
from agno.tools.local_file_system import LocalFileSystemTools

agent = Agent(
    instructions=[
        "You are a file management assistant that helps save content to local files",
        "Create files with appropriate names and extensions",
        "Organize files in the specified directory structure",
        "Provide clear feedback about file operations",
    ],
    tools=[LocalFileSystemTools(target_directory="./output")],
)

agent.print_response("Save this meeting summary to a file: 'Discussed Q4 goals and budget allocation'", stream=True)

Toolkit Params

ParameterTypeDefaultDescription
target_directoryOptional[str]NoneDefault directory for file operations. Uses the current directory if not set. Created if it doesn't exist.
default_extensionstr"txt"Default file extension to use if none specified.
enable_write_fileboolTrueEnable the write_file tool.
enable_read_fileboolTrueEnable the read_file tool.
restrict_to_base_dirboolTrueIf True, file operations cannot escape target_directory.
allboolFalseEnables all functionality when set to True.

Toolkit Functions

FunctionDescription
write_fileWrite content to a local file with customizable options.
read_fileRead content from a local file.

Developer Resources