Default retry policy

RetryPolicy.builder()
    .maxAttempts(3)
    .initialDelay(Duration.ofMillis(500))
    .maxDelay(Duration.ofSeconds(10))
    .multiplier(2.0)
    .retryOn(ErrorKind.TRANSIENT, ErrorKind.QUOTA, ErrorKind.TIMEOUT)
    .build();
Advertisement

Attach to a specific LLM

BaseLLM retried = new RetryingLLM(geminiLLM, retryPolicy);
agent.setModel(retried);
Advertisement

Never retry these

  • AUTH — credentials won't get better.
  • INVALID_REQUEST — the prompt is bad.
  • Anything with side effects that isn't idempotent (rare at the model layer, but real if you have caching in front).