Skip to content

strands.agent.agent_result

Agent result handling for SDK.

This module defines the AgentResult class which encapsulates the complete response from an agent’s processing cycle.

@dataclass
class AgentResult()

Defined in: src/strands/agent/agent_result.py:19

Represents the last result of invoking an agent with a prompt.

Attributes:

  • stop_reason - The reason why the agent’s processing stopped.
  • message - The last message generated by the agent.
  • metrics - Performance metrics collected during processing.
  • state - Additional state information from the event loop.
  • interrupts - List of interrupts if raised by user.
  • structured_output - Parsed structured output when structured_output_model was specified.
def __str__() -> str

Defined in: src/strands/agent/agent_result.py:38

Return a string representation of the agent result.

Priority order:

  1. Interrupts (if present) → stringified list of interrupt dicts
  2. Structured output (if present) → JSON string
  3. Text content from message → concatenated text blocks

Returns:

String representation based on the priority order above.

@classmethod
def from_dict(cls, data: dict[str, Any]) -> "AgentResult"

Defined in: src/strands/agent/agent_result.py:71

Rehydrate an AgentResult from persisted JSON.

Arguments:

  • data - Dictionary containing the serialized AgentResult data

Returns:

AgentResult instance

Raises:

  • TypeError - If the data format is invalid@
def to_dict() -> dict[str, Any]

Defined in: src/strands/agent/agent_result.py:89

Convert this AgentResult to JSON-serializable dictionary.

Returns:

Dictionary containing serialized AgentResult data