Class SkillsAgentHook

java.lang.Object
com.alibaba.cloud.ai.graph.agent.hook.AgentHook
com.alibaba.cloud.ai.graph.agent.hook.skills.SkillsAgentHook
All Implemented Interfaces:
Hook, Prioritized

public class SkillsAgentHook extends AgentHook
AgentHook for integrating Skills with ReactAgent. This hook provides a complete Skills integration solution: - Manages skill loading and reloading from the SkillRegistry - Provides the `read_skill` tool for LLM to read SKILL.md files - Automatically creates and configures SkillsInterceptor to inject skills into system prompts The hook wraps a SkillRegistry instance and shares it with SkillsInterceptor. The SkillRegistry must be provided explicitly - it will not be created automatically. Skills can be optionally reloaded in beforeAgent if auto-reload is enabled. The hook uses the SkillRegistry's generic interface methods, making it compatible with any SkillRegistry implementation (FileSystemSkillRegistry, DatabaseSkillRegistry, etc.).

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();

 // With grouped tools (skill name → tools for dynamic injection when LLM calls read_skill)
 Map<String, List<ToolCallback>> groupedTools = Map.of("my-skill", List.of(myTool));
 SkillsAgentHook hookWithTools = SkillsAgentHook.builder()
     .skillRegistry(registry)
     .groupedTools(groupedTools)
     .build();
 
  • Method Details

    • builder

      public static SkillsAgentHook.Builder builder()
    • beforeAgent

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

      public SkillRegistry getSkillRegistry()
      Get the SkillRegistry instance used by this hook. This allows sharing the registry with SkillsInterceptor.
      Returns:
      the SkillRegistry instance
    • getModelInterceptors

      public List<ModelInterceptor> getModelInterceptors()
      Description copied from interface: Hook
      Gets the list of model interceptors provided by this hook.

      Model interceptors can modify model requests/responses, add retry logic, implement guardrails, or provide other cross-cutting concerns.

      These interceptors will be merged with the agent's configured interceptors and applied to all model calls.

      Returns:
      list of model interceptors, empty list by default
      See Also:
    • 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.

      Returns:
      list of tool callbacks, empty list by default
      See Also:
      • ToolCallback
    • getSkillCount

      public int getSkillCount()
    • hasSkill

      public boolean hasSkill(String skillName)
    • listSkills

      public List<SkillMetadata> listSkills()
    • 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.
      Returns:
      the hook name, must not be null