Giving AgentGateway a Semantic Brain with vLLM Semantic Router

Agent systems that span multiple models — a local endpoint for coding, a frontier cloud model for deep reasoning, and a fast general-purpose model for everyday tasks — all face the same routing question: how should each request be directed to the right backend?
Many deployments start with a lightweight Python proxy or keyword matcher in front of the gateway. That approach works at small scale, but misroutes grow quickly as traffic, languages, and task types diversify. This post shows how vLLM Semantic Router running as an Envoy ExtProc sidecar inside AgentGateway replaces that pattern with semantic, config-driven routing.
The Problem: Keyword Routing Does Not Scale
A typical multi-model agent gateway fronts three backends:
| Backend | Model | Role |
|---|---|---|
| Local Ollama | qwen2.5-coder:7b | Coding and technical work |
| OpenAI | gpt-4o | Deep reasoning |
gemini-2.5-flash | Fast general tasks |
The routing layer was a simple keyword matcher:
# router.py — keyword-based routing
coding_keywords = ["code", "python", "javascript", "bash", "script",
"function", "bug", "error", "html", "css"]
reasoning_keywords = ["think", "analyze", "explain in detail",
"reasoning", "logic", "deduce"]
if any(k in prompt_lower for k in coding_keywords):
intent = "coding"
elif len(prompt) > 400 or any(k in prompt_lower for k in reasoning_keywords):
intent = "reasoning"
else:
intent = "simple"
After two weeks of sustained traffic, the rough numbers looked like this:
| Metric | With Python Router |
|---|---|
| Misrouted requests (spot-checked) | ~18% |
| Monthly estimated API cost | ~$24 |
| Routing latency (Python proxy hop) | ~45ms |
| Keyword list maintenance | Manual, weekly tweaks |
Eighteen percent misroutes is not just wasted spend — it produces worse answers. Scheduled agent jobs that sent "summarize this week's calendar and suggest optimizations" to the 7B local model instead of Gemini or GPT-4o returned noticeably weaker output. Mixed-language prompts and unanticipated domains silently fell through to the wrong lane.
The architecture needed a routing layer that understood the prompt, not just scanned it for keywords.
Enter vLLM Semantic Router + AgentGateway
AgentGateway maintainers Keith Mattix and John Howard helped shape first-class ExtProc integration with vLLM Semantic Router. The resulting architecture is straightforward.
Instead of a Python reverse proxy sitting in front of the gateway, Semantic Router runs as an Envoy ExtProc sidecar. AgentGateway pauses the request, sends the HTTP body to the SR gRPC endpoint, receives a header mutation (x-selected-model: qwen-coder), and resumes routing. Zero proxy hops. Zero Python processes. Just gRPC-native intelligence inside the gateway's own request lifecycle.
Semantic Router uses an embedded mmBERT model (a 2D Matryoshka embedding model, ~130MB) to classify every prompt and compare it against model descriptions defined in YAML. No keyword lists. No regex. Actual embeddings.

For Kubernetes deployments, the same pattern is documented in the Install with agentgateway guide.
The Setup: Two YAML Files, No Code
The full integration is defined in two config files.

