Class ShellTool2
java.lang.Object
com.alibaba.cloud.ai.graph.agent.tools.ShellTool2
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();
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ShellTool2.BuilderexecuteShellCommand(String command, Boolean restart, org.springframework.ai.chat.model.ToolContext toolContext)
-
Field Details
-
DEFAULT_TOOL_DESCRIPTION
- See Also:
-
-
Constructor Details
-
ShellTool2
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
-
builder
-