مهندسی سامانه‌های هوش مصنوعی · فصل ۲ — Model Selection، Serving، Cost Governor و Workflow · 137

Local-first Routing and Model Selection

Design a local-first routing policy that consumes qualification evidence from AIE-004, explicit capability requirements, placement/privacy constraints, latency/availability evidence and bounded cost signals; prove that the router prefers a qualified local path when its hard constraints pass, rejects unqualified candidates, and records why a remote or alternate route is chosen when local execution cannot satisfy the contract. می‌تواند «Local-first Routing و Model Selection» را در یک workflow AI محدود طراحی کند و validation، authority، cost یا failure controls مرتبط را مشخص کند.

Local-first Routing و Model Selection — fa-IR

Lesson summary

Design a local-first routing policy that consumes qualification evidence from AIE-004, explicit capability requirements, placement/privacy constraints, latency/availability evidence and bounded cost signals; prove that the router prefers a qualified local path when its hard constraints pass, rejects unqualified candidates, and records why a remote or alternate route is chosen when local execution cannot satisfy the contract.

می‌تواند «Local-first Routing و Model Selection» را در یک workflow AI محدود طراحی کند و validation، authority، cost یا failure controls مرتبط را مشخص کند.

This lesson produces

می‌تواند «Local-first Routing و Model Selection» را در یک workflow AI محدود طراحی کند و validation، authority، cost یا failure controls مرتبط را مشخص کند.

Who it is for

Foundation

Use a guided lesson-specific evidence matrix and one worked negative case.

Repair

Re-run only the failed owned dimension with a smaller deterministic synthetic fixture.

Experienced

Start from mixed current-tool and synthetic product evidence; require explicit trade-offs and provenance.

Prerequisites

1. The real problem: local-first is a preference, not a shortcut

A workflow may have several execution paths at once: a workstation model, a local/cluster serving endpoint, and one or more remote providers. If the router looks only at locality, price, or latency, it can select a model that is not qualified for the requested task/locale/risk slice. In this lesson, local-first is allowed to matter only after hard gates pass.

2. Keep routing separate from model qualification

AIE-004 determines which exact model/runtime/configuration is qualified for a task/locale/risk slice. AIE-005 consumes that evidence and decides a route. The router may not replace missing qualification with familiarity, model reputation, a general benchmark, or one successful call.

3. Freeze the request contract before evaluating candidates

Every decision begins with a request slice: task, locale, risk, mandatory capabilities, latency SLO, placement/privacy constraints, and data-egress state. If that contract is ambiguous, candidate ranking only looks rigorous; an auditor cannot tell why a route was allowed.

4. Qualification binding must match the exact candidate version

QUALIFIED is insufficient without the relevant model version, runtime/configuration, and slice. If a decisive model/runtime version changes without a matching qualification record, the binding becomes STALE or MISSING. Local-first never grants implicit reuse of an old qualification.

5. Capability is an independent hard gate

A candidate can be quality-qualified yet lack a mandatory capability such as structured output. That candidate is INELIGIBLE; the router must not drop the field, rewrite the prompt, or weaken the application contract merely to keep execution local.

6. Placement and egress remain hard gates after qualification

A remote candidate may have the best quality and latency, but it is not allowed when egress_allowed=false. Conversely, locality is not itself a privacy proof; it only identifies execution placement, which still must be evaluated against policy and deployment evidence.

7. Keep availability and latency evidence separate from folklore

Qualification does not mean availability. A qualified local candidate that is unavailable or whose measured latency violates the request SLO is not eligible for that request. Record the evidence rather than assuming local routes are normally fast.

8. Consume cost signals without owning budget enforcement

AIE-005 may retain a versioned cost signal and use it for bounded preference or ordering, but quota enforcement, retry amplification, and circuit state belong to AIE-008. Routing must not reinterpret or bypass those controls.

9. Decision order: hard gates → eligible set → local preference

The auditable order is qualification binding → capability → placement/egress → availability/latency → eligible candidate set. Only then may local-first preference and route priority run. A high score cannot re-admit a candidate that failed a hard gate.

10. Worked example: why remote-alpha wins

In the baseline fixture, local-ollama-q4 has no Persian qualification; local-vllm-fp16 is qualified for Persian but unavailable; remote-alpha is qualified for the requested Persian/risk slice, egress is allowed, and the route is available. The bounded result is ROUTE to remote, not breaking qualification to preserve locality.

11. Negative case: local structured output is missing

If local-vllm-fp16 is available and qualified but lacks mandatory structured output, the local route fails. If the remote route passes all gates, select remote; if egress is also blocked, return REJECT rather than silently degrading the contract.

12. Stale binding: a new model version needs new qualification evidence

Suppose the local model version changes while the qualification record remains bound to the previous version. Even if the endpoint is healthy, latency is good, and the model name looks familiar, the current candidate is not qualified. With no eligible alternative, DEFER pending requalification is the bounded decision.

13. Route provenance is part of the output

The output is more than selected_route. Retain policy version, request slice, candidate versions, gate results, rejection reasons, and the final selection rationale. Without provenance, downstream code sees only a route name and cannot audit the evidence that allowed it.

14. Lab: eight deterministic fixtures

The lab covers baseline remote fallback, a qualified/available local route, missing capability, blocked egress, stale qualification, local latency breach, remote unavailability, and a transfer case with a new local candidate that lacks a required capability. The evaluator applies hard gates before preference and emits eight result fields per case.

15. Exit checklist and transfer

Before leaving, verify that the request contract is versioned; qualification matches the exact slice and version; capability and egress are hard gates; unavailable or too-slow routes are ineligible; local preference runs only on the eligible set; and rejection reasons plus policy version are recorded. For transfer, recompute from scratch with egress_allowed=false and a newly qualified local candidate that still lacks structured output; do not copy the earlier route decision.

Assessment

There is no answer key in this lesson pack; answer it yourself and mark honestly. "Needs review" sends the lesson to your review queue.

Q1 retrieval

When may local-first preference influence route selection?

lesson ✗AI ✗notes ✗

Q2 application

A local model is qualified for English low-risk classification but the request is Persian medium-risk. Is locality enough to route to it?

lesson ✗AI ✗notes ✗

Q3 diagnosis

A qualified local route lacks mandatory structured output while a qualified remote route passes all gates and egress is allowed. What is the bounded decision?

lesson ✗AI ✗notes ✗

Q4 evidence

The model version changes but the qualification record remains bound to the old version. What happens?

lesson ✗AI ✗notes ✗

Q5 transfer

Egress becomes false and a newly qualified local route meets latency but lacks required structured output. May the prior remote decision be copied?

lesson ✗AI ✗notes ✗
Assessment rubric

A sufficient submission makes the owned routing boundary explicit, binds qualification to the exact task/locale/risk and candidate version, preserves capability/placement/availability/latency failures as typed states, applies local preference only after hard gates, records provenance and rejection reasons, and rebuilds the transfer decision from changed evidence. A submission fails if locality, cost, one endpoint success, or a stale qualification overrides a hard gate.

References & freshness

Ollama API — Introduction
·
Current Ollama local/cloud API availability and base-surface facts; not proof of task quality, privacy, cost superiority, or MAKNOW qualification.
vLLM — Stable Documentation
·
Current vLLM serving feature/capability overview used only as candidate-route evidence; not product qualification for a specific model/server configuration.

Case studies

Lesson visuals

AIE005-V1

Lab files

Implement evaluate(case) in starter.py. The function must return at least these eight auditable fields: qualified_eligible_count, capability_eligible_count, placement_eligible_count, operational_eligible_count, final_eligible_count, selected_route, final_decision, and reason_class.

Apply hard gates in order. Qualification must match the exact request task/locale/risk and candidate model version. Required capabilities must be present. Remote placement must respect egress_allowed. Availability must be AVAILABLE, and measured latency must be within the request SLO. Only after those gates may local-first preference influence selection. Do not invent qualification, capability, latency, availability, or cost evidence.

Run python run_checks.py for learner-visible structural checks. The hidden evaluator tests deterministic states and changed-context transfer.

Lesson media & slides

MAKNOW_AIE-005_DECISION_EVIDENCE_TABLE_v1.0.svg
DECISION EVIDENCE TABLE v1.0.svg
MAKNOW_AIE-005_FAILURE_REPAIR_v1.0.svg
FAILURE REPAIR v1.0.svg
MAKNOW_AIE-005_PRIMARY_MODEL_v1.0.svg
PRIMARY MODEL v1.0.svg
MAKNOW_AIE-005_WORKED_EXAMPLE_v1.0.svg
WORKED EXAMPLE v1.0.svg

Teaching files (download)

XLSXLocal first Model Route Policy Qualification Binding Record v1 v1.0.0.xlsxTeaching files (download)
DOCXLocal first Model Route Policy Qualification Binding Record v1 WORKSHEET v1.0.0.docxTeaching files (download)
PDFLocal first Model Route Policy Qualification Binding Record v1 WORKSHEET v1.0.0.pdfTeaching files (download)