Skip to content
AgenticAIWiki
  1. Learn
  2. Part 5
  3. 30. Local inference
  4. 30.5

Lesson 30.5 · 5 of 8 · 4 min read · Reviewed 24 Nov 2026

Hybrid setups: local models with a cloud fallback

By the end, you can

  • Design a hybrid local-plus-cloud setup.
  • Handle routing and fallback safely.

A routing sketch

request
  -> classify data: may it leave the device?     no  -> local only (queue if busy)
  -> classify task: easy or hard?                easy -> local
                                                 hard -> Claude (with redaction if needed)
  -> local model unsure or failing?              yes -> Claude, if data allows; else a person
  -> offline?                                    yes -> local, or save for later

Rules

  1. Data rules are hard limits. Never fall back to the cloud with data that must stay local.
  2. Confidence signals. Let the local model say “unsure”, or use a small check, to trigger escalationEscalation: Handing a case from an agent to a person, with the context needed to continue..
  3. One interface. Your app calls llm.call(route, ...); the router picks local or cloud.
  4. Same evalsEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. for both. Run your eval set on each route (Part 3).
  5. Observe. Log route, reason, latencyLatency: The time from sending a request until you get the response, or until the first token arrives when streaming. and outcome (chapter 67).

Example

A note-taking app summarises meetings on the laptop by default (private, offline). For a long legal document the user explicitly shares, it asks before sending a redactedRedaction: Removing or masking sensitive data, such as PII or secrets, before it is stored, logged or sent. version to Claude for deeper analysis, and shows which model answered.

Watch for

  • Different behaviour between models confusing users; keep formats consistent with structured outputsStructured outputs: Making a model return data that matches a defined schema, such as JSON with required fields and types..
  • Quiet drift when a local model is updated; pin versions and re-run evals.

Key points

  • Hybrid setups run some requests locally and send others to a cloud model such as Claude.
  • Route by data sensitivity, difficulty, connectivity and cost.
  • Fall back to the cloud when the local model is unsure, overloaded or offline, but only for data allowed to leave.
  • Keep one interface in your app so the route is configuration, and log every routing decision.
Hands-on labRuns in the Playground

Build a router with a privacy hard limit

Route requests between a local model, a cloud model and a person, without ever leaking private data.

You will have: A route() function, a log of five routed requests with reasons, and a leak check that prints 0.

Steps

  1. Read the five requests: whether the data may leave, how hard the task is, the local model's state, and whether you are offline.
  2. Make the data rule the first check: private data never goes to the cloud.
  3. Handle offline, then send hard tasks or an unsure local model to the cloud.
  4. Run it and confirm the leak check prints 0.

Done when

  • Request 1 (private, hard, busy) stays local.
  • Request 4 (private, local model failing) goes to a person.
  • The script prints private requests sent to cloud: 0.

Open in the Playground No API key needed.

Starter code (Python)
# A hybrid router: data rules first, then difficulty, then the local model's state.
def route(req):
    # TODO: if the data may not leave, never return "cloud". Use "local", or "person" if the local model is failing.
    # TODO: if offline, return "local".
    # TODO: send hard tasks, or tasks where the local model is unsure or failing, to "cloud".
    if req["hard"]:
        return "cloud", "hard task"
    return "local", "default"


requests_ = [
    {"id": 1, "may_leave": False, "hard": True, "local_state": "busy", "offline": False},
    {"id": 2, "may_leave": True, "hard": False, "local_state": "ok", "offline": False},
    {"id": 3, "may_leave": True, "hard": True, "local_state": "ok", "offline": False},
    {"id": 4, "may_leave": False, "hard": False, "local_state": "failing", "offline": False},
    {"id": 5, "may_leave": True, "hard": True, "local_state": "ok", "offline": True},
]

log = []
for r in requests_:
    where, why = route(r)
    log.append((r["id"], where, why))
    print(f"request {r['id']}: {where:<6} because {why}")

leaks = [i for i, where, _ in log if where == "cloud" and not requests_[i - 1]["may_leave"]]
print("private requests sent to cloud:", len(leaks))
Show a solution
# A hybrid router: data rules first, then difficulty, then the local model's state.
def route(req):
    if not req["may_leave"]:
        if req["local_state"] == "failing":
            return "person", "data must stay local and the local model cannot do it"
        return "local", "data must stay local" + (" (queued while busy)" if req["local_state"] == "busy" else "")
    if req["offline"]:
        return "local", "offline: run locally or save for later"
    if req["hard"] or req["local_state"] in ("failing", "unsure"):
        return "cloud", "hard task or unsure local model, and the data may leave"
    return "local", "easy and allowed: cheaper and private"


requests_ = [
    {"id": 1, "may_leave": False, "hard": True, "local_state": "busy", "offline": False},
    {"id": 2, "may_leave": True, "hard": False, "local_state": "ok", "offline": False},
    {"id": 3, "may_leave": True, "hard": True, "local_state": "ok", "offline": False},
    {"id": 4, "may_leave": False, "hard": False, "local_state": "failing", "offline": False},
    {"id": 5, "may_leave": True, "hard": True, "local_state": "ok", "offline": True},
]

log = []
for r in requests_:
    where, why = route(r)
    log.append((r["id"], where, why))
    print(f"request {r['id']}: {where:<6} because {why}")

leaks = [i for i, where, _ in log if where == "cloud" and not requests_[i - 1]["may_leave"]]
print("private requests sent to cloud:", len(leaks))
Quick checkThe local model is overloaded, and the request contains data that must not leave the device. What should happen?
How sure are you?
Pick an answer and how sure you are