aea.protocols.base

This module contains the base message and serialization definition.

Message Objects

class Message()

This class implements a message.

Performative Objects

class Performative(Enum)

Performatives for the base message.

__str__

 | __str__()

Get the string representation.

__init__

 | __init__(body: Optional[Dict] = None, **kwargs)

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.

has_sender

 | @property
 | has_sender() -> bool

Check if it has a sender.

sender

 | @property
 | sender() -> Address

Get the sender of the message in Address form.

:return the address

sender

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

Set the sender of the message.

has_to

 | @property
 | has_to() -> bool

Check if it has a sender.

to

 | @property
 | to() -> Address

Get address of receiver.

to

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

Set address of receiver.

body

 | @property
 | body() -> Dict

Get the body of the message (in dictionary form).

Returns:

the body

body

 | @body.setter
 | body(body: Dict) -> None

Set the body of hte message.

Arguments:

  • body: the body.

Returns:

None

dialogue_reference

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

Get the dialogue_reference of the message.

message_id

 | @property
 | message_id() -> int

Get the message_id of the message.

performative

 | @property
 | performative() -> "Performative"

Get the performative of the message.

target

 | @property
 | target() -> int

Get the target of the message.

set

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

Set key and value pair.

Arguments:

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

Returns:

None

get

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

Get value for key.

is_set

 | is_set(key: str) -> bool

Check value is set for key.

__eq__

 | __eq__(other)

Compare with another object.

__str__

 | __str__()

Get the string representation of the message.

encode

 | encode() -> bytes

Encode the message.

Encoder Objects

class Encoder(ABC)

Encoder interface.

encode

 | @staticmethod
 | @abstractmethod
 | 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
 | 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.

ProtobufSerializer Objects

class ProtobufSerializer(Serializer)

Default Protobuf serializer.

It assumes that the Message contains a JSON-serializable body.

encode

 | @staticmethod
 | encode(msg: Message) -> bytes

Encode a message into bytes using Protobuf.

decode

 | @staticmethod
 | decode(obj: bytes) -> Message

Decode bytes into a message using Protobuf.

Protocol Objects

class Protocol(Component)

This class implements a specifications for a protocol.

It includes a serializer to encode/decode a message.

__init__

 | __init__(configuration: ProtocolConfig, message_class: Type[Message], **kwargs)

Initialize the protocol manager.

Arguments:

  • configuration: the protocol configurations.
  • message_class: the message class.

serializer

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

Get the serializer.

from_dir

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

Load the protocol from a directory.

Arguments:

  • directory: the directory to the skill package.

Returns:

the protocol object.

from_config

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

Load the protocol from configuration.

Arguments:

  • configuration: the protocol configuration.

Returns:

the protocol object.