AS AgentScopeAPI 手册 / API Reference

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–58

WriteFileTool

public WriteFileTool(String baseDir)

初始化 WriteFileTool 实例。

Creates a WriteFileTool 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/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
filePathString目标文件路径。The target file path
contentString内容(类型 `String`)。The content to be inserted
lineNumberIntegerline 数量(类型 `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.
返回Returns Mono<ToolResultBlock>
返回Mono。The result of the insertion operation
源码Source io/agentscope/core/tool/file/WriteFileTool.java:84–224

writeTextFile

public Mono<ToolResultBlock> writeTextFile(String filePath, String content, String ranges)

执行写入文本文件相关操作。

Create/Replace/Overwrite content in a text file.

参数Parameters
名称Name类型Type说明Description
filePathString目标文件路径。The target file path
contentString内容(类型 `String`)。The content to be written
rangesStringranges(类型 `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"
返回Returns Mono<ToolResultBlock>
返回Mono。The result of the writing operation
源码Source io/agentscope/core/tool/file/WriteFileTool.java:237–404
基于官方固定版本源码静态生成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.