toolops Design Notes¶
Overview¶
toolops provides cross-cutting operational concerns for tool execution:
- observe: tracing, metrics, structured logging
- cache: deterministic caching with TTL policy
- auth: authentication + authorization primitives
- health: health checks and probe handlers
- resilience: retries, timeouts, circuit breakers, rate limits, bulkheads
observe Package¶
Design Decisions¶
- Observer abstraction: Wraps OpenTelemetry tracer/meter/logger into one object.
- Middleware wrapping:
Middlewaredecorates anExecuteFuncfor execution telemetry. - No execution dependency: observe only instruments; it does not call tools.
Contracts¶
- Observer must be shut down to flush exporters.
- Middleware wraps an
ExecuteFuncand records telemetry per call. - ToolMeta drives span naming (
tool.exec.<namespace>.<name>).
cache Package¶
Design Decisions¶
- Deterministic keys: Inputs are canonicalized and hashed (SHA‑256).
- Explicit policy: TTL and unsafe tag handling are policy‑driven.
- No caching on error: executor failures are never cached.
Policy Semantics¶
- DefaultTTL controls caching enablement (0 disables).
- MaxTTL clamps overrides.
- AllowUnsafe gates caching for unsafe-tagged tools.
auth Package¶
Design Decisions¶
- Authenticator vs Authorizer: Authentication returns identities; authorization enforces permissions.
- RBAC support: Simple RBAC authorizer with role inheritance.
- Protocol-agnostic: Works with any transport layer.
Contracts¶
- Authenticator returns
AuthResultfor success/failure; errors indicate internal failure. - Authorizer returns an
AuthzErrorwhen denied.
health Package¶
Design Decisions¶
- Checker interface: Components implement
Check(ctx)returningResult. - Aggregator: Multiple checkers can be composed into liveness/readiness endpoints.
- HTTP handlers: Built-in probe handlers for orchestration platforms.
Contracts¶
- Checker returns a
Resultwith status + details. - Aggregator combines results and computes overall status.
resilience Package¶
Design Decisions¶
- Composable executor: Pattern chain order is deterministic and documented.
- Minimal state: Each pattern is isolated and configurable.
- Context-aware: All patterns honor cancellation and deadlines.
Execution Order¶
The executor composes patterns in this order: 1. Rate limiter 2. Bulkhead 3. Circuit breaker 4. Retry 5. Timeout
Trade-offs¶
- No built-in storage: cache is in-memory by default; external backends are explicit.
- No implicit telemetry: callers must wire observe middleware to execution functions.
- Fail-fast execution: resilience executor stops on first failure after pattern handling.