This example demonstrates the middleware system for graph, model, and tool execution.
- Logging: Logs graph execution start, completion, and errors
- Events: Publishes execution events to event bus
- Visualization: Integrates with viz server for real-time monitoring
- Caching: Caches model responses to reduce API calls
- Retry: Retries failed calls with exponential backoff
- Rate Limiting: Prevents quota exhaustion
- Token Counting: Tracks token usage for cost monitoring
- Caching: Caches tool results for deterministic tools
- Timeout: Enforces execution timeouts
- Circuit Breaker: Prevents cascading failures
- Audit: Logs all tool executions for compliance
go run main.goThe middleware system uses a layered approach:
Agent
ββ Graph Middleware (logging, events, viz)
β ββ Graph Executor
β ββ Model Middleware (cache, retry, rate limit, tokens)
β β ββ Model Executor
β ββ Tool Middleware (cache, timeout, circuit breaker, audit)
β ββ Tool Executor
Each layer can have multiple middleware composed together using the Chain function.