Class ModelFallbackInterceptor

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

public class ModelFallbackInterceptor extends ModelInterceptor
Automatic fallback to alternative models on errors. Retries failed model calls with alternative models in sequence until success or all models exhausted. Example: ModelFallbackInterceptor interceptor = ModelFallbackInterceptor.builder() .addFallbackModel(gpt4oMiniModel) .addFallbackModel(claude35SonnetModel) .build();
  • Method Details

    • builder

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