---
title: "How to Build a Model Router in the Harness"
description: "Routing each coding-agent thread to one of three model tiers (fast, balanced, performance) cut median cost per thread by 64% versus always using a top frontier model, with no measurable change in merged-PR rate (29.2% vs 27.3%, p=0.49) across 973 threads in Open SWE."
url: "https://swe.quest/articles/how-to-build-a-model-router-in-the-harness-cfe4402ea89738e9"
canonical: "https://www.langchain.com/blog/how-to-build-a-model-router-in-the-harness"
source: "LangChain"
published: "2026-10-09"
difficulty: "medium"
kind: "Case study"
reading_minutes: 11
tags: ["ai-agents","llms","cost-optimization","evals","ai-coding"]
---

# How to Build a Model Router in the Harness

A post on [LangChain](https://swe.quest/sources/langchain.md), published 2026-10-09, 11 min read, Case study. Original: [https://www.langchain.com/blog/how-to-build-a-model-router-in-the-harness](https://www.langchain.com/blog/how-to-build-a-model-router-in-the-harness)

## Summary

Routing each coding-agent thread to one of three model tiers (fast, balanced, performance) cut median cost per thread by 64% versus always using a top frontier model, with no measurable change in merged-PR rate (29.2% vs 27.3%, p=0.49) across 973 threads in Open SWE. The router runs as harness middleware, classifying the first user message against per-tier criteria. Those criteria come from trace-based task analysis and provider guidance, which is why it belongs in the harness rather than a generic gateway. Most threads went to the balanced (56%) or fast (34%) tiers. A fast-only control degraded quality so quickly it was stopped within a day. Future work includes subagent routing and mid-thread re-routing, which carries a prompt-cache cost.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)
- [Evaluation](https://swe.quest/tags/evals.md) (AI & ML)
- [AI for coding](https://swe.quest/tags/ai-coding.md) (AI & ML)

## Prerequisites

- LLM agents ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- A/B testing basics ([easy posts on Testing](https://swe.quest/tags/testing.md?difficulty=easy))

## Keywords

LangChain, Open SWE, LangSmith, GPT-6 Astra, GLM-5.3-Flash, Artificial Analysis Intelligence Index

## Related posts

- [Model Routing Is Simple. Until It Isn’t.](https://swe.quest/articles/model-routing-is-simple-until-it-isn-t-aff4745dc4d94524.md): Hugging Face · 2026-07-15 · Easy · 5 min read · Inference & serving, AI agents, LLMs, Cost optimization
  LLM model routing in agentic systems is a systems optimization problem, not a classification one.
- [How Cursor Router chooses the right model for the task · Cursor](https://swe.quest/articles/how-cursor-router-chooses-the-right-model-for-the-task-cursor-5ca9c42f82fc2ccc.md): Cursor · 2026-08-06 · Medium · 6 min read · LLMs, AI for coding, Evaluation, Cost optimization
  Cursor Router picks a model per agent turn in two stages: Compass, a complexity predictor trained on implicit user-satisfaction signals (moving on vs. correcting the agent), decides whether a turn stays on a cheap model (Grok) or gets upgraded.
- [The Open Source AI Stack](https://swe.quest/articles/the-open-source-ai-stack-4e2d322b6b4e06e6.md): Together AI · 2026-09-09 · Easy · 14 min read · AI for coding, AI agents, LLMs, Inference & serving
  Adopting open models for agentic coding is framed as a five-layer "MIGHT" stack: model, inference provider, gateways/routers, harness and tools (skills and MCP), with each layer swappable independently so new models can be tried in minutes.
- [Introducing harness adapters: adapt your favorite model to your harness to improve performance and cost](https://swe.quest/articles/introducing-harness-adapters-adapt-your-favorite-model-to-your-harness-to-8f64a783213a2586.md): Hugging Face · 2026-11-20 · Hard · 21 min read · Model training, AI agents, AI for coding, Evaluation, LLMs
  RL-training a LoRA adapter for a specific agent harness and task distribution makes a frozen base model both more accurate and cheaper: Qwen3.8-27B under the pi harness rises from 39% to 55% pass@1 on Terminal-Bench 2.1 while average token usage drops from 2.9K to 1.5K per task, mostly because the model reasons less and calls fewer tools.
- [AI Agent Latency 101: How do I speed up my AI agent?](https://swe.quest/articles/ai-agent-latency-101-how-do-i-speed-up-my-ai-agent-62a7a640683900cd.md): LangChain · 2026-08-26 · Easy · 5 min read · AI agents, Performance engineering, LLMs
  AI agent latency can be cut in five ways: find the bottleneck first (e.g. with per-step tracing and a waterfall view), reduce perceived latency through UX, make fewer LLM calls, make each call faster, and run calls in parallel.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
