Skip to content

aea.protocols.base

This module contains the base message and serialization definition.

Message Objects

class Message()

This class implements a message.

protocol_id

type: PublicId

protocol_specification_id

type: PublicId

serializer

type: Type["Serializer"]

Performative Objects

class Performative(Enum)

Performatives for the base message.

__str__

def __str__() -> str

Get the string representation.

__init__

def __init__(_body: Optional[Dict] = None, **kwargs: Any) -> None

Initialize a Message object.

Arguments:

  • _body: the dictionary of values to hold.
  • kwargs: any additional value to add to the body. It will overwrite the body values.

json

def json() -> dict

Get json friendly str representation of the message.

from_json

@classmethod
def from_json(cls, data: dict) -> "Message"

Construct message instance from json data.

valid_performatives

@property
def valid_performatives() -> Set[str]

Get valid performatives.

has_sender

@property
def has_sender() -> bool

Check if it has a sender.

sender

@property
def sender() -> Address

Get the sender of the message in Address form.

sender

@sender.setter
def sender(sender: Address) -> None

Set the sender of the message.

has_to

@property
def has_to() -> bool

Check if it has a sender.

to

@property
def to() -> Address

Get address of receiver.

to

@to.setter
def to(to: Address) -> None

Set address of receiver.

dialogue_reference

@property
def dialogue_reference() -> Tuple[str, str]

Get the dialogue_reference of the message.

message_id

@property
def message_id() -> int

Get the message_id of the message.

performative

@property
def performative() -> "Performative"

Get the performative of the message.

target

@property
def target() -> int

Get the target of the message.

set

def set(key: str, value: Any) -> None

Set key and value pair.

Arguments:

  • key: the key.
  • value: the value.

get

def get(key: str) -> Optional[Any]

Get value for key.

is_set

def is_set(key: str) -> bool

Check value is set for key.

__eq__

def __eq__(other: Any) -> bool

Compare with another object.

__repr__

def __repr__() -> str

Get the representation of the message.

__str__

def __str__() -> str

Get the string representation of the message. Abbreviated to prevent spamming of logs.

encode

def encode() -> bytes

Encode the message.

decode

@classmethod
def decode(cls, data: bytes) -> "Message"

Decode the message.

has_dialogue_info

@property
def has_dialogue_info() -> bool

Check whether a message has the dialogue fields populated.

More precisely, it checks whether the fields 'message_id', 'target' and 'dialogue_reference' are set.

Returns:

True if the message has the dialogue fields set, False otherwise.

Encoder Objects

class Encoder(ABC)

Encoder interface.

encode

@staticmethod
@abstractmethod
def encode(msg: Message) -> bytes

Encode a message.

Arguments:

  • msg: the message to be encoded.

Returns:

the encoded message.

Decoder Objects

class Decoder(ABC)

Decoder interface.

decode

@staticmethod
@abstractmethod
def decode(obj: bytes) -> Message

Decode a message.

Arguments:

  • obj: the sequence of bytes to be decoded.

Returns:

the decoded message.

Serializer Objects

class Serializer(Encoder, Decoder, ABC)

The implementations of this class defines a serialization layer for a protocol.

Protocol Objects

class Protocol(Component)

This class implements a specifications for a protocol.

It includes a serializer to encode/decode a message.

__init__

def __init__(configuration: ProtocolConfig, message_class: Type[Message],
             **kwargs: Any) -> None

Initialize the protocol manager.

Arguments:

  • configuration: the protocol configurations.
  • message_class: the message class.
  • kwargs: the keyword arguments.

serializer

@property
def serializer() -> Type[Serializer]

Get the serializer.

from_dir

@classmethod
def from_dir(cls, directory: str, **kwargs: Any) -> "Protocol"

Load the protocol from a directory.

Arguments:

  • directory: the directory to the skill package.
  • kwargs: the keyword arguments.

Returns:

the protocol object.

from_config

@classmethod
def from_config(cls, configuration: ProtocolConfig,
                **kwargs: Any) -> "Protocol"

Load the protocol from configuration.

Arguments:

  • configuration: the protocol configuration.
  • kwargs: the keyword arguments.

Returns:

the protocol object.

protocol_id

@property
def protocol_id() -> PublicId

Get protocol id.

protocol_specification_id

@property
def protocol_specification_id() -> PublicId

Get protocol specification id.

__repr__

def __repr__() -> str

Get str representation of the protocol.