Skip to main content
Use the built-in FileSystemTools to interact with your filesystem. It provides a comprehensive set of tools for reading, writing, and managing files and directories.

Usage

Import and use the FileSystemTools:
import os
from hypertic.agents import Agent
from hypertic.models import OpenAIChat
from hypertic.tools import FileSystemTools

# Initialize with optional root directory
filesystem_tools = FileSystemTools(root_dir="./data")

model = OpenAIChat(model="gpt-4o")
agent = Agent(
    model=model,
    tools=[filesystem_tools],
)

response = agent.run("List all files in the current directory")
print(response.content)

Features

The FileSystemTools provides:
  • List Directory - List contents of directories
  • Read File - Read file contents
  • Write File - Create and write to files
  • Copy File - Copy files to new locations
  • Move File - Move or rename files
  • Search Files - Search for files by pattern
  • Delete File - Delete files

Configuration

You can specify a root directory when initializing FileSystemTools:
from hypertic.tools import FileSystemTools

# All file operations will be relative to this directory
filesystem_tools = FileSystemTools(root_dir="./data")

Example

import os
import asyncio
from hypertic.agents import Agent
from hypertic.models import OpenAIChat
from hypertic.tools import FileSystemTools

# Set root directory for file operations
test_dir = os.path.join(os.path.dirname(__file__), "data")
filesystem_tools = FileSystemTools(root_dir=test_dir)

model = OpenAIChat(model="gpt-4o")
agent = Agent(
    model=model,
    tools=[filesystem_tools],
)

async def main():
    # List directory contents
    response = await agent.arun("List all the contents")
    print(response.content)
    
    # Read a file
    response = await agent.arun("Read the contents of sample.txt")
    print(response.content)

asyncio.run(main())
The agent can use FileSystemTools to perform various file operations based on natural language requests.