Class LargeResultEvictionInterceptor

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

public class LargeResultEvictionInterceptor extends ToolInterceptor
Tool interceptor that automatically evicts large tool results to the filesystem. This interceptor monitors tool call responses and when they exceed a configurable token limit, it automatically saves the full result to a file and returns a truncated message with a pointer to the file location. Key Features (from Python's FilesystemMiddleware.wrap_tool_call): - Automatic detection of large results (>20000 tokens by default) - Eviction to /large_tool_results/ directory - Content sample (first 10 lines) included in response - Exclusion of filesystem tools (they handle their own results) - Tool call ID sanitization for safe file paths Example:
 LargeResultEvictionInterceptor interceptor = LargeResultEvictionInterceptor.builder()
     .toolTokenLimitBeforeEvict(20000)
     .excludeTools(Set.of("ls", "read_file", "write_file"))
     .build();
 
  • Method Details

    • builder

      public static LargeResultEvictionInterceptor.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