Class ShellTool2

java.lang.Object
com.alibaba.cloud.ai.graph.agent.tools.ShellTool2

public class ShellTool2 extends Object
A tool for executing shell commands using Spring AI Tool annotations. This tool allows for the execution of shell commands within a managed session. The session's lifecycle and configuration are handled by the ShellSessionManager. This implementation uses Spring AI Tool annotations (@Tool, @ToolParam) similar to FileSystemTools, providing better integration with the Spring AI framework. Example of creating an instance:
 ShellTool2 shellTool2 = ShellTool2.builder("/tmp/agent-workspace")
     .withName("shell")
     .build();
 
  • Field Details

  • Constructor Details

    • ShellTool2

      public ShellTool2(ShellSessionManager sessionManager)
      Constructs a new ShellTool2.
      Parameters:
      sessionManager - The manager for the shell session. Must not be null.
  • Method Details

    • executeShellCommand

      @Tool(name="shell", description="Execute a shell command inside a persistent session. Before running a command, confirm the working directory is correct (e.g., inspect with `ls` or `pwd`) and ensure any parent directories exist. Prefer absolute paths and quote paths containing spaces, such as `cd \"/path/with spaces\"`. Chain multiple commands with `&&` or `;` instead of embedding newlines. Avoid unnecessary `cd` usage unless explicitly required so the session remains stable. Outputs may be truncated when they become very large, and long running commands will be terminated once their configured timeout elapses.") public String executeShellCommand(@ToolParam(description="The command to execute in the shell.") String command, @ToolParam(description="Restart the shell session before executing the command (default: false).",required=false) Boolean restart, org.springframework.ai.chat.model.ToolContext toolContext)
    • getSessionManager

      public ShellSessionManager getSessionManager()
    • builder

      public static ShellTool2.Builder builder(String workspaceRoot)