← All courses ← Course home

Lesson 02 of 05

Write cost, latency, and quality rules

Pick a model with numbers you can defend: expected milliseconds, tokens, privacy, and a quality floor.

Agent brief (llms.md)

PCC is not a credit-card invoice in your app, but it is still a larger, slower, networked call. On-device is cheaper in battery when the prompt is short. A custom Core AI model is worth it when quality on your job beats the system model, not because the file is large.

TaskClassify the job
LimitsLatency + privacy
FloorQuality bar
enum TaskClass: String, Sendable {
    case classify, extract, draft, plan, customStyle
}

enum PrivacyBound: String, Sendable {
    case mustStayOnDevice
    case applePCCAllowed
}

struct RouteRule: Sendable {
    var task: TaskClass
    var privacy: PrivacyBound
    var maxMilliseconds: Int
    var needsDeepReasoning: Bool
    var prefersCustomCoreAI: Bool
}

func choose(_ rule: RouteRule, available: Set<String>) -> String {
    if rule.privacy == .mustStayOnDevice {
        if rule.prefersCustomCoreAI, available.contains("coreai") { return "coreai" }
        return "system"
    }
    if rule.needsDeepReasoning, available.contains("pcc") { return "pcc" }
    if rule.maxMilliseconds <= 800 { return "system" }
    if rule.prefersCustomCoreAI, available.contains("coreai") { return "coreai" }
    return available.contains("system") ? "system" : "pcc"
}

Start with four task classes:

If privacy is mustStayOnDevice, PCC is illegal for that request even if quality would rise. That is a product rule, not a model score.

Write the rule in code. A comment in a View is not a router.

Next, attach the choice to a Profile modifier.

Key concepts

  • Task classes include classify, extract, draft, plan, and custom style.
  • Privacy is mustStayOnDevice or applePCCAllowed.
  • A RouteRule encodes max latency, deep reasoning, and custom Core AI.
  • If privacy is mustStayOnDevice, PCC is illegal even if quality would rise.

Takeaways

  • Write the rule in code. A comment in a View is not a router.
  • Classify and extract go on-device first. Plan can use PCC with deep reasoning.
  • Custom style goes to Core AI when that file is present.