get_next_step() is an asynchronous TaskHandler method that selects the next TaskStep or returns a final TaskResult. In the agent’s processing loop, it alternates with run_step(): the latter executes each step and supplies a TaskStepResult for the next decision. section 4.2.3 section 4.5
The decision depends on the preceding state:
- With no previous result, return a TaskStep carrying the task ID and original instruction. section 4.2.3
- After a step, use the backbone LLM to decide whether another sub-step is needed or the task is complete. The decision prompt includes the original instruction and current rollout, a log of earlier sub-steps. section 4.2.3 section 4.5
- After a rejected result in the approval-enabled flow, bypass LLM routing and return a TaskStep that incorporates the operator’s feedback. section 8.3.1
Figure 4.11 The get_next_step() execution to produce either a TaskStep or TaskResult

The decision flow shows how get_next_step() produces either a TaskStep or a TaskResult. section 4.2.3
The loop stops when it receives a TaskResult or encounters another stopping condition, such as an irrecoverable error or a maximum step count. When result approval is enabled, a proposed TaskResult is sent to the operator. Approval completes the task; rejection re-enters the loop with feedback for a revision. section 4.2.3 section 8.3.1
Supervised execution
For a Hailstone sequence starting at 4, call get_next_step(None) to obtain the first TaskStep. Inspect or modify it, run it with run_step(), and pass the returned TaskStepResult to get_next_step(). Continue until it returns a TaskResult, then accept that result with complete(). A TaskStep is not a valid argument to complete(). section 8.4.2
