Announcing Genkit Middleware: Intercept, extend, and harden your agentic apps
Summary
Genkit, an open-source framework for building AI-powered and agentic applications, has introduced a new middleware system. This system provides composable hooks that intercept generation calls, including the tool execution loop, to inject custom behaviors for reliability, human approval, and observability. Middleware operates at three layers: Generate (per tool-loop iteration), Model (per model API call), and Tool (per tool execution). Genkit offers pre-built middleware for common use cases such as Retry for transient errors, Fallback to alternative models, Tool Approval for human-in-the-loop confirmation, Skills for injecting prompt content, and Filesystem for scoped model access. Developers can also create custom middleware to enforce specific application rules, like content filtering, and inspect their execution via the Genkit Developer UI.
Key takeaway
For AI Engineers building production-ready agentic applications, Genkit's new middleware system offers critical capabilities to harden your deployments. You should explore integrating pre-built middleware like Retry and Fallback for enhanced reliability, and consider developing custom middleware for application-specific logic such as content filtering or data governance. This approach centralizes control and improves the maintainability of complex AI workflows.
Key insights
Genkit middleware enhances agentic AI applications with composable hooks for reliability, control, and custom logic.
Principles
- Composable hooks enable custom behavior injection.
- Middleware operates at distinct layers of the tool loop.
- Order of middleware in a stack matters.
Method
Implement custom middleware by providing a name and a factory function that returns specific hooks (WrapModel, WrapGenerate, WrapTool) to intercept and modify AI generation calls.
In practice
- Use Retry middleware for model API call reliability.
- Implement Tool Approval for human-in-the-loop actions.
- Develop custom content filters for model outputs.
Topics
- Genkit Framework
- AI Agentic Applications
- Middleware System
- Tool Execution Loop
- Reliability Patterns
Code references
Best for: AI Engineer, Machine Learning Engineer, Software Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Google Developers Blog - AI.