AS AgentScopeAPI 手册 / API Reference

ReadFileTool

public class ReadFileTool
源码Source 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.

源码Source io/agentscope/core/tool/file/ReadFileTool.java:63–65

ReadFileTool

public ReadFileTool(String baseDir)

初始化 ReadFileTool 实例。

Creates a ReadFileTool with a base directory restriction.

参数Parameters
名称Name类型Type说明Description
baseDirString基类目录(类型 `String`)。The base directory to restrict file access to. If null, no restriction is applied.
源码Source 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.

参数Parameters
名称Name类型Type说明Description
filePathString目标文件路径。The target file path
rangesStringranges(类型 `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]"
返回Returns Mono<ToolResultBlock>
返回Mono。The file content with line numbers or an error message
源码Source io/agentscope/core/tool/file/ReadFileTool.java:91–228

listDirectory

public Mono<ToolResultBlock> listDirectory(String dirPath)

列出目录。

List files and directories in the specified directory.

参数Parameters
名称Name类型Type说明Description
dirPathString目标目录路径。The target directory path
返回Returns Mono<ToolResultBlock>
返回Mono。A list of files and directories with their full paths
源码Source io/agentscope/core/tool/file/ReadFileTool.java:236–346
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.