Documentation
¶
Overview ¶
Package router dispatches AITasks to the right AIAgent and wraps each call with per-kind caching and per-kind rate limiting.
The router is intentionally thin: it owns no model code itself. It holds one AIAgent per AITaskKind, an optional *ai.ResultCache per kind, and an optional *ai.RateLimiter per kind. Callers (the agent worker for detect, the admin controller for analyze) pass the constructed task in; the router does cache lookup → rate check → agent.Run → cache write.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoAgent = errors.New("router: no agent registered for kind")
ErrNoAgent is returned by Run when no AIAgent is registered for the task's kind. The router never falls back across kinds.
var ErrRateLimited = errors.New("router: rate limited")
ErrRateLimited is returned by Run when the per-kind rate limiter rejected the call. Callers should treat this as a soft skip (record an "emit_quota" outcome, do not retry within the bucket).
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Agent core.AIAgent
Cache *ai.ResultCache
Rate *ai.RateLimiter
}
Entry is one wired-up (agent, cache, rate) tuple for a single kind. Cache and Rate may be nil — the router treats nil as "no cache" / "no rate cap" respectively.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router fans an AITask out to the entry for its kind.
func New ¶
func New(entries map[core.AITaskKind]Entry) *Router
New builds a Router from the given per-kind entries. nil agents are dropped so callers can pass `Entry{}` for kinds they have not wired up yet (e.g. analyze remains unset until E4).
func (*Router) Has ¶
func (r *Router) Has(kind core.AITaskKind) bool
Has reports whether an agent is registered for the given kind.
func (*Router) Run ¶
Run executes the task on the kind-specific agent, wrapped with cache + rate. Order of operations:
- Cache lookup on task.CacheKey() — hit short-circuits and returns a *AICallResult with the cached finding (UserPrompt/RawResponse left empty because the model was not called).
- Rate check — false returns ErrRateLimited without calling the agent.
- agent.Run — failure is propagated.
- Cache write on success.
Run never panics on a zero receiver; it returns ErrNoAgent instead.