WriteFileTool
public class WriteFileTool
源码Source
io/agentscope/core/tool/file/WriteFileTool.java:43–405写入文件工具,封装可被智能体调用的能力。位于 io.agentscope.core.tool.file 包。核心成员包括 insertTextFile、writeTextFile、WriteFileTool。
Text file writing and insertion tools.
Provides tools for manipulating text files, including:
-
Inserting content at specific line numbers
-
Writing/replacing content with optional line range specification
Security: When baseDir is specified, all file operations are restricted to that directory to prevent unauthorized file access.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public WriteFileTool() | 初始化 `WriteFileTool` 实例。 Creates a WriteFileTool with no base directory restriction. |
public WriteFileTool(String baseDir) | 初始化 `WriteFileTool` 实例。 Creates a WriteFileTool with a base directory restriction. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<ToolResultBlock> insertTextFile(String filePath, String content, Integer lineNumber) | 插入文本文件。 Insert content at the specified line number in a text file. |
public Mono<ToolResultBlock> writeTextFile(String filePath, String content, String ranges) | 执行写入文本文件相关操作。 Create/Replace/Overwrite content in a text file. |
构造器详情Constructor Detail
WriteFileTool
public WriteFileTool()
初始化 WriteFileTool 实例。
Creates a WriteFileTool with no base directory restriction.
源码Source
io/agentscope/core/tool/file/WriteFileTool.java:56–58WriteFileTool
public WriteFileTool(String baseDir)
初始化 WriteFileTool 实例。
Creates a WriteFileTool with a base directory restriction.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
baseDir | String | 基类目录(类型 `String`)。The base directory to restrict file access to. If null, no restriction is applied. |
源码Source
io/agentscope/core/tool/file/WriteFileTool.java:65–72方法详情Method Detail
insertTextFile
public Mono<ToolResultBlock> insertTextFile(String filePath, String content, Integer lineNumber)
插入文本文件。
Insert content at the specified line number in a text file.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
filePath | String | 目标文件路径。The target file path |
content | String | 内容(类型 `String`)。The content to be inserted |
lineNumber | Integer | line 数量(类型 `Integer`)。The line number at which the content should be inserted, starting from 1. If it exceeds the number of lines in the file, it will be appended to the end of the file. |
Mono<ToolResultBlock>返回Mono。The result of the insertion operation
源码Source
io/agentscope/core/tool/file/WriteFileTool.java:84–224writeTextFile
public Mono<ToolResultBlock> writeTextFile(String filePath, String content, String ranges)
执行写入文本文件相关操作。
Create/Replace/Overwrite content in a text file.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
filePath | String | 目标文件路径。The target file path |
content | String | 内容(类型 `String`)。The content to be written |
ranges | String | ranges(类型 `String`)。The range of lines to be replaced as [start, end]. If null, the entire file will be overwritten. Format: "[1,5]" or "1,5" |
Mono<ToolResultBlock>返回Mono。The result of the writing operation
源码Source
io/agentscope/core/tool/file/WriteFileTool.java:237–404