AAnvio
Runtimes & Model Routing

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 local loop, 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 local runtime (or the routing layer above it) needs one: Anthropic, OpenAI, Gemini, and 14 OpenAI-compatible APIs, selected and retried by the ModelRouter.

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

Rendering diagram…

Two independent fallback mechanisms are involved:

  1. Runtime chain fallback (packages/runtimes/src/runtime-fallback-chain.ts) — walks provider → fallbacks → local when 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.
  2. Model provider fallback (packages/models/src/fallback-chain.ts, walkFallbackChain) — only relevant once execution reaches the local runtime or ModelRouter.chat() directly. Retries on 429, timeout, 503/502 by default.

Runtime providers

IDClassPackage pathWhat it does
localLocalRuntimeProviderpackages/runtimes/src/local/Delegates straight to Anvio's own AgentRuntime (context assembly, tool loop, model calls). Always configured.
claude-codeClaudeCodeRuntimeProviderpackages/runtimes/src/claude-code/Runs Anthropic's @anthropic-ai/claude-agent-sdk with OAuth (Pro/Max subscription).
cursorCursorRuntimeProviderpackages/runtimes/src/cursor/Cursor agent via ACP or agent -p CLI.
codexCodexRuntimeProviderpackages/runtimes/src/codex/OpenAI Codex CLI (codex exec).
antigravityAntigravityRuntimeProviderpackages/runtimes/src/antigravity/Google Antigravity CLI (agy -p).
dockerDockerRuntimeProviderpackages/runtimes/src/docker/Shells out to docker; delegates actual execution to CodeExecutor.
sshSshRuntimeProviderpackages/runtimes/src/ssh/Remote shell exec over SSH.
singularitySingularityRuntimeProviderpackages/runtimes/src/singularity/Local HPC container exec via singularity/apptainer binary.
daytonaDaytonaRuntimeProviderpackages/runtimes/src/remote/Daytona serverless sandbox (mock + HTTP exec).
modalModalRuntimeProviderpackages/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 provider
Edit on GitHub

Last updated on

On this page