ReadFileTool
public class ReadFileTool
io/agentscope/core/tool/file/ReadFileTool.java:50–387读取文件工具,封装可被智能体调用的能力。位于 io.agentscope.core.tool.file 包。核心成员包括 viewTextFile、listDirectory、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.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ReadFileTool() | 初始化 `ReadFileTool` 实例。 Creates a ReadFileTool with no base directory restriction. |
public ReadFileTool(String baseDir) | 初始化 `ReadFileTool` 实例。 Creates a ReadFileTool with a base directory restriction. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<ToolResultBlock> viewTextFile(String filePath, String ranges) | 执行 `viewTextFile` 方法。 View the file content in the specified range with line numbers. |
public Mono<ToolResultBlock> listDirectory(String dirPath) | 列出目录。 List files and directories in the specified directory. |
构造器详情Constructor Detail
ReadFileTool
public ReadFileTool()
初始化 ReadFileTool 实例。
Creates a ReadFileTool with no base directory restriction.
io/agentscope/core/tool/file/ReadFileTool.java:63–65ReadFileTool
public ReadFileTool(String baseDir)
初始化 ReadFileTool 实例。
Creates a ReadFileTool with a base directory restriction.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
baseDir | String | 基类目录(类型 `String`)。The base directory to restrict file access to. If null, no restriction is applied. |
io/agentscope/core/tool/file/ReadFileTool.java:72–79方法详情Method Detail
viewTextFile
public Mono<ToolResultBlock> viewTextFile(String filePath, String ranges)
执行 viewTextFile 方法。
View the file content in the specified range with line numbers.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
filePath | String | 目标文件路径。The target file path |
ranges | String | ranges(类型 `String`)。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]" |
Mono<ToolResultBlock>io/agentscope/core/tool/file/ReadFileTool.java:91–228listDirectory
public Mono<ToolResultBlock> listDirectory(String dirPath)
列出目录。
List files and directories in the specified directory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dirPath | String | 目标目录路径。The target directory path |
Mono<ToolResultBlock>io/agentscope/core/tool/file/ReadFileTool.java:236–346