Provider routing

ProviderRouter is a strategy interface for picking which provider to call when the runtime decides to switch (e.g. after RecoveryStep.SWITCH_PROVIDER fires). Three reference implementations ship: first-acceptable (static), rotating (round-robin), and weighted by config.

Quick example

from techrevati.runtime import (
    AgentSession, StaticProviderRouter,
)

router = StaticProviderRouter(("model-a", "model-b", "model-c"))
agent = AgentSession(
    role="writer", phase="draft",
    provider_router=router,
)

The runtime exposes the router through session.provider_router so caller code that owns the actual call can ask for a next provider on a failure recovery branch:

next_provider = session.provider_router.select(
    scenario=FailureScenario.PROVIDER_FAILURE,
    attempt=2,
    current="model-a",
    exclude=("model-already-429d",),
)

select is allowed to return None — that's the signal to escalate to the recipe's EscalationPolicy rather than continue retrying.

When to use

When NOT to use

Comparison

Router State Strategy Determinism
StaticProviderRouter stateless first non-excluded in order yes
RoundRobinProviderRouter cursor strict rotation yes, given input order
WeightedProviderRouter stateless highest weight, ties to earliest declaration yes

Anti-patterns

See also