Class ContextEditingInterceptor

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

public class ContextEditingInterceptor extends ModelInterceptor
Context editing interceptor that clears older tool results once the conversation grows beyond a configurable token threshold. This mirrors Anthropic's context editing capabilities by managing tool result history to stay within token limits. Example: ContextEditingInterceptor interceptor = ContextEditingInterceptor.builder() .trigger(100000) .keep(3) .clearAtLeast(1000) .build();
  • Method Details

    • builder

      public static ContextEditingInterceptor.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()