Step 1 of 5
Define the loop contract
Write down exactly what one turn of the loop does before coding it.
Design the core loop for a single-agent system and write it as a contract before implementation. Specify: (1) INPUT: system prompt + message history + tool registry. (2) TURN: send to model; the model returns either final text or one or more tool calls. (3) EXECUTE: run each tool call in order, capture result or error. (4) FOLD: append tool results as tool-role messages, preserving call order and IDs. (5) TERMINATE: stop on explicit finish, max N turns, or K consecutive tool failures. Produce this as a short design doc with a state diagram and the exact message shapes you will use.
Expected after this step
A one-page loop contract with message shapes and termination rules.
Should not happen
- ✕Building an orchestration framework before a single loop works
- ✕Dropping or reordering tool results so the model loses causality
- ✕No termination condition - the agent loops forever on a stuck task
- ✕Swallowing tool errors instead of showing them to the model
Verify before continuing
Do not move on until every check is true. The complete button stays locked until then.
Do not continue if…
- !Building an orchestration framework before a single loop works
- !Dropping or reordering tool results so the model loses causality
- !No termination condition - the agent loops forever on a stuck task
- !Swallowing tool errors instead of showing them to the model
If the AI messes this up
Use this when the AI fakes progress or breaks the feature. It forces a real fix.
The design jumped straight to classes and frameworks. Rewrite it as the sequence of messages exchanged in one turn - if you cannot write the transcript by hand, the design is not ready.