strands.types.session
Data models for session management.
SessionType
Section titled “SessionType”class SessionType(str, Enum)Defined in: src/strands/types/session.py:17
Enumeration of session types.
As sessions are expanded to support new use cases like multi-agent patterns, new types will be added here.
encode_bytes_values
Section titled “encode_bytes_values”def encode_bytes_values(obj: Any) -> AnyDefined in: src/strands/types/session.py:27
Recursively encode any bytes values in an object to base64.
Handles dictionaries, lists, and nested structures.
decode_bytes_values
Section titled “decode_bytes_values”def decode_bytes_values(obj: Any) -> AnyDefined in: src/strands/types/session.py:42
Recursively decode any base64-encoded bytes values in an object.
Handles dictionaries, lists, and nested structures.
SessionMessage
Section titled “SessionMessage”@dataclassclass SessionMessage()Defined in: src/strands/types/session.py:58
Message within a SessionAgent.
Attributes:
message- Message contentmessage_id- Index of the message in the conversation historyredact_message- If the original message is redacted, this is the new content to usecreated_at- ISO format timestamp for when this message was createdupdated_at- ISO format timestamp for when this message was last updated
from_message
Section titled “from_message”@classmethoddef from_message(cls, message: Message, index: int) -> "SessionMessage"Defined in: src/strands/types/session.py:76
Convert from a Message, base64 encoding bytes values.
to_message
Section titled “to_message”def to_message() -> MessageDefined in: src/strands/types/session.py:85
Convert SessionMessage back to a Message, decoding any bytes values.
If the message was redacted, return the redact content instead.
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, env: dict[str, Any]) -> "SessionMessage"Defined in: src/strands/types/session.py:96
Initialize a SessionMessage from a dictionary, ignoring keys that are not class parameters.
to_dict
Section titled “to_dict”def to_dict() -> dict[str, Any]Defined in: src/strands/types/session.py:101
Convert the SessionMessage to a dictionary representation.
SessionAgent
Section titled “SessionAgent”@dataclassclass SessionAgent()Defined in: src/strands/types/session.py:107
Agent that belongs to a Session.
Attributes:
agent_id- Unique id for the agent.state- User managed state.conversation_manager_state- State for conversation management.created_at- Created at time.updated_at- Updated at time.
from_agent
Section titled “from_agent”@classmethoddef from_agent(cls, agent: "LocalAgent") -> "SessionAgent"Defined in: src/strands/types/session.py:126
Convert a local agent to a SessionAgent.
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, env: dict[str, Any]) -> "SessionAgent"Defined in: src/strands/types/session.py:150
Initialize a SessionAgent from a dictionary, ignoring keys that are not class parameters.
to_dict
Section titled “to_dict”def to_dict() -> dict[str, Any]Defined in: src/strands/types/session.py:155
Convert the SessionAgent to a dictionary representation.
initialize_internal_state
Section titled “initialize_internal_state”def initialize_internal_state(agent: "LocalAgent") -> NoneDefined in: src/strands/types/session.py:159
Restore internal state for Agent instances.
Session
Section titled “Session”@dataclassclass Session()Defined in: src/strands/types/session.py:173
Session data model.
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, env: dict[str, Any]) -> "Session"Defined in: src/strands/types/session.py:182
Initialize a Session from a dictionary, ignoring keys that are not class parameters.
to_dict
Section titled “to_dict”def to_dict() -> dict[str, Any]Defined in: src/strands/types/session.py:186
Convert the Session to a dictionary representation.