---
title: "Build the router"
lesson_id: "04"
---

# Build the router

- **Lesson ID:** 04
- **Goal:** Probe availability, choose a route, create one session, and log the key.
- **Human lesson:** [04-build-the-router.html](04-build-the-router.html)

## Prerequisites

- Lessons 02 and 03.

## Inputs, outputs, and artifacts

- **Inputs:** Question and RouteRule.
- **Outputs:** Answer text and a printed route key.

## Agent build steps

1. Probe system, PCC, and Core AI availability with documented APIs.
2. Call choose().
3. Build LanguageModelSession with RoutedProfile.
4. Keep the router out of the view.
5. Replace the placeholder isUsable before ship.

## Constraints

Illustrative Swift. iOS 27 and macOS 27. No em dashes.

## Key concepts

- The router probes availability, chooses a route, builds a session, and logs the key.
- Replace stub availability with the real API. Do not ship always-true.
- Keep the router out of SwiftUI views.
- Probe availability once per request path.

## Takeaways

- The view sends a rule. The router returns text and a logged key.
- You cannot tune rules without a trace.
- Confirm initializer and availability names in the Xcode 27 SDK.

## Acceptance checks

- Router type is shown.
- Availability is probed.
- Agent brief link is present.
