Core APIs
Middleware APIs
Reference for middleware in Agenite
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
The middleware wraps the agent’s execution generator, allowing you to:
- 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