Overview
How Anvio separates runtime providers (who executes the agent) from model providers (which LLM answers), and how both fall back on failure.
4 min read
Anvio makes a hard distinction between two layers, both configurable independently per agent:
- Runtime provider — who runs the agent loop: Anvio's own
localloop, or a vendor-native coding agent CLI (Claude Code, Cursor, Codex, Antigravity), or a remote/sandboxed executor (Docker, SSH, Daytona, Modal, Singularity). - Model provider — which LLM answers a chat request when the
localruntime (or the routing layer above it) needs one: Anthropic, OpenAI, Gemini, and 14 OpenAI-compatible APIs, selected and retried by theModelRouter.
This split exists so that "run this agent through Claude Code on my Pro subscription" and "route this chat call to whichever provider is cheapest" are two separate, composable decisions — see ADR 0009 for the reasoning.
Runtime provider dispatch and fallback
Two independent fallback mechanisms are involved:
- Runtime chain fallback (
packages/runtimes/src/runtime-fallback-chain.ts) — walksprovider → fallbacks → localwhen a runtime isn't configured, or retries the next runtime when an auth error occurs mid-run (OAuth expired, 401, "login required"). Non-auth errors fail immediately, no runtime retry. - Model provider fallback (
packages/models/src/fallback-chain.ts,walkFallbackChain) — only relevant once execution reaches thelocalruntime orModelRouter.chat()directly. Retries on429, timeout,503/502by default.
Runtime providers
| ID | Class | Package path | What it does |
|---|---|---|---|
local | LocalRuntimeProvider | packages/runtimes/src/local/ | Delegates straight to Anvio's own AgentRuntime (context assembly, tool loop, model calls). Always configured. |
claude-code | ClaudeCodeRuntimeProvider | packages/runtimes/src/claude-code/ | Runs Anthropic's @anthropic-ai/claude-agent-sdk with OAuth (Pro/Max subscription). |
cursor | CursorRuntimeProvider | packages/runtimes/src/cursor/ | Cursor agent via ACP or agent -p CLI. |
codex | CodexRuntimeProvider | packages/runtimes/src/codex/ | OpenAI Codex CLI (codex exec). |
antigravity | AntigravityRuntimeProvider | packages/runtimes/src/antigravity/ | Google Antigravity CLI (agy -p). |
docker | DockerRuntimeProvider | packages/runtimes/src/docker/ | Shells out to docker; delegates actual execution to CodeExecutor. |
ssh | SshRuntimeProvider | packages/runtimes/src/ssh/ | Remote shell exec over SSH. |
singularity | SingularityRuntimeProvider | packages/runtimes/src/singularity/ | Local HPC container exec via singularity/apptainer binary. |
daytona | DaytonaRuntimeProvider | packages/runtimes/src/remote/ | Daytona serverless sandbox (mock + HTTP exec). |
modal | ModalRuntimeProvider | packages/runtimes/src/remote/ | Modal serverless sandbox (mock + HTTP exec). |
RuntimeFactory (packages/runtimes/src/runtime-factory.ts) instantiates every provider up front and exposes resolveForAgent(), which walks the chain built by buildAgentRuntimeChain() and picks the first provider whose isConfigured() returns true, defaulting to local if nothing else matches.
Only local, cursor, claude-code, codex, antigravity are valid values for an agent's spec.runtime.provider — ssh/docker/daytona/modal/singularity are invoked directly via anvio runtime exec <id>, not bound to an agent definition.
Model providers
18 provider IDs total: 2 native SDK integrations (anthropic, gemini) + 14 OpenAI-compatible APIs sharing one adapter (openai, openrouter, deepseek, groq, mistral, together, xai, fireworks, moonshot, cerebras, sambanova, perplexity, cohere, huggingface, ollama) + custom for any other OpenAI-compatible endpoint. Full table: Model Router.
Configuring per agent
# workspace/agents/architect.yaml
spec:
runtime:
provider: claude-code
fallbacks: [cursor, codex, local] # chain A -> B -> C -> local
model:
provider: anthropic # used only if the chain reaches `local`
model: claude-sonnet-4-20250514
routing: coding # optional: use ModelRouter route instead of a fixed providerLast updated on