liveBook · Manning

TaskStepResult

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

TaskStepResult is a framework data structure containing the result of executing one agent sub-step.

TaskStepResult records the result of one agent sub-step, rather than the result of the overall task. A sub-step starts with a TaskStep instruction and can involve LLM planning and tool calls; its result helps determine what happens next. section 4.2.1

The Python implementation is a Pydantic BaseModel with two fields:

  • task_step_id: the identifier of the TaskStep that was executed. section 4.2.2
  • content: the step’s result as a string. Converting the object to a string returns this content. section 4.2.2
Listing 4.5 Implementing TaskStep, TaskStepResult and NextStepDecision
# llm_agents_from_scratch/data_structures/agent.py
… #A
 
… #B
 
class TaskStep(BaseModel):
    """Represents a step within a task and its own instruction.""" #C
 
    id_: str = Field(
        default_factory=lambda: str(uuid.uuid4())
    )
    task_id: str #D
    instruction: str = Field(
        description="The instruction for this step in the task.",
    )
 
    def __str__(self) -> str:
        """String representation of TaskStep."""
        return self.instruction
 
 
class TaskStepResult(BaseModel):
    """The result of a task step execution."""
 
    task_step_id: str
    content: str
 
    def __str__(self) -> str:
        """String representation of TaskStepResult."""
        return self.content
 
 
class NextStepDecision(BaseModel):
    """Structured output used within TaskHandler.get_next_step()."""
 
    kind: Literal["next_step", "final_result"] #E
    content: str = Field(
        description=(
            "Content for the next step of the task execution. Or, the "
            "the final result."
        ),
    )

The listing defines TaskStepResult alongside the step and decision structures used by the processing loop. section 4.2.2

TaskHandler.run_step() returns a TaskStepResult. The loop passes the previous result to get_next_step(), which returns either another TaskStep to execute or a TaskResult for the completed task. With no previous result, get_next_step() creates the initial step from the task instruction. The loop can also stop on an error or a maximum-step limit. section 4.2.3

The result is distinct from the rollout: after each sub-step, the handler formats the step’s chat history and appends it to the rollout, maintaining a history of task execution. section 4.2.3

Inspecting a supervised step

For a Hailstone sequence starting at 4, a human operator obtains a TaskStep, optionally edits it, and calls run_step(). One returned TaskStepResult contains the step’s ID and the content “I need to call the next_number tool with x=4.” The operator can inspect it before passing it to get_next_step() and continuing until a TaskResult is available. section 8.4.2

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

How deep it goes
Defines the two-field model and string conversion, then traces its use through step execution and next-step selection.
Examples
Uses a supervised Hailstone-sequence task to inspect a step result requesting a next_number tool call.
What you can do after
Builds it from scratch as a model and uses it to advance or inspect agent task execution.
How it connects
Connects LLM agents, tool calling, processing loops, and human-in-the-loop supervision.

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.