Class ShellToolAgentHook

java.lang.Object
com.alibaba.cloud.ai.graph.agent.hook.AgentHook
com.alibaba.cloud.ai.graph.agent.hook.shelltool.ShellToolAgentHook
All Implemented Interfaces:
Hook, ToolInjection, Prioritized

public class ShellToolAgentHook extends AgentHook implements ToolInjection
Hook for managing ShellTool2 session. This hook initializes the shell session before the agent starts and cleans it up after the agent finishes. Supports ShellTool2 (@Tool annotation).
  • Method Details

    • builder

      public static ShellToolAgentHook.Builder builder()
      Create a new builder instance.
      Returns:
      a new Builder instance
    • beforeAgent

      public CompletableFuture<Map<String,Object>> beforeAgent(OverAllState state, RunnableConfig config)
      Overrides:
      beforeAgent in class AgentHook
    • afterAgent

      public CompletableFuture<Map<String,Object>> afterAgent(OverAllState state, RunnableConfig config)
      Overrides:
      afterAgent in class AgentHook
    • getName

      public String getName()
      Description copied from interface: Hook
      Gets the unique name of this hook. The name is used to identify the hook in the execution graph.
      Specified by:
      getName in interface Hook
      Returns:
      the hook name, must not be null
    • injectTool

      public void injectTool(org.springframework.ai.tool.ToolCallback toolCallback)
      Description copied from interface: ToolInjection
      Inject a tool into the hook. Only the tool matching the required tool name or type will be injected.
      Specified by:
      injectTool in interface ToolInjection
      Parameters:
      toolCallback - the tool callback to inject
    • getTools

      public List<org.springframework.ai.tool.ToolCallback> getTools()
      Description copied from interface: Hook
      Gets the list of tools provided by this hook.

      Tools provided by hooks will be merged with the agent's configured tools and made available for the agent to use during execution.

      These tools will be registered with the agent's tool node and can be invoked by the agent during its execution.

      Specified by:
      getTools in interface Hook
      Returns:
      list of tool callbacks, empty list by default
      See Also:
      • ToolCallback
    • getRequiredToolName

      public String getRequiredToolName()
      Description copied from interface: ToolInjection
      Get the required tool name that this hook needs. Return null to match by tool type instead.
      Specified by:
      getRequiredToolName in interface ToolInjection
      Returns:
      the tool name required by this hook, or null to match by type
    • getRequiredToolType

      public Class<? extends org.springframework.ai.tool.ToolCallback> getRequiredToolType()
      Description copied from interface: ToolInjection
      Get the required tool type (class) that this hook needs. Return null to match by tool name instead. If both name and type are null, the first available tool will be injected.
      Specified by:
      getRequiredToolType in interface ToolInjection
      Returns:
      the tool class type required by this hook, or null to match by name
    • getShellTool2

      protected ShellTool2 getShellTool2()
      Get the injected ShellTool2 instance.
      Returns:
      the ShellTool2 instance, or null if not injected