Skip to main content

Overview

File tool allows you to read, write, and manage files from your AI agents. The user asks to read or write a file; the agent performs the operation and returns the result.

Installation

pip install "praisonai[tools]"

Quick Start

1

Simple Usage

from praisonai_tools import FileTool

# Initialize
file = FileTool()

# Read file
content = file.read("document.txt")
print(content)
2

With Configuration

Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.

Usage with Agent

from praisonaiagents import Agent
from praisonai_tools import FileTool

agent = Agent(
    name="FileManager",
    instructions="You help manage files.",
    tools=[FileTool()]
)

response = agent.chat("Read the contents of config.json")
print(response)

Available Methods

read(path)

Read file contents.
from praisonai_tools import FileTool

file = FileTool()
content = file.read("data.txt")

write(path, content)

Write content to a file.
file.write("output.txt", "Hello World!")

list_dir(path)

List directory contents.
files = file.list_dir("./documents")

Common Errors

ErrorCauseSolution
File not foundInvalid pathCheck file path
Permission deniedNo accessCheck permissions

How It Works


Best Practices

Pass absolute paths so file operations are predictable regardless of the working directory.
Check for existing files before write to avoid data loss.
Limit file operations to a known workspace so the agent can’t touch sensitive paths.

JSON

JSON files

CSV

CSV files

Shell

Shell commands