State is what the agent needs to remember within one task.
The goal, the steps already completed, the results returned, the errors hit.
The simplest approach is to keep everything in the conversation.
That works and consumes context fast, since every tool result stays forever.
A twenty-step run can fill a large window with material long since irrelevant.
Keeping state outside the conversation lets you control what the model sees.
A structured record of steps and results can be summarised into a few lines.
The model then sees a compact status rather than a full transcript.
That costs less, and it keeps the important parts away from the middle of a long context.
Decide explicitly what to carry forward and what to drop.
Failed attempts are worth keeping, or the agent will retry them.
Losing state mid-task makes agents repeat work or contradict themselves.
Persisting it also lets a long task resume after a crash.
Store it somewhere queryable so a human can inspect a stuck run.
State is separate from memory, which is what persists between tasks rather than within one.