Class SubAgentInterceptor

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

public class SubAgentInterceptor extends ModelInterceptor
SubAgent interceptor that provides subagent invocation capabilities to agents. This interceptor adds a `task` tool to the agent that can be used to invoke subagents. Subagents are useful for handling complex tasks that require multiple steps, or tasks that require a lot of context to resolve. A chief benefit of subagents is that they can handle multi-step tasks, and then return a clean, concise response to the main agent. This interceptor comes with a default general-purpose subagent that can be used to handle the same tasks as the main agent, but with isolated context. Example:
 SubAgentInterceptor interceptor = SubAgentInterceptor.builder()
     .defaultModel(chatModel)
     .addSubAgent(SubAgentSpec.builder()
         .name("research-analyst")
         .description("Use this agent to conduct thorough research on complex topics")
         .systemPrompt("You are a research analyst...")
         .build())
     .build();
 
  • Method Details

    • builder

      public static SubAgentInterceptor.Builder builder()
    • getTools

      public List<org.springframework.ai.tool.ToolCallback> getTools()
      Description copied from class: ModelInterceptor
      Get tools provided by this interceptor. Interceptors can provide built-in tools that will be automatically added to the agent.
      Overrides:
      getTools in class ModelInterceptor
      Returns:
      List of tools provided by this interceptor, empty list by default
    • getName

      public String getName()
    • 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