strands.types.session
Data models for session management.
SessionType
Section titled “SessionType”class SessionType(str, Enum)Defined in: src/strands/types/session.py:18
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:28
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:43
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:59
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:77
Convert from a Message, base64 encoding bytes values.
to_message
Section titled “to_message”def to_message() -> MessageDefined in: src/strands/types/session.py:86
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:97
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:102
Convert the SessionMessage to a dictionary representation.
SessionAgent
Section titled “SessionAgent”@dataclassclass SessionAgent()Defined in: src/strands/types/session.py:108
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: "Agent") -> "SessionAgent"Defined in: src/strands/types/session.py:127
Convert an Agent to a SessionAgent.
from_bidi_agent
Section titled “from_bidi_agent”@classmethoddef from_bidi_agent(cls, agent: "BidiAgent") -> "SessionAgent"Defined in: src/strands/types/session.py:141
Convert a BidiAgent to a SessionAgent.
Arguments:
agent- BidiAgent to convert
Returns:
SessionAgent with empty conversation_manager_state (BidiAgent doesn’t use conversation manager)
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, env: dict[str, Any]) -> "SessionAgent"Defined in: src/strands/types/session.py:166
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:170
Convert the SessionAgent to a dictionary representation.
initialize_internal_state
Section titled “initialize_internal_state”def initialize_internal_state(agent: "Agent") -> NoneDefined in: src/strands/types/session.py:174
Initialize internal state of agent.
initialize_bidi_internal_state
Section titled “initialize_bidi_internal_state”def initialize_bidi_internal_state(agent: "BidiAgent") -> NoneDefined in: src/strands/types/session.py:179
Initialize internal state of BidiAgent.
Arguments:
agent- BidiAgent to initialize internal state for
Session
Section titled “Session”@dataclassclass Session()Defined in: src/strands/types/session.py:192
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:201
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:205
Convert the Session to a dictionary representation.