Skip to main content
The AutonomousFilesystemToolKit provides comprehensive file operations, all sandboxed to the workspace directory.

Available Tools

ToolDescription
read_fileRead file contents with optional line offset/limit
write_fileCreate or overwrite files
edit_fileReplace text in files (requires reading first)
list_filesList directory contents (recursive or non-recursive)
search_filesSearch for files by name pattern
grep_filesSearch file contents using regex
file_infoGet file metadata (size, dates, permissions)
create_directoryCreate directories recursively
move_fileMove or rename files
copy_fileCopy files or directories
delete_fileDelete files or directories

Example: Code Analysis

from upsonic import AutonomousAgent, Task

agent = AutonomousAgent(
    model="openai/gpt-4o",
    workspace="/path/to/project"
)

# Search and analyze code
task = Task("Find all Python files that contain 'TODO' comments and list them with line numbers")
agent.print_do(task)

Example: Bulk File Operations

from upsonic import AutonomousAgent, Task

agent = AutonomousAgent(
    model="openai/gpt-4o",
    workspace="/path/to/project"
)

# Create project structure
task = Task("""
Create a basic Python package structure:
- src/mypackage/__init__.py
- src/mypackage/core.py with a sample function
- tests/__init__.py
- tests/test_core.py with a basic test
""")
agent.print_do(task)

Read-Before-Edit Safety

The filesystem toolkit enforces reading a file before editing it. This prevents accidental modifications to files the agent hasn’t seen:
from upsonic import AutonomousAgent, Task

agent = AutonomousAgent(
    model="openai/gpt-4o",
    workspace="/path/to/project"
)

# The agent will automatically read first, then edit
task = Task("Add type hints to all functions in utils.py")
agent.print_do(task)

Direct Toolkit Access

Access the toolkit directly for programmatic use:
from upsonic import AutonomousAgent

agent = AutonomousAgent(
    model="openai/gpt-4o",
    workspace="/path/to/project"
)

# Read a file
content = agent.filesystem_toolkit.read_file("README.md")
print(content)

# List files in a directory
files = agent.filesystem_toolkit.list_files("src", recursive=True)
print(files)

# Search for files by pattern
python_files = agent.filesystem_toolkit.search_files("*.py")
print(python_files)

# Check what files were read
print(agent.filesystem_toolkit.get_read_files())

# Reset tracking if needed
agent.filesystem_toolkit.reset_read_tracking()