类 ReadFileTool
java.lang.Object
io.agentscope.core.tool.file.ReadFileTool
Tool for viewing text file content with optional line range specification and listing directory
contents.
This tool provides the following capabilities:
- Viewing entire file content
- Viewing specific line ranges (e.g., lines 1-100)
- Viewing from the end using negative indices (e.g., last 100 lines: [-100, -1])
- Listing files and directories in a specified directory with full paths
Security: When baseDir is specified, all file operations are restricted to that directory to prevent unauthorized file access.
-
构造器概要
构造器构造器说明Creates a ReadFileTool with no base directory restriction.ReadFileTool(String baseDir) Creates a ReadFileTool with a base directory restriction. -
方法概要
修饰符和类型方法说明reactor.core.publisher.Mono<ToolResultBlock> listDirectory(String dirPath) List files and directories in the specified directory.reactor.core.publisher.Mono<ToolResultBlock> viewTextFile(String filePath, String ranges) View the file content in the specified range with line numbers.
-
构造器详细资料
-
ReadFileTool
public ReadFileTool()Creates a ReadFileTool with no base directory restriction. -
ReadFileTool
Creates a ReadFileTool with a base directory restriction.- 参数:
baseDir- The base directory to restrict file access to. If null, no restriction is applied.
-
-
方法详细资料
-
viewTextFile
@Tool(name="view_text_file", description="View the file content in the specified range with line numbers. If ranges is not provided, the entire file will be returned. Use this to read and inspect file contents. Supports negative indices to view from the end (e.g., \'-100,-1\' for last 100 lines).") public reactor.core.publisher.Mono<ToolResultBlock> viewTextFile(@ToolParam(name="file_path",description="The target file path") String filePath, @ToolParam(name="ranges",description="The range of lines to be viewed (e.g., \'1,100\' or \'[1,100]\'), inclusive. If not provided, the entire file will be returned. To view the last 100 lines, use \'-100,-1\'.",required=false) String ranges) View the file content in the specified range with line numbers. If ranges is not provided, the entire file will be returned.- 参数:
filePath- The target file pathranges- The range of lines to be viewed (e.g., lines 1 to 100: "1,100"), inclusive. If not provided, the entire file will be returned. To view the last 100 lines, use "-100,-1". Format: "start,end" or "[start,end]"- 返回:
- The file content with line numbers or an error message
-
listDirectory
@Tool(name="list_directory", description="List all files and directories in the specified directory. Returns the full paths of all files and folders in the directory. Use this to explore the file system structure.") public reactor.core.publisher.Mono<ToolResultBlock> listDirectory(@ToolParam(name="dir_path",description="The target directory path to list files and folders") String dirPath) List files and directories in the specified directory.- 参数:
dirPath- The target directory path- 返回:
- A list of files and directories with their full paths
-