Class RetryMiddleware
java.lang.Object
com.google.genkit.ai.middleware.BaseGenerationMiddleware
com.google.genkit.plugins.middleware.RetryMiddleware
- All Implemented Interfaces:
GenerationMiddleware
Retries a failed model call with exponential backoff.
Wraps the wrapModel hook: if the underlying model call throws, it is retried up to
RetryMiddleware.Options.maxRetries times, sleeping initialDelayMs before the first retry and
multiplying the delay by backoffFactor (capped at maxDelayMs) after each attempt.
Mirrors the JS retry middleware in @genkit-ai/middleware and the Go
Retry middleware.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionname()Returns the middleware's unique identifier.Returns a fresh instance for eachgenerate()call, enabling per-invocation state.wrapModel(ActionContext ctx, ModelParams params, ModelNext next) Wraps each model API call.Methods inherited from class com.google.genkit.ai.middleware.BaseGenerationMiddleware
tools, wrapGenerate, wrapTool
-
Constructor Details
-
RetryMiddleware
-
-
Method Details
-
name
Description copied from interface:GenerationMiddlewareReturns the middleware's unique identifier. -
newInstance
Description copied from interface:GenerationMiddlewareReturns a fresh instance for eachgenerate()call, enabling per-invocation state.Stable state (e.g., API keys, configuration) should be preserved. Per-request state (e.g., counters) should be reset.
-
wrapModel
public ModelResponse wrapModel(ActionContext ctx, ModelParams params, ModelNext next) throws GenkitException Description copied from interface:GenerationMiddlewareWraps each model API call.- Specified by:
wrapModelin interfaceGenerationMiddleware- Overrides:
wrapModelin classBaseGenerationMiddleware- Parameters:
ctx- the action contextparams- the model parameters including the requestnext- the next function in the chain- Returns:
- the model response
- Throws:
GenkitException- if processing fails
-