Overview
Middleware in Agenite allows you to intercept and modify agent behavior at various stages of execution. Middleware can be used for logging, error handling, state management, and more.Interface
- Intercept and modify values yielded by the generator
- Process the final return value
- Handle next values passed into the generator
- Access the execution context
Middleware Types
Using middleware with an agent
Custom middleware examples
Logging middleware
Metrics middleware
State persistence middleware
Best practices
- Order matters: Middlewares execute in the order specified in the array, with each wrapping the ones that come after it
- Keep it focused: Each middleware should have a single responsibility
- Error handling: Implement proper error handling within the middleware
- Performance: Be mindful of performance impacts, especially in middleware that runs for every yield
- Typing: Use proper TypeScript types for your custom middleware
Next steps
- Learn about providers
- See examples
- Read about core concepts