类 WriteFileTool
java.lang.Object
io.agentscope.core.tool.file.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.
-
构造器概要
构造器构造器说明Creates a WriteFileTool with no base directory restriction.WriteFileTool(String baseDir) Creates a WriteFileTool with a base directory restriction. -
方法概要
修饰符和类型方法说明reactor.core.publisher.Mono<ToolResultBlock> insertTextFile(String filePath, String content, Integer lineNumber) Insert content at the specified line number in a text file.reactor.core.publisher.Mono<ToolResultBlock> writeTextFile(String filePath, String content, String ranges) Create/Replace/Overwrite content in a text file.
-
构造器详细资料
-
WriteFileTool
public WriteFileTool()Creates a WriteFileTool with no base directory restriction. -
WriteFileTool
Creates a WriteFileTool with a base directory restriction.- 参数:
baseDir- The base directory to restrict file access to. If null, no restriction is applied.
-
-
方法详细资料
-
insertTextFile
@Tool(name="insert_text_file", description="Insert the content at the specified line number in a text file. Use this when you need to add content at a specific position without replacing existing content. The content will be inserted as a new line, pushing existing lines down.") public reactor.core.publisher.Mono<ToolResultBlock> insertTextFile(@ToolParam(name="file_path",description="The target file path") String filePath, @ToolParam(name="content",description="The content to be inserted") String content, @ToolParam(name="line_number",description="The line number at which the content should be inserted, starting from 1. If it exceeds the number of lines, it will be appended to the end.") Integer lineNumber) Insert content at the specified line number in a text file.- 参数:
filePath- The target file pathcontent- The content to be insertedlineNumber- 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.- 返回:
- The result of the insertion operation
-
writeTextFile
@Tool(name="write_text_file", description="Create/Replace/Overwrite content in a text file. When ranges is provided, the content will be replaced in the specified range. Otherwise, the entire file (if exists) will be overwritten. Use this for creating new files or replacing large sections of content.") public reactor.core.publisher.Mono<ToolResultBlock> writeTextFile(@ToolParam(name="file_path",description="The target file path") String filePath, @ToolParam(name="content",description="The content to be written") String content, @ToolParam(name="ranges",description="The range of lines to be replaced as [start, end], e.g., \'[1,5]\' or \'1,5\'. If null or empty, the entire file will be overwritten.",required=false) String ranges) Create/Replace/Overwrite content in a text file. When ranges is provided, the content will be replaced in the specified range. Otherwise, the entire file (if exists) will be overwritten.- 参数:
filePath- The target file pathcontent- The content to be writtenranges- The range of lines to be replaced as [start, end]. If null, the entire file will be overwritten. Format: "[1,5]" or "1,5"- 返回:
- The result of the writing operation
-