Class SkillsAgentHook.Builder

java.lang.Object
com.alibaba.cloud.ai.graph.agent.hook.skills.SkillsAgentHook.Builder
Enclosing class:
SkillsAgentHook

public static class SkillsAgentHook.Builder extends Object
Builder for creating SkillsAgentHook instances.

Required:

  • skillRegistry: must be provided - use FileSystemSkillRegistry.builder() to create one

Optional:

  • autoReload: defaults to false - skills are loaded once during initialization
  • groupedTools: map from skill name to list of tools; passed to SkillsInterceptor so that when the LLM calls read_skill for a skill, those tools are added to the request's dynamicToolCallbacks

Example Usage:


 // Create a FileSystemSkillRegistry first
 FileSystemSkillRegistry registry = FileSystemSkillRegistry.builder()
     .userSkillsDirectory("~/saa/skills")
     .projectSkillsDirectory("./skills")
     .build();

 // Then create the hook with the registry
 SkillsAgentHook hook = SkillsAgentHook.builder()
     .skillRegistry(registry)
     .autoReload(true)
     .build();

 // Use a shared registry
 FileSystemSkillRegistry sharedRegistry = FileSystemSkillRegistry.builder().build();
 SkillsAgentHook hook1 = SkillsAgentHook.builder()
     .skillRegistry(sharedRegistry)
     .build();
 SkillsAgentHook hook2 = SkillsAgentHook.builder()
     .skillRegistry(sharedRegistry)
     .build();
 
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • skillRegistry

      public SkillsAgentHook.Builder skillRegistry(SkillRegistry skillRegistry)
      Sets the SkillRegistry instance.

      Required: Must be provided. Use FileSystemSkillRegistry.builder() to create one. This is useful when you want to share a registry between multiple hooks or components.

      Parameters:
      skillRegistry - the SkillRegistry to use (must not be null)
      Returns:
      this builder
    • autoReload

      public SkillsAgentHook.Builder autoReload(boolean autoReload)
      Sets whether to automatically reload skills in beforeAgent.

      Optional: Defaults to false

      If true, skills will be reloaded on each agent invocation. If false, skills are loaded once during registry initialization.

      Parameters:
      autoReload - true to enable auto-reload, false to disable
      Returns:
      this builder
    • groupedTools

      public SkillsAgentHook.Builder groupedTools(Map<String,List<org.springframework.ai.tool.ToolCallback>> groupedTools)
      Sets grouped tools: map from skill name to list of tools for that skill.

      Optional: When set, this map is passed to SkillsInterceptor. When the LLM calls read_skill with a given skill_name, the corresponding tools are added to the request's dynamicToolCallbacks.

      Parameters:
      groupedTools - map from skill name to list of ToolCallbacks (can be null or empty)
      Returns:
      this builder
    • build

      public SkillsAgentHook build()
      Builds the SkillsAgentHook instance with the configured parameters.
      Returns:
      a new SkillsAgentHook instance
      Throws:
      IllegalArgumentException - if skillRegistry is not provided