cgn-router — KV-aware request router

OpenAI-compatible HTTP gateway with BLAKE3 prefix scoring, per-tenant admission, optional cascade and disaggregated dispatch, and policy loaded from etcd without blocking the hot path.

Overview

cgn-router is the only binary that speaks HTTP to clients. It authenticates (cgn-auth), applies rate limits (cgn-ratelimit), hashes the prompt into sequence-chained BLAKE3 digests, scores every healthy agent that hosts the requested model, picks the best node, and opens an Agent.Generate gRPC stream to cgn-agent. Streaming responses are re-encoded as OpenAI SSE chunks.

For background on the score function and etcd keys, read Routing architecture and the topology overview.

Features

  • Four-term routing score: KV prefix overlap, load, power (from metrics), and capacity; weights hot-reloaded from etcd via lock-free arc_swap
  • Sequence-chained BLAKE3 digests over ~64-token blocks (positional correctness for interleaved prefixes)
  • Per-(model, role) admission with configurable queue caps and TTFT SLO hints
  • Optional cascade (SLM → larger model on low confidence) and disaggregated routing (prefill vs decode pools)
  • Cross-cluster federation hooks (forwarding path documented in Protocols)
  • API key and OIDC auth; optional mTLS on gRPC admin paths

Architecture

Client → :8080 HTTP → auth → rate limit → BLAKE3 prefix hash → score candidates → pick agent → gRPC :7070 (mTLS) → cgn-agent → SSE stream.

Admin and Prometheus scrape live on listen_admin (default 127.0.0.1:9091): /healthz, /readyz, /metrics.

Configuration (highlights)

Defaults from configs/cognitora.toml.example:

KeyTypeDefaultDescription
[router].listen_httpstring0.0.0.0:8080OpenAI HTTP API
[router].listen_grpcstring0.0.0.0:7070Internal RPC to agents
[router].listen_adminstring127.0.0.1:9091Health + Prometheus
[router.score_weights].*f64kv 0.55, load 0.25, power 0.10, capacity 0.10Routing weights
[router.admission].*u32 / msmax_queue, ttft_slo_ms, queue_timeout_msBack-pressure
[router.rate_limit].*bool / u32disabled by defaultPer-subject RPS
[router.cascade].*bool / f64off by defaultMulti-model escalation
[router.disagg].*bool / u32off by defaultPrefill/decode split

[auth], [cluster], and [models.<name>] sections are shared with other binaries; see Configuration reference.

Example

[cluster]
name     = "demo"
data_dir = "/var/lib/cognitora"
etcd     = ["127.0.0.1:2379"]

[security]
require_mtls = true

[auth]
enabled       = true
api_keys_file = "/etc/cognitora/keys.txt"

[router]
listen_http  = "0.0.0.0:8080"
listen_grpc  = "0.0.0.0:7070"
listen_admin = "127.0.0.1:9091"

[router.score_weights]
kv       = 0.55
load     = 0.25
power    = 0.10
capacity = 0.10

[models."llama3-70b"]
hf_repo = "meta-llama/Meta-Llama-3-70B-Instruct"
tp      = 4

Dependencies

  • etcd — node registry and routing policy
  • cgn-agent — gRPC streaming backends
  • cgn-metrics (optional but recommended) — power term for scoring

Operational targets

Latency budgets and behaviour are summarized in SLOs. Symptom-led debugging: Runbook: Router down.

Related documentation

Source: rust/services/cgn-router/