Skip to content

RFC: [Go] Middleware V2#4422

Draft
apascal07 wants to merge 1 commit intomainfrom
ap/go-middleware-design
Draft

RFC: [Go] Middleware V2#4422
apascal07 wants to merge 1 commit intomainfrom
ap/go-middleware-design

Conversation

@apascal07
Copy link
Collaborator

@apascal07 apascal07 commented Feb 3, 2026

@github-actions github-actions bot added the docs Improvements or additions to documentation label Feb 3, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @apascal07, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This RFC outlines a significant redesign of the middleware system for Genkit Go, moving from a limited model-only wrapper to a comprehensive framework. The new design introduces a flexible Middleware interface with hooks for various stages of AI generation, including tool execution and overall generation flow, allowing for per-invocation state and robust plugin integration. This change aims to enhance extensibility and control over AI generation processes, with a clear path for deprecating older middleware implementations.

Highlights

  • New Middleware Interface: Introduced a new Middleware interface with Generate, Model, and Tool hooks, providing comprehensive control over the AI generation lifecycle, including tool execution and overall generation flow.
  • Per-Invocation State: The Middleware interface now includes a New() method, enabling the creation of fresh middleware instances for each ai.Generate() call, allowing for per-invocation state management.
  • Base Implementation for Convenience: A BaseMiddleware struct is provided to offer default pass-through behavior for hooks, simplifying the implementation of custom middleware.
  • Enhanced Registration and Configuration: New mechanisms like DefineMiddlewareFor and NewMiddlewareFor facilitate middleware registration, expose configuration schemas to the Dev UI, and enable dynamic configuration from JSON.
  • Plugin Integration: A MiddlewarePlugin interface has been added, allowing plugins to automatically register middleware and provide factory methods for injecting dependencies into middleware instances.
  • API and Schema Updates: The API and associated Zod and Go schemas have been updated to support middleware references and their configurations within GenerateActionOptions, ensuring seamless integration with the Dev UI.
  • Reflection API Endpoint: A new reflection API endpoint, GET /api/middlewares, has been introduced to list all registered middleware, aiding in discovery and dynamic UI generation.
  • Deprecation Plan: Existing core.Middleware and ai.ModelMiddleware types are slated for deprecation, with internal middleware being refactored to use the new design and a plan for complete removal in a future major version.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • docs/go-middleware-design.md
    • This new document details the proposed Middleware V2 design for Genkit Go, covering its core interface, usage, registration, plugin integration, API schema, and deprecation strategy for existing middleware.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive design for a new middleware system in Genkit Go, addressing the limitations of the existing ModelMiddleware. The document clearly outlines the core interface, base implementation, usage patterns, and integration points for plugins and the API. The examples, especially the RetryMiddleware and TracingMiddleware, effectively demonstrate how to implement and use the new system, including handling per-invocation state and injected dependencies. The deprecation plan for older middleware types is also well-defined. Overall, this is a well-thought-out and clearly documented design that significantly enhances the flexibility and power of middleware in Genkit Go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant