Skip to content

Envoy AI Gateway becomes Agent Router and joins the Agentic AI Foundation

Learn more

Smart Routing in Agent Router, powered by NVIDIA NeMo Switchyard

Tetrate and NVIDIA bring NVIDIA NeMo Switchyard's per-turn model routing to Agent Router as a native Envoy extension built with Built On Envoy. It runs in process, with no extra service, sidecar, or Agent Router changes.

Smart Routing in Agent Router, powered by NVIDIA NeMo Switchyard

Today, Tetrate and NVIDIA are making smart routing powered by NVIDIA NeMo Switchyard available to Agent Router. The integration is a Built On Envoy extension, a native Rust module that runs Switchyard’s routing algorithms inside the Envoy proxies that already carry your agent traffic. You don’t run another service or sidecar, and you don’t change Agent Router.

If you want to try it right away, the switchyard extension page has a script that brings up the whole setup in a local kind cluster. Otherwise, read on for the problem it solves and how it works.

Agents don’t need the same model for every step

A coding agent working on a task makes dozens of model calls. Most of them are routine: read a file, list a directory, summarize the output of a tool. A smaller, faster model handles those steps well. Then a build fails, a tool call returns an error, or the agent starts going in circles, and that is where a frontier model earns its price.

Teams usually end up picking a single model per agent, and both choices hurt:

  • Use the most capable model for everything, and you pay frontier prices for steps that never needed it.
  • Use an efficient model for everything, and agents fail on exactly the turns that matter.

Choosing the model per turn fixes this, but the decision needs context. Whether the next step is routine depends on what happened in the previous ones: which tools ran, which ones failed, how long the agent has been stuck. And it has to happen on every request, for every agent, without asking each agent team to build their own routing logic.

That makes the gateway the right place for it. Every request already passes through it, it already knows the models and their backends, and it applies the same policy to every agent.

NVIDIA NeMo Switchyard and the Envoy extension

Switchyard is NVIDIA’s open source library for choosing which model handles each request of an agent. Its algorithms look at the conversation, including recent tool calls and their results, and pick between an efficient tier and a capable tier. The stage_router algorithm, for example, starts on the efficient model, escalates to the capable one when tool calls fail or the agent stalls, and steps back down once things recover. Because it keeps state per session, an escalation holds for as long as it is needed. Other algorithms ask a judge model which tier the task needs, or let the efficient model answer and escalate only when a verifier rejects the answer.

The switchyard extension, a joint effort between Tetrate and NVIDIA, runs those algorithms in Envoy. Clients ask for a virtual model, such as coding-auto, which is backed by a pool of models you define. For each request, the extension:

  1. Reads the request body of OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages calls.
  2. Decodes it with Switchyard’s own translation layer and runs the configured algorithm, calling a judge model when the algorithm needs one.
  3. Rewrites the model field to the model Switchyard selected, and lets the request continue.

Clients can still ask for a specific model by name: requests for any model other than a virtual one pass through untouched. Each decision is also recorded in request headers, Envoy dynamic metadata and filter state, and a switchyard_decisions counter, so you can see which model served which turn and why.

Switchyard’s core is a Rust library, so we wrote the extension in Rust to integrate with it directly: it calls Switchyard’s crates for decoding requests and running algorithms, and parses the algorithm configuration with Switchyard’s own code, so configurations stay compatible with upstream Switchyard. Switchyard also ships bindings for other languages. Its Go bindings, for example, run the same Rust core compiled to WebAssembly, which makes Switchyard usable from Go applications, including Go-based Envoy extensions.

Supported features

A virtual model is a name your clients send, plus a Switchyard route. The configuration maps target names to real models and uses Switchyard’s own algorithm format:

Two variants of the same virtual model
{
  "virtual_models": [
    {
      "name": "coding-auto",
      "match_headers": [{"name": "x-tier", "value": "free"}],
      "targets": {"efficient": "gpt-6-luna"},
      "algorithm": {"type": "passthrough", "target": "efficient"}
    },
    {
      "name": "coding-auto",
      "targets": {"efficient": "gpt-6-luna", "capable": "gpt-6.1-sol"},
      "algorithm": {"type": "auto", "capable_target": "capable", "efficient_target": "efficient"},
      "default_model": "gpt-6-luna",
      "failure_mode": "use_default"
    }
  ],
  "session": {
    "id_header": "x-switchyard-session-id",
    "fallback_id_headers": ["agent-session-id"],
    "scope_headers": ["x-tenant-id"]
  }
}

auto is an alias. Today auto points to stage_router, and a later release can point auto at a different algorithm.

Several entries can share a name. The first one whose match_headers all match wins, so a free tier or a tenant gets its own policy under one model name. failure_mode sets what happens when routing fails: route to default_model, leave the request unchanged, or reject it with a 503.

The extension supports Switchyard’s routing algorithms, both the ones that decide from the request itself and the ones that call a model:

AlgorithmBehavior
autoAlias for Switchyard’s recommended preset, which today is stage_router
stage_routerScores recent tool results and picks a tier per turn, optionally with a classifier judge
plan_executePlans on the capable target, hands off to the efficient one after the first edit or when a judge approves
randomWeighted split across targets
passthroughAlways the same target
llm_classifierA judge model picks the target
compositeA judge picks the tier at each user turn, and a stage router runs the turns within it
vgrThe efficient model answers, unless a verifier escalates the request to the capable model
advisorAn executor model answers, and an advisor model reviews some answers first
noopAnswers OK without calling a model, for smoke tests

The only Switchyard algorithm this first release of the Envoy extension doesn’t run is prefill_router, which runs a PyTorch model in process. Configurations that use it, or any other option the extension can’t honor yet, are rejected when they are loaded, with an error that names it.

The stage_router algorithm keeps per-session state, for example to hold the capable tier for a few turns after an escalation. The session ID comes from id_header, falling back to the agent-session-id header Agent Router already records, and the values of scope_headers prefix it, so two tenants never share state. Session state lives in the memory of each Envoy instance, so requests of the same session should reach the same instance. Requests from sub-agents, marked with subagent_header, can follow their own routing rules, and eligible_models_header limits the models of a request, for example to the ones in a tenant’s plan. That header must be set by a trusted filter, such as an ext_authz service, never by the client.

Judges and model calls

Algorithms such as llm_classifier, composite and vgr call a model before the request can move on. Switchyard doesn’t make those calls itself: it hands each one back to its host. The extension makes them as non-blocking Envoy HTTP callouts, so the request waits for the decision but the Envoy worker keeps serving other traffic.

Calls take one of two paths:

  • Through the gateway. With model_calls, judges and the models that vgr and advisor call go back through the gateway, usually over a loopback cluster. Agent Router then routes, authenticates, rate-limits and charges them like any other request, and forward_headers passes along the client’s credentials, tenant and session headers.
  • Directly to a judge. decision_targets and judge_targets define judges with their own Envoy cluster and API key, such as Jev or a provider’s chat API. The key is read inline or from a file and kept out of logs, and these calls never carry client headers.

This configuration asks Jev, a decision model, whether the capable model has a real advantage on the task:

Routing coding-auto with a decision judge
{
  "decision_targets": {
    "jev": {
      "format": "system_one",
      "model": "jev-latest",
      "cluster": "typesafe",
      "authority": "api.typesafe.ai",
      "api_key": {"file": "/etc/switchyard/jev-api-key"}
    }
  },
  "virtual_models": [{
    "name": "coding-auto",
    "targets": {"efficient": "gpt-6-luna", "capable": "gpt-6.1-sol"},
    "algorithm": {
      "type": "llm_classifier", "mode": "capability", "classifier_target": "jev",
      "strong_target": "capable", "weak_target": "efficient", "classify_trigger": "new_session",
      "decision": {"cutoff": 0.05, "candidates": {"candidate_a": "capable", "candidate_b": "efficient"}, "evidence": {}}
    },
    "default_model": "gpt-6-luna"
  }]
}

A judge adds the latency of its call to the request it routes, so the trade-off is yours to tune. classify_trigger: new_session asks the judge once per session instead of on every request, and algorithm deadlines, such as judge_deadline_ms, bound how long a request can wait. When a model call fails with a transport error or a 5xx, 403, 408 or 429 status, the extension moves to the next candidate model. Otherwise the algorithm’s own fallback, such as fail_open, applies, and if the algorithm fails, so does the virtual model’s failure_mode. If the client disconnects, the run stops.

When vgr, advisor or noop produce the answer themselves, the extension replies in the client’s API format, as server-sent events when the client asked for a stream, and the request never reaches a backend.

Routing that calls models is visible too. Every call carries x-switchyard-call, x-switchyard-parent-id and, when Envoy traces the request, W3C or B3 trace context, so judge calls show up in the same trace as the request they route. The judge’s evidence and the calls, tokens and latency spent on routing go in dynamic metadata, a switchyard_judge_calls counter tracks each judge by outcome, and routing_headers returns the routing cost in response headers.

The extension can also decide without rewriting the request. Set rewrite_body to false, and a later filter reads the decision and applies its own policy. The switchyard extension page documents the fields.

The Envoy extension developer experience

Envoy Dynamic Modules let you load native extensions into Envoy at runtime, without rebuilding Envoy. Tetrate contributed the core of that mechanism, including the Rust and Go SDKs, and Built On Envoy is the developer experience around it. Here’s what it gave us while building this extension:

  • A known structure. The extension follows the same layout as every other Rust extension in the catalog: a Cargo crate, a manifest, and a JSON schema for its configuration.
  • A fast local loop. boe run --local extensions/switchyard builds the module and starts Envoy with it, in front of an upstream that echoes requests. Sending a coding-auto request and seeing the rewritten body takes seconds, with no Kubernetes involved.
  • Testing without Envoy. The SDK’s mock filter lets the unit tests drive the full request flow, from headers to buffered body to rewrite, and the repository’s end-to-end harness runs the real module in Envoy.
  • Debugging in Envoy. boe debug --local extensions/switchyard builds the module with full debug information, starts Envoy with it, and attaches a debug server to the Envoy process: gdbserver on Linux, LLDB’s debugserver on macOS. From VS Code or any IDE that supports remote GDB or LLDB sessions, you set a breakpoint in the filter, send a coding-auto request, and step through the algorithm’s decision on the live request. Envoy keeps serving traffic between debug sessions, so you can reconnect at any time. The debugging guide has ready-made IDE configurations.
  • Packaging and distribution. The build produces an OCI image with the module, and the extension gets a page in the Built On Envoy catalog with its documentation, configuration reference, and examples.

Most of the effort went into the routing integration itself, which is where it belongs.

Using it with Agent Router

Agent Router, formerly Envoy AI Gateway, routes LLM traffic on Envoy Gateway: it reads the model from the request, picks the backend, injects credentials, translates between provider APIs, and tracks token usage and cost. The switchyard extension plugs in just before Agent Router reads the model.

Inside one Envoy process, a client request for coding-auto reaches the Switchyard extension, which rewrites the model to gpt-6.1-sol. Agent Router then routes it to its backend, injects credentials, translates the API, and tracks tokens and cost, and the Envoy router sends it to gpt-6.1-sol instead of gpt-6-luna. Judge calls either loop back through the gateway with model_calls, or go directly to Jev or a judge API with decision_targets or judge_targets.
The switchyard extension rewrites the model before Agent Router routes the request. Judge calls loop back through the gateway or go directly to a judge.

Because the extension rewrites the request body, Agent Router sees the selected model as if the client had asked for it. Everything Agent Router does then applies to that model: its backend, credentials, request translation, rate limits, and cost tracking. Agent Router itself is unchanged. The integration only uses standard Envoy Gateway and Agent Router resources.

The routing behavior lives in two of them: the EnvoyExtensionPolicy defines the virtual models and how Switchyard chooses between them, and the AIGatewayRoute defines where each selected model is served. The EnvoyProxy makes the module available to the Gateway’s Envoy pods.

The EnvoyProxy

The EnvoyProxy registers the module, mounts the extension’s OCI image into the Envoy pods as a Kubernetes image volume, and uses filterOrder to place the module before Agent Router’s filter. Reference it from your Gateway with spec.infrastructure.parametersRef.

envoyproxy.yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: switchyard
  namespace: default
spec:
  dynamicModules:
    - name: switchyard
      source:
        type: Local
        local:
          path: /var/boe/extensions/switchyard/libswitchyard.so
      # Keeps routers, and their session state, across configuration updates.
      doNotClose: true
  # Agent Router inserts its filter before the first lua, ext_proc or wasm filter,
  # so the module goes before them. Rules for filters that aren't present are ignored.
  filterOrder:
    - name: envoy.filters.http.dynamic_modules
      before: envoy.filters.http.lua
    - name: envoy.filters.http.dynamic_modules
      before: envoy.filters.http.ext_proc
    - name: envoy.filters.http.dynamic_modules
      before: envoy.filters.http.wasm
  provider:
    type: Kubernetes
    kubernetes:
      envoyDeployment:
        pod:
          volumes:
            - name: switchyard
              image:
                reference: ghcr.io/tetratelabs/built-on-envoy/extension-switchyard:0.1.1
                pullPolicy: IfNotPresent
        container:
          volumeMounts:
            - name: switchyard
              mountPath: /var/boe/extensions/switchyard
              readOnly: true

The EnvoyExtensionPolicy: the virtual models

The policy enables the module and holds its configuration. Here, coding-auto has two variants: requests with x-tier: free always get the efficient model, and everyone else gets the tier the stage_router algorithm picks for each step. Session state is scoped by tenant, so tenants never share routing state.

The policy targets the whole Gateway, not a route. Envoy picks the filters for a request from the first route it matches, and before the model is known, Agent Router requests first match its catch-all rule.

switchyard-policy.yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
  name: switchyard
  namespace: default
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: switchyard
  dynamicModule:
    - name: switchyard
      filterName: switchyard
      config:
        virtual_models:
          # Free-tier tenants always get the efficient model.
          - name: coding-auto
            match_headers:
              - name: x-tier
                value: free
            targets:
              efficient: gpt-6-luna
            algorithm:
              type: passthrough
              target: efficient
          # Everyone else gets the tier Switchyard picks for each agent step.
          - name: coding-auto
            targets:
              efficient: gpt-6-luna
              capable: gpt-6.1-sol
            algorithm:
              type: auto
              capable_target: capable
              efficient_target: efficient
            default_model: gpt-6-luna
        session:
          scope_headers:
            - x-tenant-id

The AIGatewayRoute: where each model is served

The route is a regular Agent Router route, with nothing specific to Switchyard. It has one rule per target model, matched on the x-ai-eg-model header that Agent Router sets from the rewritten body. The last rule is optional: it lists coding-auto in /v1/models and serves any request the extension leaves unchanged. The AIServiceBackend and Backend resources for efficient and capable are the same as in any Agent Router setup, with the provider schema and credentials of each model.

routes.yaml
apiVersion: aigateway.envoyproxy.io/v1beta1
kind: AIGatewayRoute
metadata:
  name: switchyard
  namespace: default
spec:
  parentRefs:
    - name: switchyard
      kind: Gateway
      group: gateway.networking.k8s.io
  rules:
    - matches:
        - headers:
            - type: Exact
              name: x-ai-eg-model
              value: gpt-6-luna
      backendRefs:
        - name: efficient
    - matches:
        - headers:
            - type: Exact
              name: x-ai-eg-model
              value: gpt-6.1-sol
      backendRefs:
        - name: capable
    - matches:
        - headers:
            - type: Exact
              name: x-ai-eg-model
              value: coding-auto
      backendRefs:
        - name: efficient

With these in place, a client sends "model": "coding-auto", the extension rewrites it to gpt-6-luna or gpt-6.1-sol, and Agent Router routes it to the matching rule.

Agent Router’s telemetry picks up the routing decisions too. Its request header attributes can map the x-switchyard-virtual-model and x-switchyard-reason headers to metric and span attributes, so dashboards show which virtual model a request asked for and why it went where it did.

Try it locally

The switchyard extension page includes a script that creates a kind cluster, installs Envoy Gateway and Agent Router, applies an example policy with two test model backends, and checks that coding-auto requests reach the model Switchyard picks. There is an example policy for every algorithm and feature, along with a test judge and decision API, and ./kind.sh all checks them all. The complete setup is in the extension’s README.

Seeing it route real traffic

We pointed the configuration at real models and let stage_router decide. The efficient target was minimaxai/minimax-m3.1-flash and the capable one nvidia/nemotron-3.5-super-vl-120b-a12b:

POST /v1/chat/completions  {"model":"coding-auto", ...}
→ 200, model=minimaxai/minimax-m3.1-flash

same session, one turn later, a tool result with exit_code=1 ("out of memory")
→ 200, model=nvidia/nemotron-3.5-super-vl-120b-a12b

We did the same for judges. The judge-routing example in the repository runs two virtual models side by side against real models: one asks Jev, through its own API key, and the other asks a Claude Haiku classifier through an OpenAI-compatible endpoint. It sends a set of coding-agent prompts, each labelled with the tier a person would pick, and writes an HTML report with each decision, the judge’s evidence and the end-to-end latency. On ten labelled tasks, Jev picked the expected tier for all ten and the Haiku classifier for eight. Ten tasks is a sanity check, not a benchmark: it shows the judges are wired in and make sensible calls, and the example is there so you can calibrate cutoffs and thresholds on your own traffic.

What this means for teams running agents

For agent developers, routing becomes a model name. Point an agent at coding-auto and the gateway decides, per turn, whether that step needs the efficient model or the capable one, with no routing code in the agent.

For platform teams, model routing becomes gateway policy. It is configured in one place, applies to every agent, shows up in the same metrics and traces as the rest of the traffic, and runs on the same Envoy foundation, with no new service to operate. When a policy needs a judge, its calls go through the same gateway credentials, rate limits and cost tracking as the rest of the traffic, or to a judge you choose, with its own key.

And for the Envoy ecosystem, it shows what Built On Envoy is for: taking a capability from another project, in this case NVIDIA’s routing research, and making it a first-class part of the gateway without forking it.

Get started with the switchyard extension, explore NVIDIA NeMo Switchyard, and learn more about Agent Router. We’d love your feedback and contributions in the Built On Envoy repository.

Agent Router is Tetrate's Envoy-based AI data plane — AI Gateway, MCP Gateway, and AI Guardrails — built on the open source Agent Router project (formerly Envoy AI Gateway) by its co-creators, and kept continuously patched by the Tetrate Patch Service.

Explore Agent Router
Product background Product background for tablets
Building AI agents

Agent Router Enterprise provides a managed AI Gateway, MCP Gateway, and AI Guardrails in your dedicated instance. Graduate agents from prototype to production with consistent model access, governed tool use, and runtime supervision — built on the open source Agent Router project (formerly Envoy AI Gateway) by its co-creators.

  • AI Gateway – Unified model catalog with automatic fallback across providers
  • MCP Gateway – Curated tool access with per-profile authentication and filtering
  • AI Guardrails – Enforce policies, prevent data loss, and supervise agent behavior
  • Learn more
    Replacing NGINX Ingress

    Tetrate Enterprise Gateway for Envoy (TEG) is the enterprise-ready replacement for NGINX Ingress Controller. Built on Envoy Gateway and the Kubernetes Gateway API, TEG delivers advanced traffic management, security, and observability without vendor lock-in.

  • 100% upstream Envoy Gateway – CVE-protected builds
  • Kubernetes Gateway API native – Modern, portable, and extensible ingress
  • Enterprise-grade support – 24/7 production support from Envoy experts
  • Learn more
    Decorative CTA background pattern background background
    Tetrate logo in the CTA section Tetrate logo in the CTA section for mobile

    Ready to enhance your
    network

    with more
    intelligence?