Stop Conditions
The agent loop stops whenExecutionState::shouldStop() returns true. This is controlled by ExecutionContinuation, StopSignals, and AgentStopException.
Default Stop Logic
The loop stops when:- A
StopSignalis present and no continuation is requested, OR - There are no pending tool calls (LLM gave a final response)
StopSignal
A signal requesting the loop to stop, with a reason and context:StopReason
AgentStopException
Throw from a tool to immediately stop the loop:ExecutionContinuation
Manages the interplay between stop signals and continuation requests:shouldStop()- true if signals exist and no continuation requestedisContinuationRequested()- true if a hook requested continuation- Hooks can override stop signals by calling
$state->withExecutionContinued()
Emitting Stop Signals from Hooks
Guard hooks emit stop signals by modifying state:shouldStop() after each step and breaks if true.