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 Details

    • middlewares

      List<GenerationMiddlewareDesc> middlewares(Registry registry)
      Returns the generation middleware this plugin provides. Called once during Genkit initialization.
      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)