liveBook · Manning

Get_next_step()

As explained in Build a Multi-Agent System (from Scratch)

get_next_step() is an asynchronous TaskHandler method that determines the next TaskStep or returns the final TaskResult.

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

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Implements initial-step construction and LLM-based routing, then extends the method to handle rejected results.
Examples
Uses Hailstone sequences to demonstrate supervised stepping and revision after an operator rejects a proposed result.
What you can do after
Build it from scratch as an asynchronous task-routing method and apply it in a supervised execution loop.
How it connects
Connects agent loops, LLM planning, rollouts, tool calling, and human-in-the-loop approval.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Multi-Agent System (from Scratch). The section links point to the parts of the book it draws on.