Skip to content

feat(js/ai): implemented generate middleware#5043

Merged
pavelgj merged 21 commits intopj/gm-refactor-generate-api-into-aifrom
pj/gm-impl-middleware
Apr 10, 2026
Merged

feat(js/ai): implemented generate middleware#5043
pavelgj merged 21 commits intopj/gm-refactor-generate-api-into-aifrom
pj/gm-impl-middleware

Conversation

@pavelgj
Copy link
Copy Markdown
Member

@pavelgj pavelgj commented Apr 1, 2026

Checklist (if applicable):

Copy link
Copy Markdown
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 middleware system for Genkit, allowing developers to intercept and modify the high-level generation process, model calls, and tool executions. It includes new utilities for defining and normalizing middleware, along with integration into the core registry and plugin architecture. Feedback indicates a regression in error handling within resolveToolRequest where the removal of a try-catch block leaves resumed and restarted tool calls unprotected against interrupts, and suggests simplifying redundant logic in resolveToolRequests once error handling is centralized.

@pavelgj
Copy link
Copy Markdown
Member Author

pavelgj commented Apr 1, 2026

/gemini review

Copy link
Copy Markdown
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 new middleware system for Genkit, allowing developers to intercept and modify the top-level generate action, underlying model execution, and individual tool calls. It includes the addition of a generateMiddleware factory, a normalization process for different middleware representations, and updates to the core generation logic to support these hooks. One piece of feedback was provided regarding the restoration of a comment explaining a specific error check for better maintainability.

@pavelgj
Copy link
Copy Markdown
Member Author

pavelgj commented Apr 2, 2026

/gemini review

Copy link
Copy Markdown
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 new middleware system for Genkit's generate action, allowing for interceptors at the generate, model, and tool execution levels. It includes a new normalizeMiddleware utility to handle various middleware formats and integrates this system into the generation pipeline. I have reviewed the proposed changes and identified an issue with the tool middleware hook signature where allowing a void return type could lead to inconsistent conversation states.

Copy link
Copy Markdown

@ahamedjobayer081-spec ahamedjobayer081-spec left a comment

Choose a reason for hiding this comment

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

Fixes #Fixes #5043

@pavelgj
Copy link
Copy Markdown
Member Author

pavelgj commented Apr 2, 2026

/gemini review

Copy link
Copy Markdown
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 middleware system for Genkit AI, enabling interception and modification of generation, model, and tool execution. It includes new interfaces, normalization logic for various middleware formats, and updates to the tool resolution process to support middleware-injected tools. Feedback highlights a bug in resolveRestartedTools where tools injected by middleware are overlooked during resolution, which could lead to failures for interrupted tools.

@github-actions github-actions bot added docs Improvements or additions to documentation config labels Apr 10, 2026
@pavelgj pavelgj merged commit 05e924d into pj/gm-refactor-generate-api-into-ai Apr 10, 2026
17 checks passed
@pavelgj pavelgj deleted the pj/gm-impl-middleware branch April 10, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation go js python Python tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants