LLM Runtime: Which Layer Should Own Rate Limits, Retries, and Routing
Once the second business, the second provider, and the second tenant show up, calling the SDK directly is no longer enough. This piece covers the responsibility boundary of an LLM Runtime, multi-model routing, reliability under high concurrency, and how to choose an observability approach.
On this page · 14 sections
When the first Agent goes live, the model call is usually one line: send a request with the vendor SDK. Nothing wrong with that. The problems come later:
- a second business onboards and people start implementing their own retries;
- you switch model providers and the streaming event format is different;
- one tenant's batch job (a tenant being one business or customer sharing the system) eats the whole quota and everyone else's requests time out.
None of these is a model problem. They happen because nobody owns “one model call” as a whole. I saw the same structure repeatedly while working on the order domain and the risk platform: when a capability everyone depends on has no clear owner, reliability ends up scattered across every caller in inconsistent ways.
The Short Version
- The Harness owns the task and the Runtime owns one logical call: one stable contract separates the upper layers from ever-changing models, SDKs, and providers.
- Not every team needs this layer; it is worth splitting out when signals appear such as several businesses implementing their own retries, several models in use, multi-tenancy, or a need for unified usage data.
- Multi-model routing starts from the simplest option that solves the problem; reliability starts with an overall deadline, bounded retries, and basic rate limiting and queuing, with the rest driven by failures that have occurred or can be foreseen.
- Cancellation must be persisted and propagated along the whole chain; observability starts by reliably recording usage, cost, and quality signals for every call, split by tenant and scenario.
First, Separate Five Roles
“Isn't this just a model gateway? Can't we use an open-source one?”—this is the line I hear most often when LLM Runtime comes up. It conflates several layers with different responsibilities. In each row of the table, compare what the role owns with what it does not; the boundary sits between those two columns:
| Role | Responsible for | Not responsible for |
|---|---|---|
| Agent Harness | Tasks, loops, tools, state | How a single call gets executed reliably |
| LLM Runtime | The full lifecycle of one logical call: configuration, capability constraints, routing, retries, streaming, usage | Task planning and business logic |
| SDK | Adapting to one provider's protocol | Consistent semantics across providers |
| Gateway | Unified entry point, authentication, forwarding | Call-level business policy and recovery |
| Inference engine | Managing compute resources, running inference | Upper-layer call policy |
The one-line distinction: the Harness owns the task; the Runtime owns one logical call. One logical call may map physically to several requests—retries, fallback to a backup model, resuming after a streaming disconnect—but to the layer above it should look like exactly one call with a definite outcome.
Architecture
When This Layer Is Worth Building
Not every team needs it. With one business, one provider, and no multi-tenancy, the SDK plus a thin wrapper is enough. It becomes worth splitting out when these signals appear:
- Several businesses each implement their own retries, timeouts, and rate limiting, and the behavior is inconsistent;
- You need to use multiple models at once and want the upper layer to be unaware of protocol differences;
- You have multiple tenants and need quotas, isolation, and cost attribution;
- You need unified usage, cost, and quality data to support operational decisions;
- Changes in provider SDKs frequently affect business code.
The value of splitting it out comes down to one thing: a single stable contract that separates the upper layer from the constantly changing models, SDKs, and providers.
As for how far to take “building it yourself,” I lean toward a pragmatic trade-off:
- reuse mature open-source components for the generic, fast-changing parts such as protocol adaptation;
- own the parts tightly bound to your own business constraints—model registry, call policy, stream handling, usage, and observability;
- fill in special protocols with dedicated adapters.
Building everything in-house and depending entirely on third parties are both extremes.
Multi-Model Routing: Start with the Simplest Option
Multi-model routing answers this question: which model, and which service instance, should execute a given call? The inputs to that decision include task requirements, model capability, cost, performance, and current runtime state. The reason it exists is practical—no single model is best on quality, speed, and price at once.
Routing shows up at different layers:
- the Harness layer decides “what tier of model this kind of task uses”;
- the Runtime layer decides “who exactly this call goes to”;
- the SDK layer handles switching inside a single provider.
The mainstream options, in order of increasing complexity. When choosing, focus on the “Fits when” and “Main risk” columns:
| Option | How it works | Fits when | Main risk |
|---|---|---|---|
| Static binding | One fixed model per scenario | Few scenarios with clear differences | Cannot respond to changes in load or failures |
| Rule-based routing | Choose by rules on task type, length, tenant, and so on | Rules are enumerable and explainable | Rule sprawl and many edge cases |
| Semantic classification routing | A small model first judges intent or difficulty, then requests are split | Requests vary widely and classifying is cheaper than solving | A classification error becomes a quality problem directly |
| Quality-prediction routing | Predict each model's performance on the request, then choose | Enough historical evaluation data exists | The predictor itself needs training and maintenance |
| Quality-cascade routing | Try the cheap model first and escalate if the result falls short | Most requests are easy and a few are hard | Added latency; requires a reliable quality judgment |
The selection principle is the same as for all infrastructure: start with the simplest option that solves the problem. On intent-based splitting, a few lessons are worth remembering:
- Split only when necessary. If one model is acceptable on both cost and quality, do not introduce routing.
- Keep it as simple as possible. The more categories, the more chances to misclassify.
- Define categories by goal and destination, not by topic. A category should correspond to “which processing path it takes next.”
- Validate on a small share of traffic. A routing policy change, like a code release, needs a gradual rollout (that is, a small share of traffic first) and a comparison.
I put a similar constraint on the LLM controller in my RAG system: at most two retrieval rounds and only four possible decisions. See Why the LLM Controller Is Allowed at Most Two Retrieval Rounds. Routing and the controller are the same kind of problem—letting a model choose within a bounded space.
Reliability: A Model Call Is a Very Unusual Dependency
Compared with an ordinary RPC (that is, a remote call between services), an LLM call has several traits that defeat traditional reliability techniques:
- a single call takes a long time with high variance;
- the response is streamed;
- billing is per Token;
- the output is non-deterministic;
- provider rate limiting and outages are relatively frequent.
Enterprise settings add a few more problems on top: long-tail requests piling up, tenants interfering with one another, and streamed output breaking off midway.
High Concurrency
- Capacity planning comes first. Provider quotas are usually counted in both requests and Tokens; plan for both.
- Admission control and queuing. When capacity is exceeded, queue or reject explicitly rather than letting every request slow down together.
- Multi-tenant isolation and fairness. One tenant's batch job should not exhaust other tenants' quota.
- Overall deadline. Give one logical call a total time budget; retries and fallbacks happen inside that budget instead of each attempt running its own clock.
- Retry budget. Retries amplify load. Cap the total amount of retrying, or a single provider blip will be amplified into an avalanche by your own retries.
Failure and Recovery
- Persist checkpoints. Long tasks save progress at key steps and resume from the checkpoint after a failure instead of starting over.
- Streaming events carry a cursor. After a client disconnects and reconnects, it can continue from the last position it received instead of regenerating everything.
- Tool execution is idempotent. A resumed run may execute the same tool call again, so you need stable idempotency keys (that is, identifiers that make a repeated execution take effect only once) and a pre-execution check.
This is exactly the principle from event-driven systems: at-least-once delivery, with side effects idempotent end to end. I wrote down the same constraint in the decision record for the real-time risk platform.
Termination
Cancellation is the part most easily underestimated. After the user clicks “Stop,” the system needs to:
- Persist the cancellation intent, not just set a flag in memory;
- Propagate the cancellation event along the entire chain—Harness, Runtime, the in-flight model call, and tool execution;
- Forbid further retries, otherwise the retry mechanism will bring a cancelled task back to life;
- Clean up and reconcile reliably, confirming the usage and side effects already incurred.
A system that does not handle termination well keeps consuming Tokens after the user believes it has stopped, and may even keep executing actions with side effects.
The Trade-off: Build the Minimum First
The list above is long, but it does not all need to exist on day one. A sensible order:
- start with an overall deadline, bounded retries, and basic rate limiting and queuing;
- add isolation and fairness once multi-tenancy appears;
- add checkpoints and resumption once long tasks appear.
Reliability mechanisms have their own maintenance cost and should be driven by failures that have already occurred or can be foreseen.
Observability: From Callable to Operable
The gap between being able to call a model and being able to operate a model platform is data. What you need to observe is not only “did the request succeed,” but also usage, cost, each phase of latency, quality, and how those metrics are distributed across tenant, scenario, and model.
Observability infrastructure can be viewed as five layers:
| Layer | What it is concerned with |
|---|---|
| Runtime objects | What is being observed: a call, a session, a task |
| Standards and transport | Which specification and channel collect the data, for example OpenTelemetry |
| LLM instrumentation and collection | How Prompts, responses, Token usage, and tool calls are recorded |
| Evaluation and quality | How to judge whether output is good; offline evaluation and online scoring |
| Visualization and analysis | Who looks at it and which questions it answers |
When choosing, do not start from tools. First decide which kind of need you have:
- Lightweight diagnostics: A small team whose main purpose is troubleshooting. Logs plus basic Trace are enough.
- Production operations: You need to track cost, latency, and quality continuously to support day-to-day operational decisions.
- Governance at scale: Multiple teams and tenants that need quotas, cost attribution, and unified quality standards.
- Compliance and isolation: Data cannot leave a specific environment, with strict requirements on storage and access.
Most enterprise Agents in a growth phase belong to production operations: the priority is reliably recording the usage, cost, and quality signals of every call and being able to break them down by tenant and scenario. Building for governance at scale too early saddles you with the maintenance cost of an entire platform before you have that many tenants.
One reminder: recording Prompts and responses is itself handling sensitive data. Collection scope, redaction, and access permissions should be settled at design time, not after the first data incident.
A Few Judgments That Will Change over Time
This layer is not static. The following questions are worth re-answering periodically:
- How much of routing will be absorbed by models or provider platforms? Some of it will. But decisions such as “which requests can use a cheap model” and “can this data be sent to a given provider” involve the enterprise's own cost and compliance and should stay in its own hands.
- If a model can detect its own errors and retry, what is left of the system's reliability design? Budgets, isolation, idempotency, and cancellation—these are questions about resources and side effects, not about answer quality.
- If model calls become cheap, stable, and standardized enough, where does the focus of governance move? To quality and data: whether the output is correct, whether data flows are compliant, and whether the cost produced corresponding business value.
These questions have no fixed answers. But writing them down, and agreeing on which signals trigger a re-evaluation, is itself part of designing this layer.
Rollout Checklist
- Is there a stable call contract the upper layer can depend on, one that isolates specific SDKs and providers?
- Does one logical call have an overall deadline and a retry budget?
- When capacity is exceeded, do you queue, reject, or let every request slow down together?
- Are there quotas and isolation between tenants?
- Can streamed output resume after a disconnect? Can a long task resume after a failure?
- Is cancellation persisted and propagated along the entire chain?
- Can the usage and cost of every call be attributed to a tenant and a scenario?
- Do routing policy changes go through a gradual rollout and a comparison?
At this point all five questions have answers: where cost and risk come from, who holds control, how to deliver reliably, who owns the call, and how you know it is still right after launch. Go back to the series overview to see how they connect into one route.
Note
This article is my notes and further thinking after studying material from an enterprise Agent engineering architecture course (“企业级 Agent 工程架构实战营”). The structure, wording, and diagrams are all rewritten and combined with my reliability experience on the order domain and the real-time risk platform; the judgments are my own responsibility.
Related notes
Agent Architecture: Should the Program or the Model Decide the Next Step
The difference between Workflow, Autonomous, and Hybrid is not the framework but who decides the next step. This article covers when each pattern fits, how each one fails, and a selection method that starts from task conditions.
Where the Cost of a Model Call Comes From, and Where It Can Go Wrong
Token, Context, Prefill, Decode, and caching determine an Agent’s cost and latency; hallucination and Prompt Injection determine the floor of its risk. Without understanding these, none of the later architectural trade-offs has a basis.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]