Class ReadFileTool
java.lang.Object
com.alibaba.cloud.ai.graph.agent.extension.tools.filesystem.ReadFileTool
- All Implemented Interfaces:
BiFunction<ReadFileTool.ReadFileRequest,org.springframework.ai.chat.model.ToolContext, String>
public class ReadFileTool
extends Object
implements BiFunction<ReadFileTool.ReadFileRequest,org.springframework.ai.chat.model.ToolContext,String>
Tool for reading file contents with pagination support.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRequest structure for reading a file. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(ReadFileTool.ReadFileRequest request, org.springframework.ai.chat.model.ToolContext toolContext) static org.springframework.ai.tool.ToolCallbackcreateReadFileToolCallback(String description) static StringreadFileContent(Path filePath, Integer offset, Integer limit, boolean checkEmpty) Core logic for reading file content with pagination.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThen
-
Field Details
-
DESCRIPTION
- See Also:
-
-
Constructor Details
-
ReadFileTool
public ReadFileTool()
-
-
Method Details
-
apply
public String apply(ReadFileTool.ReadFileRequest request, org.springframework.ai.chat.model.ToolContext toolContext) - Specified by:
applyin interfaceBiFunction<ReadFileTool.ReadFileRequest,org.springframework.ai.chat.model.ToolContext, String>
-
readFileContent
public static String readFileContent(Path filePath, Integer offset, Integer limit, boolean checkEmpty) Core logic for reading file content with pagination. This method can be reused by other classes like FileSystemTools.- Parameters:
filePath- The path to the file to readoffset- Line offset to start reading from (null means 0)limit- Maximum number of lines to read (null means 500)checkEmpty- Whether to check for empty content and return warning- Returns:
- Formatted file content with line numbers, or error message
-
createReadFileToolCallback
public static org.springframework.ai.tool.ToolCallback createReadFileToolCallback(String description)
-