Step Results
The _get_single_step_result_from_response
method is a core orchestration function in the AgentRunner
class that processes a model response and determines what should happen next in the agent workflow
Purpose and Functionality¶
This method serves as the bridge between receiving a model response and executing the appropriate actions based on that response. It takes a raw ModelResponse
and converts it into a structured SingleStepResult
that contains all the information needed to continue the agent execution loop
The method performs two key operations:
-
Response Processing: It calls
RunImpl.process_model_response()
to parse the model's output into structured actions like tool calls, handoffs, and computer actions -
Tool Use Tracking and Execution: It updates the
AgentToolUseTracker
with tools used, then executesRunImpl.execute_tools_and_side_effects()
to run any tools that were called and determine the next step in the workflow
Usage in the Execution Flow¶
The method is called in two critical places in the agent execution system:
Non-Streaming Execution¶
In the standard execution path, it's called after getting a new response from the model in _run_single_turn()
Streaming Execution¶
In streaming mode, it's called after the streaming response is complete to process the final result in _run_single_turn_streamed()
Return Value and Decision Making¶
The method returns a SingleStepResult
that contains a next_step
field indicating what should happen next, The execution loop then uses this to decide whether to:
- Continue the loop (
NextStepRunAgain
) - when tools were executed but no final output was determined - Hand off to another agent (
NextStepHandoff
) - when a handoff tool was called - Terminate with final output (
NextStepFinalOutput
) - when the agent produces structured output or completes without more tools to run
Method Signature and Parameters¶
The method accepts comprehensive parameters including the agent, all available tools, original input, pre-step items, the new response, output schema, handoffs, hooks, context wrapper, run config, and tool use tracker
Notes¶
This method is essential to the turn-based execution model where each "turn" represents one model invocation plus all resulting side effects. It encapsulates the complex logic of determining what actions to take based on the model's response and ensures the agent workflow continues appropriately. The method also handles tool use tracking to support features like automatic tool choice reset to prevent infinite loops.