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

# Build the orchestrator

- **Lesson ID:** 04
- **Goal:** Run a capped loop that packs, responds, and stops at done.
- **Human lesson:** [04-build-the-orchestrator.html](04-build-the-orchestrator.html)

## Prerequisites

- Lessons 02 and 03.

## Inputs, outputs, and artifacts

- **Inputs:** User text.
- **Outputs:** Final text, step log, stop reason.

## Agent build steps

1. Reset to gather.
2. Loop until done or maxSteps.
3. Build the session from the current Profile.
4. Pack state-specific facts before respond.
5. Log each mode.

## Constraints

No LangChain. Cap required. No em dashes.

## Key concepts

- The orchestrator owns state, session, and a `maxSteps` cap.
- The loop is pack, respond, maybe change mode, stop at done or cap.
- Pack state-specific facts before `respond`.
- A loop without a step cap is a battery leak.

## Takeaways

- The cap is mandatory.
- Confirm whether the SDK keeps transcript across Profile changes on one session.
- Do not copy a LangGraph checkpointer.

## Acceptance checks

- Loop and cap are shown.
- Agent brief link is present.
