feat(py): generate middleware#5253
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a robust middleware system for Genkit, enabling interception and modification of model generation, API calls, and tool executions. It introduces the genkit-plugin-middleware package, providing standard middleware for retries, fallbacks, tool approval, skills, and filesystem operations. Core generation logic was refactored to handle middleware normalization and per-call scoping. Feedback identifies redundant model copies in the asynchronous generation methods and a design conflict between validation tests and the normalization implementation. Furthermore, the reviewer noted blocking synchronous I/O in asynchronous tool implementations and issues with the jitter calculation in the retry middleware that could cause delays to exceed configured maximums.
There was a problem hiding this comment.
Code Review
This pull request introduces a new middleware architecture for the Genkit framework, replacing the previous functional middleware approach with a class-based BaseMiddleware system. It adds support for middleware registration via MiddlewareDesc and MiddlewareRef, allowing for more flexible, configuration-driven middleware usage. The changes include the addition of a new genkit-plugin-middleware package containing implementations for Retry, Fallback, ToolApproval, Skills, and Filesystem, along with updates to the core engine to support these new middleware hooks and tool execution flows. No review comments were provided for this pull request.
Description here... Help the reviewer by:
Checklist (if applicable):