File Tools
This feature is supported in the Professional Edition.
XpertAI's agent system includes a powerful File Tools Collection, providing AI with programmable file operations in a virtual workspace, enabling agents to read, create, edit, rewrite, delete, and list workspace files during execution.
These tools are integrated into the execution flow of digital expert agents, supporting workspaces tied to sessions/projects. They call backend file services through a unified interface, ensuring operations are both immediately visible and persistently stored.
๐ฆ Tools Overviewโ
Tool Name | Function Description |
---|---|
list_files | Lists all files in the current workspace |
create_file | Creates a new file with initial content |
str_replace | Replaces a unique string in a file |
full_file_rewrite | Overwrites file content entirely |
delete_file | Deletes a file at the specified path |
read_file | Reads the content of a specified file |
๐งฐ Function Detailsโ
๐ list_files
โ
Lists all files in the current session or project workspace, returning a list with file paths, URLs, and basic metadata.
- Path Description: Relative to the
/workspace
root directory (e.g.,src/main.py
). - Output: JSON list containing
filePath
and accessibleurl
. - Use Cases: Browsing the AI workspace file structure, confirming existing filenames, etc.
๐ create_file
โ
Creates a new file and writes initial content.
Parameters:
file_path
: Relative file path from/workspace
root (e.g.,src/main.py
)file_contents
: Initial file contentfile_description
(optional): File purpose descriptionpermissions
(optional): Octal permissions (defaults to644
)
Use Cases:
- Initializing programming or configuration files
- Generating code drafts for further modification
๐ str_replace
โ
Replaces a unique string in a specified file with new content.
Parameters:
file_path
: Target file path relative to/workspace
root (e.g.,src/main.py
)old_str
: Original text to be replaced (must appear exactly once)new_str
: Replacement text content
Restriction: For accuracy,
old_str
must appear exactly once; otherwise, an error is returned.Use Cases:
- Precisely replacing variable names, function names, or configuration items
- Correcting spelling or logical errors
๐งน full_file_rewrite
โ
Completely overwrites a file's content with new content, suitable for structural or bulk modifications.
Parameters:
file_path
: Target file path relative to/workspace
root (e.g.,src/main.py
)file_contents
: New content to overwritepermissions
(optional): Octal permissions (defaults to644
)
Use Cases:
- Large-scale file updates
- Rewriting entire documents or code based on AI output
๐๏ธ delete_file
โ
Deletes a file at the specified path and synchronizes database record removal.
Parameters:
file_path
: Relative path of the file to delete from/workspace
root (e.g.,src/main.py
)
Use Cases:
- Cleaning up unused files
- Removing erroneous or redundant generated results
๐ read_file
โ
Reads the current content of a file in the workspace.
- Use Cases:
- AI retrieves context before analyzing or modifying a file
- Users review current content before deciding on actions
โ๏ธ Operational Mechanismโ
- All file operations are performed within the agent's dedicated Sandbox Workspace, ensuring safe isolation.
- Each workspace is tied to a session or project.
- The file service relies on the
sandbox.fs
module, managing files through standardized interfaces.
๐ Typical Use Casesโ
- AI Code Generation: Creating and iteratively modifying
.py
,.js
, or other source code files - Collaborative Document Writing: Gradually generating and adjusting
.md
files - Data Processing Tasks: Reading or replacing fields/rows in
.csv
files - Project Auto-Configuration: Batch-generating configuration files with replace/rewrite operations
โ Usage Recommendationsโ
- Use
list_files
andread_file
to gather context and avoid path or content errors. - Use
str_replace
for precise modifications andfull_file_rewrite
for major changes or refactoring. - Ensure all paths are relative to
/workspace
and avoid absolute paths or parent directory references (e.g.,../
).
๐ Security and Permissionsโ
- File operation permissions default to
0644
, with optional custom permissions. - All AI operations are logged, supporting frontend display and auditing.
- Version persistence and file recovery mechanisms are supported.