Class SkillsInterceptor

java.lang.Object
com.alibaba.cloud.ai.graph.agent.interceptor.ModelInterceptor
com.alibaba.cloud.ai.graph.agent.interceptor.skills.SkillsInterceptor
All Implemented Interfaces:
Interceptor

public class SkillsInterceptor extends ModelInterceptor
Interceptor for integrating Claude-style Skills into ReactAgent. This interceptor injects skills metadata into system prompt, following progressive disclosure pattern: - Injects lightweight skills list (name + description + path) - Injects registry type and skill load instructions from the SkillRegistry - LLM reads full SKILL.md content when needed using `read_skill` tool

Registration:

  • Recommended: Usually registered automatically via SkillsAgentHook, which creates and configures this interceptor along with the `read_skill` tool.
  • Manual: Can also be manually created and registered if you need more control over the interceptor configuration.
Skills loading is handled by SkillsAgentHook in beforeAgent (if using SkillsAgentHook). This interceptor reads from a shared SkillRegistry to inject skills into the system prompt. The interceptor uses the SkillRegistry's generic methods (getRegistryType(), getSkillLoadInstructions()) to build the prompt, making it compatible with any SkillRegistry implementation.

Usage Examples:

Automatic registration via SkillsAgentHook (recommended):

 FileSystemSkillRegistry registry = FileSystemSkillRegistry.builder().build();
 SkillsAgentHook hook = SkillsAgentHook.builder()
     .skillRegistry(registry)
     .autoReload(true)
     .build();
 // SkillsInterceptor is automatically created and registered by the hook
 

Manual registration with grouped tools (skill name → tools for dynamic injection):

 Map<String, List<ToolCallback>> groupedTools = Map.of("my-skill", List.of(myTool));
 SkillsInterceptor interceptor = SkillsInterceptor.builder()
     .skillRegistry(registry)
     .groupedTools(groupedTools)
     .build();
 

When groupedTools is configured, this interceptor scans ModelRequest messages for AssistantMessage with tool calls named "read_skill". For each such call, the skill_name argument is recorded. Tools from getGroupedTools() for those skill names are then added to the request's dynamicToolCallbacks.

  • Method Details

    • builder

      public static SkillsInterceptor.Builder builder()
    • interceptModel

      public ModelResponse interceptModel(ModelRequest request, ModelCallHandler handler)
      Description copied from class: ModelInterceptor
      Wrap a model call with custom logic. Implementations can: - Modify the request before calling the handler - Call the handler multiple times (retry logic) - Modify the response after handler returns - Handle exceptions and provide fallbacks
      Specified by:
      interceptModel in class ModelInterceptor
      Parameters:
      request - The model request
      handler - The next handler in the chain (or base handler)
      Returns:
      The model response
    • getGroupedTools

      public Map<String,List<org.springframework.ai.tool.ToolCallback>> getGroupedTools()
    • getName

      public String getName()