类 ExecutionConfig

java.lang.Object
io.agentscope.core.model.ExecutionConfig

public class ExecutionConfig extends Object
Unified execution configuration for timeout and retry behavior.

This class replaces the previous TimeoutConfig and RetryConfig classes, providing a single unified configuration for controlling execution behavior of both model API calls and tool executions.

Use the builder pattern to construct instances. All fields are optional and nullable.

Standard Defaults

  • MODEL_DEFAULTS: 5 minutes timeout, 3 retry attempts with exponential backoff
  • TOOL_DEFAULTS: 5 minutes timeout, no retry (1 attempt only)

Configuration Merging

Use mergeConfigs(ExecutionConfig, ExecutionConfig) to combine configurations with parameter-by-parameter precedence. This allows layering configs from different sources:


 // Priority: per-request > agent-level > component-defaults > system-defaults
 ExecutionConfig effective = ExecutionConfig.mergeConfigs(
     perRequestConfig,
     ExecutionConfig.mergeConfigs(agentConfig, ExecutionConfig.MODEL_DEFAULTS)
 );
 
  • 字段详细资料

    • RETRYABLE_ERRORS

      public static final Predicate<Throwable> RETRYABLE_ERRORS
      Predicate that determines if an error should be retried.

      Retryable errors include:

      • HTTP 429 (Rate Limiting)
      • HTTP 5xx (Server errors)
      • Timeout errors
      • Network/IO errors

      Non-retryable errors include:

      • HTTP 400 (Bad Request) - parameter validation failures
      • HTTP 401/403 (Authentication/Authorization errors)
      • Other 4xx client errors
    • MODEL_DEFAULTS

      public static final ExecutionConfig MODEL_DEFAULTS
      Standard defaults for model API calls.
      • Timeout: 5 minutes
      • Max attempts: 3 (initial + 2 retries)
      • Initial backoff: 2 seconds
      • Max backoff: 30 seconds
      • Backoff multiplier: 2.0 (exponential)
      • Retry on: retryable errors only (429, 5xx, timeout, network errors)

      Note: The backoff times are set higher (2s initial, 30s max) to better handle rate limiting (HTTP 429) from model providers during high-concurrency scenarios.

    • TOOL_DEFAULTS

      public static final ExecutionConfig TOOL_DEFAULTS
      Standard defaults for tool executions.
      • Timeout: 5 minutes
      • Max attempts: 1 (no retry)
  • 方法详细资料

    • getTimeout

      public Duration getTimeout()
      Gets the timeout duration.
      返回:
      the timeout duration, or null if not set
    • getMaxAttempts

      public Integer getMaxAttempts()
      Gets the maximum number of attempts.
      返回:
      the max attempts (including initial attempt), or null if not set
    • getInitialBackoff

      public Duration getInitialBackoff()
      Gets the initial backoff duration.
      返回:
      the initial backoff duration, or null if not set
    • getMaxBackoff

      public Duration getMaxBackoff()
      Gets the maximum backoff duration.
      返回:
      the max backoff duration, or null if not set
    • getBackoffMultiplier

      public Double getBackoffMultiplier()
      Gets the backoff multiplier.
      返回:
      the backoff multiplier, or null if not set
    • getRetryOn

      public Predicate<Throwable> getRetryOn()
      Gets the retry predicate.
      返回:
      the predicate to determine if an error should be retried, or null if not set
    • builder

      public static ExecutionConfig.Builder builder()
      Creates a new builder for ExecutionConfig.
      返回:
      a new Builder instance
    • mergeConfigs

      public static ExecutionConfig mergeConfigs(ExecutionConfig primary, ExecutionConfig fallback)
      Merges two ExecutionConfig instances, with primary config taking precedence.

      This method performs parameter-by-parameter merging: for each parameter, if the primary value is non-null, it is used; otherwise, the fallback value is used. This allows proper layering of configs from different sources.

      Merge Behavior:

      • Each field: primary != null ? primary : fallback
      • If primary is null, returns fallback directly
      • If fallback is null, returns primary directly

      Example:

      
       ExecutionConfig defaults = ExecutionConfig.MODEL_DEFAULTS;
       ExecutionConfig agentLevel = ExecutionConfig.builder()
           .timeout(Duration.ofMinutes(2))
           .build();
      
       // Result: timeout=2min, maxAttempts=3 (from defaults), ...
       ExecutionConfig merged = ExecutionConfig.mergeConfigs(agentLevel, defaults);
       
      参数:
      primary - the primary config (higher priority)
      fallback - the fallback config (lower priority)
      返回:
      merged config, or null if both are null