Package com.google.genkit.ai.middleware
Interface MiddlewarePlugin
- All Known Implementing Classes:
GenerationMiddlewarePlugin
public interface MiddlewarePlugin
Implemented by plugins that share reusable generation middleware.
This is how Middleware V2 is shared as plugins, mirroring the JS SDK's
GenkitPluginV2.middleware() and the Go SDK's MiddlewarePlugin.Middlewares(). A plugin
implements both Plugin (for its actions, if any) and this
interface; during Genkit initialization each returned descriptor is registered into the
registry's "middleware" value bucket, making it discoverable in the Genkit Dev UI and
resolvable by name at generate time.
Example:
public class MyMiddlewarePlugin implements Plugin, MiddlewarePlugin {
public List<GenerationMiddlewareDesc> middlewares(Registry registry) {
return List.of(
GenerationMiddlewares.define("retry", "Retry failed model calls",
RetryOptions.class, RetryMiddleware::new));
}
// ...Plugin methods...
}
-
Method Summary
Modifier and TypeMethodDescriptionmiddlewares(Registry registry) Returns the generation middleware this plugin provides.
-
Method Details
-
middlewares
Returns the generation middleware this plugin provides. Called once duringGenkitinitialization.- Parameters:
registry- the Genkit registry, for middleware that needs to resolve dependencies (e.g. a fallback middleware that runs other models)- Returns:
- the middleware descriptors to register (may be empty)
-