Class EditFileTool
java.lang.Object
com.alibaba.cloud.ai.graph.agent.extension.tools.filesystem.EditFileTool
- All Implemented Interfaces:
BiFunction<EditFileTool.EditFileRequest,org.springframework.ai.chat.model.ToolContext, String>
public class EditFileTool
extends Object
implements BiFunction<EditFileTool.EditFileRequest,org.springframework.ai.chat.model.ToolContext,String>
Tool for editing files using string replacement.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRequest structure for editing a file. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(EditFileTool.EditFileRequest request, org.springframework.ai.chat.model.ToolContext toolContext) static org.springframework.ai.tool.ToolCallbackcreateEditFileToolCallback(String description) static StringeditFileContent(Path filePath, String oldString, String newString, boolean replaceAll) Core logic for editing file content by replacing string occurrences.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
-
EditFileTool
public EditFileTool()
-
-
Method Details
-
apply
public String apply(EditFileTool.EditFileRequest request, org.springframework.ai.chat.model.ToolContext toolContext) - Specified by:
applyin interfaceBiFunction<EditFileTool.EditFileRequest,org.springframework.ai.chat.model.ToolContext, String>
-
editFileContent
public static String editFileContent(Path filePath, String oldString, String newString, boolean replaceAll) Core logic for editing file content by replacing string occurrences. This method can be reused by other classes like FileSystemTools.- Parameters:
filePath- The path to the file to editoldString- The text to replacenewString- The text to replace it withreplaceAll- Whether to replace all occurrences (true) or only if unique (false)- Returns:
- Success message with count of replacements, or error message
-
createEditFileToolCallback
public static org.springframework.ai.tool.ToolCallback createEditFileToolCallback(String description)
-