Class ToolSelectionInterceptor

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

public class ToolSelectionInterceptor extends ModelInterceptor
Uses an LLM to select relevant tools before calling the main model. When an agent has many tools available, this interceptor filters them down to only the most relevant ones for the user's query. This reduces token usage and helps the main model focus on the right tools. Example: ToolSelectionInterceptor interceptor = ToolSelectionInterceptor.builder() .selectionModel(gpt4oMini) .maxTools(3) .build();
  • Method Details

    • builder

      public static ToolSelectionInterceptor.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
    • getName

      public String getName()