Skip to content

RFC: [Go] Middleware V2#4422

Draft
apascal07 wants to merge 4 commits intomainfrom
ap/go-middleware-design
Draft

RFC: [Go] Middleware V2#4422
apascal07 wants to merge 4 commits 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.

yesudeep added a commit that referenced this pull request Feb 9, 2026
…rity audit

- Add 7 new gaps (G38-G44) for Middleware V2, Bidi Action/Flow/Model,
  Agent primitive, Plugin V2, and Reflection API V2
- Mark middleware gaps G1-G3, G12-G16 as PAUSED (blocked on upstream
  JS #4515 and Go #4422 Middleware V2 RFCs)
- Mark G19 (Model API V2) as SUPERSEDED by G38 + G41
- Add deep-dive sections §8l-8p covering all 5 active RFC designs
- Update dependency graph: critical path now G38→G2→G1→G3 (4 levels)
- Restructure phased roadmap: Phase 1 (unblocked), Phase 2-3 (paused),
  Phase 4 (bidi/agent, blocked), Phase 5 (integration), Phase 6 (deferred)
- Update §5g cross-SDK gaps table with new primitives
- Update §9b status tracker and §9c dependency matrix
- Update summary metrics: 36 total gaps, 8 paused, 6 upstream-blocked

Co-authored-by: Cursor <cursoragent@cursor.com>
yesudeep added a commit that referenced this pull request Feb 11, 2026
… and merge order

Comprehensive update reflecting current state of all merged and open PRs:

Merged PRs reflected:
- #4511 (G5+G6: span_id + X-Genkit-Span-Id) → marked Done
- #4507+#4508 (G11: CHANGELOG.md) → marked Done
- #4509 (plugin test coverage uplift) → marked Done
- #4505 (PARITY_AUDIT.md baseline) → marked Done
- #4488 (sample naming, py.typed, check_consistency) → marked Done

Open PRs tracked:
- #4516 (G1+G2: model middleware storage)
- #4514 (Transfer-Encoding fix)
- #4513 (G18: multipart tools)
- #4512 (G20-G22: constructor parity)
- #4510 (G3+G12-G16: middleware functions)
- #4504 (Checks plugin)
- #4495, #4494, #4401 (bug fixes + reflection v2)

New content:
- Middleware Taxonomy section with 4-layer diagram
- Decision guide for which middleware layer to use
- G38 gap (auto-wiring via get_model_middleware)
- PR merge order graph with file conflict matrix
- Updated summary metrics and phase tables

fix: address review comments — fix G1/G2 status consistency, middleware level count, #4514 merged

docs(py): update PARITY_AUDIT.md — mark #4494 and #4514 merged, add #4518 Cohere

Update PR status tracking:
- #4494 (RedactedSpan fix): marked merged
- #4514 (Transfer-Encoding fix): marked merged
- #4518 (Cohere provider plugin): added as open PR
- Updated dependency chain, summary metrics, and open PR counts

docs(py): update PARITY_AUDIT.md — add #4519 (Core fix)

docs(py): update PARITY_AUDIT.md with latest merged PR status

Rationale: Several PRs have merged since the last update. This
syncs the document with the current state of all PRs.

Changes:
- Mark #4495, #4518, #4520 as merged in all tables
- Move #4495, #4518 from INDEPENDENT to MERGED in dependency chain
- Add #4520 (converter extraction) to merged list
- Update summary metrics: 6 open PRs (down from 8)
- Simplify Layer 3 deps since #4495 is now merged

docs(py): add issue tracker analysis, dependency graph, model conformance roadmap, and sample flow test plan

Rationale:
Comprehensive update to PARITY_AUDIT.md with 5 new sections (§12–§16) covering:
- Cross-SDK issue tracker analysis verified against Python source code
- Dependency-aware reverse topological sort roadmap for prioritized fixes
- Model conformance testing roadmap with provider parity matrix
- Sample flow test plan with optimal execution order for error detection

Changes:
- §12: Fixability assessment of 9 'likely' issues with code-level verdicts
- §13: Dependency graph (W1–W14), file conflict matrix, PR manifest with
  regression test specifications, sprint-based execution plan
- §14: Model conformance roadmap (Phases 0–4), plugin parity matrix,
  conformance PR mapping, JS-only plugin gaps
- §15: Combined roadmap unifying parity gaps, issue fixes, and conformance
- §16: Sample flow test plan with 5-phase error detection priority pyramid,
  36 samples ordered by feature coverage, quick-start commands, and env
  var reference table

docs(py): add active RFC redesigns (Middleware V2, Bidi, Agent) to parity audit

- Add 7 new gaps (G38-G44) for Middleware V2, Bidi Action/Flow/Model,
  Agent primitive, Plugin V2, and Reflection API V2
- Mark middleware gaps G1-G3, G12-G16 as PAUSED (blocked on upstream
  JS #4515 and Go #4422 Middleware V2 RFCs)
- Mark G19 (Model API V2) as SUPERSEDED by G38 + G41
- Add deep-dive sections §8l-8p covering all 5 active RFC designs
- Update dependency graph: critical path now G38→G2→G1→G3 (4 levels)
- Restructure phased roadmap: Phase 1 (unblocked), Phase 2-3 (paused),
  Phase 4 (bidi/agent, blocked), Phase 5 (integration), Phase 6 (deferred)
- Update §5g cross-SDK gaps table with new primitives
- Update §9b status tracker and §9c dependency matrix
- Update summary metrics: 36 total gaps, 8 paused, 6 upstream-blocked

docs(py): update PARITY_AUDIT.md PR status to 2026-02-11

Comprehensive status update reflecting 23 PRs merged since last
update (2026-02-09), 3 PRs closed/superseded, and 11 currently
open PRs including releasekit tooling, dotprompt fixes, and CI
workflow migration.

Key changes:
- §14f: Checks plugin marked as merged (#4504)
- §15b: Split into Recently Merged / Closed / Currently Open
- §15c: Updated metrics (31 merged, 11 open, 3 closed)
- Added releasekit PRs (14 merged, 3 open) as new workstream
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