
Routing at a glance
A request moves through these stages:- Match the requested model.
- Remove unhealthy agents.
- Match the required capability.
- Apply the policy’s static
matchfilters. - Remove agents that already failed during this policy step.
- Remove agents at their declared capacity.
- Apply live
exclude_ifgates. - Rank the remaining agents.
- Acquire a capacity slot and forward the request.
- Wait in the per-model queue when all matching agents are full.
- Move to the next fallback step when the current step is exhausted.
- Use an optional external provider fallback after all local steps fail.
Model, health, capability, previous failures, and capacity are hard constraints. They apply even when the policy does not mention them.
Default routing behavior
When you do not configure a policy file, Hivenet Router uses:- accepts agents from any region, engine, organization, or machine
- applies no optional metric gates
- ranks matching agents by current load
- uses the router’s global retry limit
max_tries.
Static matching
Thematch block filters agents by metadata reported during registration.
All non-empty fields must match. The fields use AND logic.
Match fields
All comparisons are exact and case-sensitive.
For example:
Tag matching
When a policy lists several tags, the agent must contain every listed tag. This policy:Match every agent
Use an empty match block when the step should accept any agent that passes the hard constraints:Dynamic gates
Theexclude_if block removes agents whose live metrics cross configured thresholds.
Each field must define exactly one operator:
Missing metrics
A gate is skipped when its metric is unavailable for an agent. For example, this gate:Unit conventions
Policy values use these units:
Prometheus may expose some hardware values on a
0 to 100 scale. Hivenet Router normalizes those values to 0.0 to 1.0 before evaluating routing policies.
For example, use:
Universal gates
These signals can apply to every agent when the underlying history is available.Capacity utilization
For streaming responses, Hivenet Router releases the agent capacity slot when response headers arrive, while backend generation can continue. The active-request count is therefore a routing-admission signal, not a complete count of ongoing streams.
Success rate
Smoothed latency
srtt uses Hivenet Router’s RFC 6298 smoothed round-trip-time calculation.
The value is measured in milliseconds. A new agent may not have an SRTT value until it has served requests.
Consecutive failures
Engine gates
These values are available when the backend integration reports the relevant engine metrics. vLLM provides the fullest metric set. SGLang and metrics-enabled llama.cpp provide overlapping subsets. Other integrations may leave these values unavailable.
Not every backend provides every field.
For example:
- vLLM reports cache, running, waiting, TTFT, and ITL metrics.
- SGLang reports cache, running, waiting, and TTFT metrics.
- metrics-enabled llama.cpp reports cache, running, waiting, TTFT, and ITL metrics.
- Ollama and custom engines do not currently provide these engine-specific signals.
Hardware gates
Hardware gates use the latest snapshot reported by the agent.
When an agent reports several GPUs, Hivenet Router evaluates the highest temperature, utilization, and VRAM-use value across those GPUs.
For example:
Ranking strategy
After matching and gates, Hivenet Router ranks the surviving agents. The only implemented strategy is:least-loaded ranks agents by:
Agent A ranks first.
Agents must register a positive capacity. Non-positive values are rejected before the agent joins the routing pool.
When two agents have the same ratio, Hivenet Router currently resolves the tie using the deterministic peer-ID order returned by the registry. This is stable for a given set of peer IDs, but it is not round-robin and should not be used as client affinity.
The following strategies are not implemented:
lowest-srttround-robinprefix-awarelowest-kv-cachelowest-queuebest-ttftbest-itl
Forward attempts
Each policy step has a forward-attempt budget.max_tries is zero or omitted, the step uses the router’s global value:
- backend unavailability
- backend overload or rate-limit responses
- retryable backend errors
- transport failures after connection recovery is exhausted
request_invalid, invalid_parameter, context_length_exceeded, and token_limit_exceeded stop the routing session immediately. They do not consume additional tries or advance through other local agents.
Selection failures do not consume the budget.
An agent that fails a forward attempt is excluded from further attempts within the same policy step.
When the budget is exhausted, Hivenet Router advances to the next fallback step.
Connection-level recovery
Router-agent traffic uses a persistent connection initiated by the agent. A network interruption can leave the router with stale connection state even though the agent process is still running. Hivenet Router treats a connection-levelagent_disconnected failure differently from a backend response.
For the first connection-level failure involving one agent and request, the router:
- discards its stale peer connection state
- retries the request path without consuming the step’s
max_triesbudget
Capacity wait queue
When healthy, policy-matching agents exist but all of them are at capacity, Hivenet Router can place the request in a per-model wait queue. Defaults:
Configure the queue depth:
The queue is keyed by model. Traffic for one model does not consume another model’s queue depth.
Fallback chains
A fallback chain defines ordered local alternatives.routing_policy is always evaluated first.
Each item in fallback_chain is another complete policy step with its own:
- name
- static filters
- dynamic gates
- strategy
- retry budget
- no agent is registered for the requested model
- all registered agents are unhealthy
- no agent matches the required capability
- no agent passes the static filters
- every remaining agent violates a dynamic gate
- matching agents stay at capacity until the queue is full or times out
- application-level forward failures exhaust
max_tries
Provider fallback
A policy can define one final external provider after every local step has been exhausted.openaianthropic
fallback_provider is a top-level policy field. It is not an entry inside fallback_chain.
The configured provider model replaces the model from the original client request.
For OpenAI, Hivenet Router sends an OpenAI Chat Completions request.
For Anthropic, Hivenet Router translates the supported OpenAI-style chat request into the Anthropic Messages format and converts the response back into an OpenAI-compatible chat response.
Provider fallback is non-streaming and supports only the fields handled by the provider adapter. Treat it as a final continuity mechanism rather than a transparent equivalent of every local backend feature.
See Provider fallback for the complete configuration and limitations.
Exact evaluation order
For each policy step, Hivenet Router evaluates agents in this order:- Model filter
Load agents registered for the requested model. - Health gate
Remove agents marked unhealthy or reporting an unhealthy backend. - Capability gate
Remove agents that do not serve the requiredllm,embedding, orrerankercapability. - Static match
Applyregion,engine,tags,organization,machine, andgpu_model. - Previous failures
Remove agents that already produced a forward failure in the current step. - Capacity gate
Remove agents whose active requests are greater than or equal to their declared capacity. - Dynamic gates
Apply the configuredexclude_ifthresholds. - Strategy ranking
Rank the remaining candidates withleast-loaded. - Atomic slot acquisition
Attempt to reserve one capacity slot on the selected agent. - Retry selection after a race
If another request acquired the final slot first, select again without consuming a forward try. - Wait queue
If all eligible agents are full and queueing is enabled, wait for capacity and evaluate again. - Fallback progression
Move to the next step when there are no candidates or the forward-attempt budget is exhausted. - Provider fallback
For supported language-model requests, call the configured external provider after every local step is exhausted.
Production example
- prefers production vLLM agents in
EU-France - excludes agents with high cache pressure, temperature, latency, or failure rates
- falls back to vLLM agents in any region
- uses OpenAI only after local routing is exhausted
Observe routing decisions
Policy and routing metrics are available through the router’s Prometheus endpoint. Inspect policy-related metrics:Troubleshooting
The policy does not load
Check the router logs for validation errors. Common causes include:- missing
strategy - an unknown strategy
- a misspelled
exclude_iffield - no comparison operator
- several operators on one gate
- an incomplete provider fallback
- invalid YAML indentation
least-loaded is currently accepted as a strategy.
An agent does not match
All match values are exact and case-sensitive. Compare the policy with live metadata:A metric gate does not exclude an agent
The metric may be unavailable. Inspect the agent through the routing table and confirm that the relevant engine or hardware field is present. Missing metrics skip the gate.Requests wait instead of falling back
Matching agents may exist but be at capacity. Hivenet Router waits in the per-model queue before advancing to fallback. Reduce or disable the queue when immediate fallback is more appropriate:An external provider is never called
Check that:- every local policy step was exhausted
- the request is a language-model chat request
fallback_provideris at the policy’s top level- the engine is
openaioranthropic - the corresponding environment variable is configured
- the provider model is not empty
Next steps
Policy YAML reference
Review the complete policy schema, fields, operators, and validation rules.
Fallback chains
Configure ordered local alternatives and retry budgets.
Provider fallback
Add OpenAI or Anthropic as a final fallback for chat requests.

