Class ToolEmulatorInterceptor

java.lang.Object
com.alibaba.cloud.ai.graph.agent.interceptor.ToolInterceptor
com.alibaba.cloud.ai.graph.agent.interceptor.toolemulator.ToolEmulatorInterceptor
All Implemented Interfaces:
Interceptor

public class ToolEmulatorInterceptor extends ToolInterceptor
Tool interceptor that emulates specified tools using an LLM instead of executing them. This interceptor allows selective emulation of tools for testing purposes. By default (when tools=null), all tools are emulated. You can specify which tools to emulate by passing a list of tool names. Example: // Emulate all tools (default behavior) ToolEmulatorInterceptor emulator = ToolEmulatorInterceptor.builder() .model(chatModel) .build(); // Emulate specific tools by name ToolEmulatorInterceptor emulator = ToolEmulatorInterceptor.builder() .model(chatModel) .addTool("get_weather") .addTool("get_user_location") .build(); // Emulate all except specified tools ToolEmulatorInterceptor emulator = ToolEmulatorInterceptor.builder() .model(chatModel) .emulateAllTools(false) // Only emulate specified tools .addTool("expensive_api") .build();
  • Method Details

    • builder

      public static ToolEmulatorInterceptor.Builder builder()
    • getName

      public String getName()
    • interceptToolCall

      public ToolCallResponse interceptToolCall(ToolCallRequest request, ToolCallHandler handler)
      Description copied from class: ToolInterceptor
      Wrap a tool 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 - Add caching, logging, monitoring, etc.
      Specified by:
      interceptToolCall in class ToolInterceptor
      Parameters:
      request - The tool call request
      handler - The next handler in the chain (or base handler)
      Returns:
      The tool call response