One turn of the agent loop

One turn of the agent loop A workflow diagram generated by Archify. 01 / Composer · AgentLoop.run_turn · transcript EX / Hooks (tighten only) EX / Gate and tools Intake Provider round (repeat) Finish Composer · message · @ · pastes · Composer · AgentLoop.run_turn · transcript › Intake Composer message · @ · pastes Prepare turn · @ under the gate · Composer · AgentLoop.run_turn · transcript › Intake · checkpoint turn Prepare turn @ under the gate checkpoint turn Context catalog · budget · compact · rebuild · Composer · AgentLoop.run_turn · transcript › Provider round (repeat) Context catalog budget · compact · rebuild Provider round · stream text + calls · Composer · AgentLoop.run_turn · transcript › Provider round (repeat) Provider round stream text + calls Finish · append to session JSONL · Composer · AgentLoop.run_turn · transcript › Finish Finish append to session JSONL Transcript · reply + activity feed · Composer · AgentLoop.run_turn · transcript › Finish Transcript reply + activity feed PreToolUse hooks · deny · ask · allow ignored · Hooks (tighten only) › Provider round (repeat) PreToolUse hooks deny · ask · allow ignored PostToolUse hooks · context on the result · Hooks (tighten only) › Finish PostToolUse hooks context on the result PermissionGate · allow · deny · ask · Gate and tools › Provider round (repeat) PermissionGate allow · deny · ask Approval card · once · session · project · Gate and tools › Finish Approval card once · session · project Run tools · parallel when safe · Gate and tools › Finish Run tools parallel when safe allowed ask tool calls not denied no tool calls request results, next round send Legend User UI Agent logic Policy Tool action Cloud service

The loop

  • • core/loop.py yields AgentEvents; TUI and dave run render them
  • • Rounds repeat until no calls or max_tool_rounds

Gate and tools

  • • Denied calls return a denial as the tool result
  • • Checkpoints snapshot files before writes, for /rewind

Task boundaries and time

  • • Busy switches wait or cancel; output and queued input stay with the old conversation
  • • One device lease counts model and tool work, not permission waits; off-clock turns are agent time