类 WriteFileTool

java.lang.Object
io.agentscope.core.tool.file.WriteFileTool

public class WriteFileTool extends Object
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.

  • 构造器详细资料

    • WriteFileTool

      public WriteFileTool()
      Creates a WriteFileTool with no base directory restriction.
    • WriteFileTool

      public WriteFileTool(String baseDir)
      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 path
      content - The content to be inserted
      lineNumber - 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 path
      content - The content to be written
      ranges - 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