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.
AgentResult
Section titled “AgentResult”@dataclassclass 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.
__str__
Section titled “__str__”def __str__() -> strDefined in: src/strands/agent/agent_result.py:38
Return a string representation of the agent result.
Priority order:
- Interrupts (if present) → stringified list of interrupt dicts
- Structured output (if present) → JSON string
- Text content from message → concatenated text blocks
Returns:
String representation based on the priority order above.
from_dict
Section titled “from_dict”@classmethoddef 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@
to_dict
Section titled “to_dict”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