Execution loop

ConceptResponsibility
ThreadKeep one conversation and its history in a fixed workspace
TurnExecute an admitted prompt or worker-result report
StepInvoke the executor once and record its output

Main requests, worker tasks, and result collection share the same execution machinery.

One cycle

Admit input
  → Apply pending model selection
  → Capture context and consume queued input
  → Request a model response
  → Validate completion
  → Execute requested tools in order
  → Record the step
  → Continue with tool results, or finish

The captured settings and tool router govern both the model request and its tool calls. A tool result becomes input to the next step. Turns continue until completion, failure, interruption, or an explicitly configured step limit.

Progress and committed history

Text streams to the browser while the response is arriving. Core validates the complete response before executing its requested tools, then records history and publishes lifecycle events. Partial streamed text is provisional.

Input and failure

Next-step input steers an active turn. Next-turn input waits in the browser until the conversation is idle. Agent messages are read at step boundaries and do not start an idle conversation.

Tool errors return to the model as results it can act on. Provider failures end the turn while retaining completed steps and tool effects. Child interruption cancels execution and preserves history for later reuse.

Implementation: session/turn.rs.