---
title: "Write cost, latency, and quality rules"
lesson_id: "02"
---

# Write cost, latency, and quality rules

- **Lesson ID:** 02
- **Goal:** Encode task class, privacy, latency, and reasoning into a choose function.
- **Human lesson:** [02-cost-latency-quality-rules.html](02-cost-latency-quality-rules.html)

## Prerequisites

- Lesson 01 model types.

## Inputs, outputs, and artifacts

- **Inputs:** A RouteRule and an availability set.
- **Outputs:** A key: system, pcc, or coreai.

## Agent build steps

1. Define task classes: classify, extract, draft, plan, customStyle.
2. Block PCC when privacy is mustStayOnDevice.
3. Prefer system for short, fast jobs.
4. Prefer PCC when deep reasoning is required and allowed.
5. Prefer Core AI for a baked custom job.

## Constraints

Rules in code. No em dashes.

## 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.

## Acceptance checks

- choose() is shown.
- Privacy can block PCC.
- Agent brief link is present.
