Supyagent
ToolsBuilt-in Tools

Files Tool

Reference for the files default tool: read_file, read_file_lines, write_file, list_directory, file_info, delete_file, create_directory, copy_file, move_file.

Files Tool

Script: powers/files.py Dependencies: pydantic

Read, write, copy, move, and delete files and directories. Includes line-number display for code files and efficient partial file reading.


read_file

Read the entire contents of a file, optionally with line numbers.

Input

FieldTypeDefaultDescription
pathstrrequiredPath to the file to read
encodingstr"utf-8"File encoding
include_line_numbersbooltruePrefix each line with its 1-based line number

Output

FieldTypeDescription
okbooltrue if file was read successfully
contentstrFile contents (with line numbers if enabled)
sizeintFile size in bytes
pathstrAbsolute path to the file
errorstrError message on failure

Examples

// Read with line numbers (default)
{"path": "src/main.py"}
// Content: "1: import os\n2: import sys\n3: \n4: def main():\n..."

// Read without line numbers
{"path": "data.txt", "include_line_numbers": false}

// Different encoding
{"path": "legacy.txt", "encoding": "latin-1"}

Notes

  • Maximum file size is 50MB
  • Line numbers are right-justified and formatted as N: line content
  • Returns the absolute path of the file in the output

read_file_lines

Read a specific range of lines from a file. Much more efficient than read_file for large files.

Input

FieldTypeDefaultDescription
pathstrrequiredPath to the file to read
start_lineint1First line to read (1-based, inclusive)
end_lineint-1Last line to read (1-based, inclusive). -1 = end of file
encodingstr"utf-8"File encoding
include_line_numbersbooltruePrefix each line with its line number

Output

FieldTypeDescription
okbooltrue if read succeeded
contentstrSelected lines
start_lineintActual start line (after clamping)
end_lineintActual end line
total_linesintTotal number of lines in the file
pathstrAbsolute path
errorstrError message on failure

Examples

// Read lines 1-50
{"path": "main.py", "start_line": 1, "end_line": 50}

// Read lines 100-150
{"path": "main.py", "start_line": 100, "end_line": 150}

// Read the last line
{"path": "big.log", "start_line": -1, "end_line": -1}

Notes

  • Line numbers format as N| line content (with pipe separator)
  • Negative indices work like Python: -1 = last line
  • Both start and end are inclusive

write_file

Write content to a file, creating parent directories if needed.

Input

FieldTypeDefaultDescription
pathstrrequiredPath to the file to write
contentstrrequiredContent to write
encodingstr"utf-8"File encoding
create_dirsbooltrueCreate parent directories if needed

Output

FieldTypeDescription
okbooltrue if write succeeded
pathstrAbsolute path to the written file
sizeintSize of written content in bytes
errorstrError message on failure

Examples

// Write a new file
{"path": "output.txt", "content": "Hello, world!"}

// Write to nested directory (auto-created)
{"path": "data/results/output.json", "content": "{\"status\": \"ok\"}"}

list_directory

List files and directories, optionally filtered by glob pattern.

Input

FieldTypeDefaultDescription
pathstr"."Directory path
patternstrnullOptional glob pattern (e.g., *.py)
recursiveboolfalseList recursively

Output

FieldTypeDescription
okbooltrue if directory was listed
itemslistArray of {name, path, type, size} objects
countintNumber of items found
errorstrError message on failure

Examples

// List current directory
{"path": "."}

// List Python files
{"path": "src", "pattern": "*.py"}

// Recursive markdown search
{"path": ".", "pattern": "*.md", "recursive": true}

file_info

Get detailed information about a file or directory.

Input

FieldTypeDefaultDescription
pathstrrequiredPath to get info for

Output

FieldTypeDescription
okbooltrue if path exists
pathstrAbsolute path
namestrFile/directory name
typestr"file" or "directory"
sizeintSize in bytes
extensionstrFile extension (files only)
errorstrError message on failure

delete_file

Delete a single file (not directories).

Input

FieldTypeDefaultDescription
pathstrrequiredPath to the file to delete

Output

FieldTypeDescription
okbooltrue if deleted
deletedstrPath of the deleted file
errorstrError message on failure

Notes

  • Will not delete directories -- returns an error suggesting delete_directory
  • Returns an error if the file does not exist

create_directory

Create a directory, including parent directories.

Input

FieldTypeDefaultDescription
pathstrrequiredDirectory path to create
parentsbooltrueCreate parent directories if needed

Output

FieldTypeDescription
okbooltrue if created
pathstrAbsolute path of the created directory
errorstrError message on failure

copy_file

Copy a file to a new location.

Input

FieldTypeDefaultDescription
sourcestrrequiredSource file path
destinationstrrequiredDestination path

Output

FieldTypeDescription
okbooltrue if copied
sourcestrSource path
destinationstrDestination path
errorstrError message on failure

Notes

  • Preserves file metadata (timestamps, permissions) via shutil.copy2
  • Automatically creates the destination directory if it doesn't exist

move_file

Move or rename a file or directory.

Input

FieldTypeDefaultDescription
sourcestrrequiredSource path
destinationstrrequiredDestination path

Output

FieldTypeDescription
okbooltrue if moved
sourcestrOriginal path
destinationstrNew path
errorstrError message on failure

Tips

  • All path inputs support ~ expansion (e.g., ~/Documents/file.txt)
  • read_file with include_line_numbers: true is ideal for code review -- the LLM can reference specific line numbers
  • Use read_file_lines for large files to avoid loading the entire file into memory
  • write_file with create_dirs: true means you never need to call create_directory separately