---
title: "Build and measure the assembler"
lesson_id: "05"
---

# Build and measure the assembler

- **Lesson ID:** 05
- **Goal:** Combine budget, pack, and Dynamic Profile, then log leftover tokens.
- **Human lesson:** [05-build-the-assembler.html](05-build-the-assembler.html)

## Prerequisites

- Lessons 02 through 04.

## Inputs, outputs, and artifacts

- **Inputs:** Question, candidate slices, allow-listed tools.
- **Outputs:** Response text plus leftover and slice count.

## Agent build steps

1. Build the budget, pack, and Profile in one function.
2. Precondition that packed tokens fit leftover.
3. Create `LanguageModelSession(profile:)`.
4. Log leftover tokens and usage if available.
5. Compare packed versus unpacked on one question.
6. Cite [WWDC26 241](https://developer.apple.com/videos/play/wwdc2026/241/) and [WWDC26 242](https://developer.apple.com/videos/play/wwdc2026/242/) lightly.

## Constraints

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

## Key concepts

- `ContextAssembler` wires budget, rank, and Profile into one `ask()` function.
- The pipeline is budget, rank, one active Profile, respond, measure.
- Create `LanguageModelSession(profile:)` then `session.respond(to:)`.
- Log leftover tokens, slice ids, and usage if available.

## Takeaways

- Refuse an overfull pack before you call the model.
- Compare packed versus unpacked on the same question.
- Zero slices when files were needed is a retrieval miss, not a packer win.

## Acceptance checks

- Assembler function is shown.
- Overfull pack is refused.
- Agent brief link is present.
