12 · Route and cache requests
Decide when the Facilities Helpdesk can reuse an answer, when it needs a fresh lookup and which outcome to measure.
- Part 4
- Operate and release
- Model
Qwen2.5-1.5B-Instruct- Data
- Synthetic facilities helpdesk
- Hardware
- Tesla T4 and CPU, in Google Colab
The same question comes in again
The North Yard operator asks for fan F-250’s maximum temperature. The desk has the previous answer, 101 °C. The latest manual is now on the console. Decide whether you can send the previous answer or need a fresh read. If you send an old temperature limit, the crew may use it as today’s limit.

“What is the maximum temperature for F-250?”
Previous response · 101 °C · manual-F-250-r3manual-F-250-r3
Maximum operating temperature: 101 C.
manual-F-250-r4
Maximum operating temperature: 99 C.
Check the reuse decision
On r3, the same operator and question can reuse 101 °C from manual-F-250-r3. On r4-index, reread the manual and return 99 °C from manual-F-250-r4.
The guest request is denied before the cache is checked.
Change one fact. Keep the operator, tenant, fan and question fixed. Change the active source snapshot.
| Active snapshot | What should the desk do? |
|---|---|
| r3 | Reuse the answer tied to the current r3 manual. |
| r4-index | Read the updated manual, then return its limit and citation. |
The typed route verified more requests and cut model calls
Identical queues of 40 requests. Paired change is relative to Always model.
1Strict outcomes with family uncertainty
Verified requests · delta in pp with 95% paired interval
a| Route policy | Verified | Δ and interval |
|---|---|---|
| Always model | 8/40 | Reference |
| Cheap first | 28/40 | +50 [+16.7, +80] |
| Cold cache | 28/40 | +50 [+16.7, +80] |
| Warm cache | 28/40 | +50 [+16.7, +80] |
Model calls
Calls per full replay
b| Route policy | Calls |
|---|---|
| Always model | 32 |
| Cheap first | 12 |
| Cold cache | 12 |
| Warm cache | 12 |
Decide which questions need generation
Each arm starts with the same access check. The Always model arm sends every eligible question to Qwen. Cheap first gives the host a chance to perform a typed lookup or ask for clarification. If an eligible ticket asks for a supporting system as well as an inspection date, the typed route declines it and the model gets the prompt. F-250’s temperature question needs just the limit and the current manual ID, so a typed lookup can return both directly.
These confidence values are scores assigned by rules. A missing referent gets a clarification at 1.00, an explicit temperature lookup can qualify at 0.99, and an explicit inspection lookup can qualify at 0.94. The cutoffs were compared on the lower-numbered development family in each slice before replaying the other family.
# Admit a typed outcome only at the chosen threshold.
confidence, proposal = cheap_answer(case)
if proposal is not None and confidence >= cutoff:
outcome, route = proposal, "typed"
if key is not None:
cache[key] = outcomeA cutoff of 0.94 accepted 12 of 20 eligible tuning requests. All 12 passed strict grading. The higher cutoffs also verified every proposal they admitted, with fewer cases covered. FrugalGPT similarly checks whether to accept a result or escalate to another model. RouteLLM’s thresholds vary across benchmark tasks and training sets, so measure the escalation policy on the requests it will handle. FrugalGPT, §§4–5 · RouteLLM, §5
The lowest checked cutoff admitted the most verified typed proposals
Tuning families only · all proposals at each cutoff passed strict grading
2| Cutoff | Admitted / eligible | Verified / admitted | Precision |
|---|---|---|---|
| 0.94 | 12/20 | 12/12 | 100% |
| 0.99 | 8/20 | 8/8 | 100% |
| 1.00 | 4/20 | 4/4 | 100% |
The cold cache starts empty on the same queue. The warm cache starts with entries from the cold pass, then sees the identical queue. Both can serve an earlier typed outcome. Coverage measures the fraction of eligible requests handled by typed work or reuse:
All three typed policies covered 20/32 eligible requests. Cold reuse handled six of the 40 total requests. Warm reuse handled 20. The denominator for hit rate includes guards, so it differs from the coverage denominator. A cold start is worth measuring separately when the saved work depends on state already being present. Amazon API Gateway documents that rebuilding a flushed cache can briefly raise origin traffic and latency. Amazon API Gateway cache settings
Warming the cache replaced typed reads one for one
Counts of observed routes · warm replay began with the cold pass’s cache
3| Policy | Guard | Typed | Hit | Model | Hit rate |
|---|---|---|---|---|---|
| Always model | 8 | 0 | 0 | 32 | 0% |
| Cheap first | 8 | 20 | 0 | 12 | 0% |
| Cold cache | 8 | 14 | 6 | 12 | 15% |
| Warm cache | 8 | 0 | 20 | 12 | 50% |
Give a cached answer the same scope as the original
Caching reuses an answer to equivalent work, not any answer that sounds similar. The asset, access and freshness conditions must still apply to the new request.
The same words can ask a different question after a manual changes, or come from a different operator. The key includes the tenant, role, trusted source snapshot, resolved asset, remembered revision and the versions of the prompt and policy. Only eligible requests can reach that key.
# Decide access before an entry can be used.
outcome = access_guard(case)
key = cache_key(case) if outcome is None and cache is not None else None
if key is not None and key in cache:
outcome, route = cache[key], "cache_hit"# Trusted context determines whether two answers are interchangeable.
return AnswerKey(
case["tenant"], case["role"], source_snapshot(case),
reference_asset(case) or "", case.get("previous_version", ""),
PROMPT_VERSION, POLICY_VERSION, canonical(case["question"]),
)Cloudflare AI Gateway uses provider, endpoint, model, provider authentication and request body in its default exact-response cache key. The helpdesk adds its own trusted fields because the validity of a manual citation depends on local data and access. Complete-response reuse also differs from caching an exact prompt prefix. The Claude API can reuse prefix processing and still generate the output tokens. Cloudflare AI Gateway caching · Claude API prompt caching
The timed replay changes a snapshot key while holding its source facts fixed. In the separate F-250 probe below, r4 actually changes the limit. The guard also sees the exact r4 question from a guest, after an operator has already filled the cache.
The revision missed the cache. The guard denied the guest.
Separate F-250 probe · same question on every row
4| Request | Snapshot | Checked cache | Route | Result |
|---|---|---|---|---|
| fan-1 | r3 | Yes | Typed | 101 °C |
| fan-2 | r3 | Yes | Hit | 101 °C |
| fan-3 | r4-index | Yes | Typed | 99 °C |
| fan-4 | r4-index | Yes | Hit | 99 °C |
| fan-5 | r4-index | No | Guard | Deny |
fan-2 · operator · r3 · What is the maximum temperature for F-250?
- Expected
- {"decision":"answer","value":"101","evidence":["manual-F-250-r3"]}
- Observed
- {"decision":"answer","value":"101","evidence":["manual-F-250-r3"]}
Cache hit on the unchanged trusted key.
fan-3 · operator · r4-index · What is the maximum temperature for F-250?
- Expected
- {"decision":"answer","value":"99","evidence":["manual-F-250-r4"]}
- Observed
- {"decision":"answer","value":"99","evidence":["manual-F-250-r4"]}
The new snapshot produced a cache miss and a typed lookup returned the updated evidence.
fan-5 · guest · r4-index · What is the maximum temperature for F-250?
- Expected
- {"decision":"deny","value":"","evidence":[]}
- Observed
- {"decision":"deny","value":"","evidence":[]}
The access guard denied the guest before cache lookup.
replay-000 · What is the maximum temperature for P-201?
- Expected
- {"decision":"answer","value":"70","evidence":["manual-P-201-r3"]}
- Always model · exact raw reply
- ```json { "decision": "The maximum temperature for P-201 is 70°C.", "value": null, "evidence": [ "inventory-P-201-r3",
- Cold cache · typed result
- {"decision":"answer","value":"70","evidence":["manual-P-201-r3"]}
The model reply ends without closing the JSON and names an inventory record where the grade requires a manual. The typed path returned the expected value and evidence.
Read the P-201 row alongside the F-250 rows. The model reply contains the temperature inside a sentence, sets the value to null and cites an inventory record in an incomplete JSON response. The strict grader requires the decision, exact value and source IDs together. The typed result supplies all three. The F-250 probe checks that reusing such a result still depends on the current snapshot and the current caller.
Measure less work against the same outcomes
The replay uses six equipment families with ordinary, repeated and changed-snapshot requests. Compare matching request IDs and resample whole families for confidence intervals. The gain in the replay comes from manual reads, inspection-date lookups and clarifications. Multi-source and follow-up cases had zero wins. Their remaining model work is where a new route would need to prove itself.
Lookup and clarification account for the gains
Cold cache versus Always model · same request ID on both sides
5| Slice | Wins | Losses | Ties |
|---|---|---|---|
| Manual | 7 | 0 | 1 |
| Inspection | 7 | 0 | 1 |
| Multiple sources | 0 | 0 | 6 |
| Ambiguity | 6 | 0 | 0 |
| Access | 0 | 0 | 6 |
| Follow-up | 0 | 0 | 6 |
Track tail latency and work per verified outcome separately. Request time starts before the access check and ends when the outcome is ready to grade. Model time includes tokenisation, generation and decode, with GPU work synchronised. For verified outcomes:
This denominator includes verified clarifications and denials, since they are correct desk outcomes. The FinOps Foundation makes the same distinction between infrastructure consumption and an outcome such as a resolved case. Here the numerator is measured wall time for generation calls, with zero model time assigned to CPU-only paths. It does not measure the bill, throughput under concurrency or the cost of keeping a cache hot. FinOps Foundation, Unit Economics
Fewer generation calls cut model time per verified outcome
Replay timings in ms · bars have a separate scale in each panel
6p95 request latency
Guard to returned outcome, before grading
a| Policy | p95, ms |
|---|---|
| Always model | 2157 |
| Cheap first | 1921 |
| Cold cache | 1839 |
| Warm cache | 1879 |
Model wall time per verified outcome
Sum of model-call ms / verified results
b| Policy | ms / verified |
|---|---|
| Always model | 6398 |
| Cheap first | 751 |
| Cold cache | 727 |
| Warm cache | 751 |
The recorded p95 fell from 2,157 ms with Always model to 1,921 ms with Cheap first. The three typed policies all made 12 model calls, and remaining latency differences between their sequential replays should not be read as a capacity result.
What to keep
| Policy | Verified | Model calls | Cache hits | p95 |
|---|---|---|---|---|
| Always model | 8/40 | 32 | 0 | 2,157 ms |
| Cheap first | 28/40 | 12 | 0 | 1,921 ms |
| Cold exact cache | 28/40 | 12 | 6 | 1,839 ms |
| Warm exact cache | 28/40 | 12 | 20 | 1,879 ms |
- Check access before reuse. Deny a guest even after an operator has filled the cache for the identical question.
- Version the answer’s source. Give r4 a different snapshot key so the crew gets the new limit and its citation.
- Escalate beyond tested coverage. Keep the source and grade visible for tickets the typed route cannot answer.
- Track passes with every saving. Plot strict outcomes alongside calls, hit rate and p95.
Next to try, not tested here:
- Replay the same requests with a lower duplicate rate and compare cold-start hit rate.
- Introduce a separate cacheable, verified multi-source route and check citation freshness across two source revisions.
- Replay overlapping arrivals to measure whether simultaneous misses change model calls and p95.
How it was built
| Item | Setting |
|---|---|
| Model | Qwen/Qwen2.5-1.5B-Instruct at 989aa7980e4cf806f80c7fef2b1adb7bc71aa306 |
| Runtime | Tesla T4 and host CPU. Python 3.13.16, PyTorch 2.14.1+cu130, Transformers 4.51.3, Accelerate 1.6.0 |
| Decode | Greedy, up to 48 new tokens. One model warm-up before the measured arms. |
| Development partition | 24 tuning cases across six families. 24 replay cases from the six other development families. |
| Replay mix | 24 ordinary, 12 exact repeats, two snapshot changes and two tenant-boundary requests |
| Outcome | Exact decision, value and evidence IDs. All guards run before typed reads, cache hits or generation. |
| Cache | Stores typed outcomes only. Scope includes trusted tenant, role, source snapshot, asset, remembered revision, prompt version, policy version and canonical question. |
| Timing | Request p95 across 40 rows per arm. Model-call wall milliseconds summed separately. |
Time and cost. The executed notebook completed in 150.5 seconds on the Colab T4 runtime. That whole-notebook time includes setup and differs from the replay measures. The lab reports model time per verified result and does not record a serving bill.
Download the executed notebook · Scorecard · Replay rows · F-250 revision rows · Runtime receipt
Run it yourself
Start with the F-250 revision probe to inspect the key and the actual citation. Use the tuning cells to reproduce the cutoff table, then the paired replay cells for the route, quality and cost figures.
- Change
FAN_REVISION["limit"]to 97. Predict the returned value and cited ID for the r4 request. Check both in the saved probe. - Set
repeat_variants=()inbuild_queue. Predict how the cold hit rate changes, then compare the replay composition, hit rate and model calls. - Set the accepted cutoff to 1.00 after tuning. Predict which previously typed tickets escalate. Compare the affected rows, verified counts and p95.
In Lesson 13, Turn traces into regressions, turn recorded failures into checks that can run again before a change ships.
How is this page?
Last updated on