Skip to content

Commit

Permalink
feat: rename mech_acn -> acn_data_share
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Jun 13, 2023
1 parent adc815a commit a6dd84d
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 154 deletions.
32 changes: 32 additions & 0 deletions packages/valory/protocols/acn_data_share/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ACN Data share protocol

## Description

This protocol provides support for sharing raw data using ACN

## Specification

```yaml
---
name: acn_data_share
author: valory
version: 0.1.0
description: A protocol for sharing raw data using ACN.
license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
protocol_specification_id: valory/acn_data_share:0.1.0
speech_acts:
data:
request_id: pt:str
content: pt:str
...
---
initiation: [data]
reply:
data: []
termination: [data]
roles: {agent,skill}
end_states: [successful, failed]
keep_terminal_state_dialogues: false
...
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
# ------------------------------------------------------------------------------

"""
This module contains the support resources for the mech_acn protocol.
This module contains the support resources for the acn_data_share protocol.
It was created with protocol buffer compiler version `libprotoc 3.19.4` and aea protocol generator version `1.0.0`.
"""

from packages.valory.protocols.mech_acn.message import MechAcnMessage
from packages.valory.protocols.mech_acn.serialization import MechAcnSerializer
from packages.valory.protocols.acn_data_share.message import AcnDataShareMessage
from packages.valory.protocols.acn_data_share.serialization import (
AcnDataShareSerializer,
)


MechAcnMessage.serializer = MechAcnSerializer
AcnDataShareMessage.serializer = AcnDataShareSerializer
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";

package aea.valory.mech_acn.v0_1_0;
package aea.valory.acn_data_share.v0_1_0;

message MechAcnMessage{
message AcnDataShareMessage{

// Performatives and contents
message Data_Performative{
Expand Down
54 changes: 54 additions & 0 deletions packages/valory/protocols/acn_data_share/acn_data_share_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
# ------------------------------------------------------------------------------

"""
This module contains the classes required for mech_acn dialogue management.
This module contains the classes required for acn_data_share dialogue management.
- MechAcnDialogue: The dialogue class maintains state of a dialogue and manages it.
- MechAcnDialogues: The dialogues class keeps track of all dialogues.
- AcnDataShareDialogue: The dialogue class maintains state of a dialogue and manages it.
- AcnDataShareDialogues: The dialogues class keeps track of all dialogues.
"""

from abc import ABC
Expand All @@ -31,30 +31,30 @@
from aea.protocols.base import Message
from aea.protocols.dialogue.base import Dialogue, DialogueLabel, Dialogues

from packages.valory.protocols.mech_acn.message import MechAcnMessage
from packages.valory.protocols.acn_data_share.message import AcnDataShareMessage


class MechAcnDialogue(Dialogue):
"""The mech_acn dialogue class maintains state of a dialogue and manages it."""
class AcnDataShareDialogue(Dialogue):
"""The acn_data_share dialogue class maintains state of a dialogue and manages it."""

INITIAL_PERFORMATIVES: FrozenSet[Message.Performative] = frozenset(
{MechAcnMessage.Performative.DATA}
{AcnDataShareMessage.Performative.DATA}
)
TERMINAL_PERFORMATIVES: FrozenSet[Message.Performative] = frozenset(
{MechAcnMessage.Performative.DATA}
{AcnDataShareMessage.Performative.DATA}
)
VALID_REPLIES: Dict[Message.Performative, FrozenSet[Message.Performative]] = {
MechAcnMessage.Performative.DATA: frozenset(),
AcnDataShareMessage.Performative.DATA: frozenset(),
}

class Role(Dialogue.Role):
"""This class defines the agent's role in a mech_acn dialogue."""
"""This class defines the agent's role in a acn_data_share dialogue."""

AGENT = "agent"
SKILL = "skill"

class EndState(Dialogue.EndState):
"""This class defines the end states of a mech_acn dialogue."""
"""This class defines the end states of a acn_data_share dialogue."""

SUCCESSFUL = 0
FAILED = 1
Expand All @@ -64,7 +64,7 @@ def __init__(
dialogue_label: DialogueLabel,
self_address: Address,
role: Dialogue.Role,
message_class: Type[MechAcnMessage] = MechAcnMessage,
message_class: Type[AcnDataShareMessage] = AcnDataShareMessage,
) -> None:
"""
Initialize a dialogue.
Expand All @@ -83,11 +83,11 @@ def __init__(
)


class MechAcnDialogues(Dialogues, ABC):
"""This class keeps track of all mech_acn dialogues."""
class AcnDataShareDialogues(Dialogues, ABC):
"""This class keeps track of all acn_data_share dialogues."""

END_STATES = frozenset(
{MechAcnDialogue.EndState.SUCCESSFUL, MechAcnDialogue.EndState.FAILED}
{AcnDataShareDialogue.EndState.SUCCESSFUL, AcnDataShareDialogue.EndState.FAILED}
)

_keep_terminal_state_dialogues = False
Expand All @@ -96,7 +96,7 @@ def __init__(
self,
self_address: Address,
role_from_first_message: Callable[[Message, Address], Dialogue.Role],
dialogue_class: Type[MechAcnDialogue] = MechAcnDialogue,
dialogue_class: Type[AcnDataShareDialogue] = AcnDataShareDialogue,
) -> None:
"""
Initialize dialogues.
Expand All @@ -109,7 +109,7 @@ def __init__(
self,
self_address=self_address,
end_states=cast(FrozenSet[Dialogue.EndState], self.END_STATES),
message_class=MechAcnMessage,
message_class=AcnDataShareMessage,
dialogue_class=dialogue_class,
role_from_first_message=role_from_first_message,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# ------------------------------------------------------------------------------

"""This module contains mech_acn's message definition."""
"""This module contains acn_data_share's message definition."""

# pylint: disable=too-many-statements,too-many-locals,no-member,too-few-public-methods,too-many-branches,not-an-iterable,unidiomatic-typecheck,unsubscriptable-object
import logging
Expand All @@ -28,19 +28,21 @@
from aea.protocols.base import Message


_default_logger = logging.getLogger("aea.packages.valory.protocols.mech_acn.message")
_default_logger = logging.getLogger(
"aea.packages.valory.protocols.acn_data_share.message"
)

DEFAULT_BODY_SIZE = 4


class MechAcnMessage(Message):
"""A protocol for adding ACN callbacks on AI mechs."""
class AcnDataShareMessage(Message):
"""A protocol for sharing raw data using ACN."""

protocol_id = PublicId.from_str("valory/mech_acn:0.1.0")
protocol_specification_id = PublicId.from_str("valory/mech_acn:0.1.0")
protocol_id = PublicId.from_str("valory/acn_data_share:0.1.0")
protocol_specification_id = PublicId.from_str("valory/acn_data_share:0.1.0")

class Performative(Message.Performative):
"""Performatives for the mech_acn protocol."""
"""Performatives for the acn_data_share protocol."""

DATA = "data"

Expand Down Expand Up @@ -70,7 +72,7 @@ def __init__(
**kwargs: Any,
):
"""
Initialise an instance of MechAcnMessage.
Initialise an instance of AcnDataShareMessage.
:param message_id: the message id.
:param dialogue_reference: the dialogue reference.
Expand All @@ -82,7 +84,7 @@ def __init__(
dialogue_reference=dialogue_reference,
message_id=message_id,
target=target,
performative=MechAcnMessage.Performative(performative),
performative=AcnDataShareMessage.Performative(performative),
**kwargs,
)

Expand All @@ -107,7 +109,7 @@ def message_id(self) -> int:
def performative(self) -> Performative: # type: ignore # noqa: F821
"""Get the performative of the message."""
enforce(self.is_set("performative"), "performative is not set.")
return cast(MechAcnMessage.Performative, self.get("performative"))
return cast(AcnDataShareMessage.Performative, self.get("performative"))

@property
def target(self) -> int:
Expand All @@ -128,7 +130,7 @@ def request_id(self) -> str:
return cast(str, self.get("request_id"))

def _is_consistent(self) -> bool:
"""Check that the message follows the mech_acn protocol."""
"""Check that the message follows the acn_data_share protocol."""
try:
enforce(
isinstance(self.dialogue_reference, tuple),
Expand Down Expand Up @@ -164,7 +166,7 @@ def _is_consistent(self) -> bool:
# Light Protocol Rule 2
# Check correct performative
enforce(
isinstance(self.performative, MechAcnMessage.Performative),
isinstance(self.performative, AcnDataShareMessage.Performative),
"Invalid 'performative'. Expected either of '{}'. Found '{}'.".format(
self.valid_performatives, self.performative
),
Expand All @@ -173,7 +175,7 @@ def _is_consistent(self) -> bool:
# Check correct contents
actual_nb_of_contents = len(self._body) - DEFAULT_BODY_SIZE
expected_nb_of_contents = 0
if self.performative == MechAcnMessage.Performative.DATA:
if self.performative == AcnDataShareMessage.Performative.DATA:
expected_nb_of_contents = 2
enforce(
isinstance(self.request_id, str),
Expand Down
21 changes: 21 additions & 0 deletions packages/valory/protocols/acn_data_share/protocol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: acn_data_share
author: valory
version: 0.1.0
protocol_specification_id: valory/acn_data_share:0.1.0
type: protocol
description: A protocol for sharing raw data using ACN.
license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeiexqywrjzv4ajzesbzaw7bujvmgadsqtxzfnerwqogi7nz6jcvp6u
__init__.py: bafybeidkszn5crtpejlyfx3urgcubywrhq72ni3wn532mcutt3kk237daq
acn_data_share.proto: bafybeiell3oa6eo2oogbgymu5cupeakbkpkmxkh7gossgy4jdip7lrr7tu
acn_data_share_pb2.py: bafybeiamh6xu6fmsitjzcxy6zmacsp5fff4tgc24ujbuzx4vjyd5twfkle
dialogues.py: bafybeigtnzvicosvctjk67qni5mu3yy77fp5u2xpb2eszwfht7igeaip4m
message.py: bafybeie3coddm7v4m7utlxy6rlaef4wg6cg5nq36unx4dc2noolp5bnaty
serialization.py: bafybeigmposkg5bdsdb2hyfafgmedlwcwcrujyiueytolxjdmqqyjp7lmm
tests/test_acn_data_share_dialogues.py: bafybeie5kcwchjl5vozdlrnwhmim4kffa7fr5zsqjy3r27mjzuilaog5su
tests/test_acn_data_share_messages.py: bafybeifap2cnraojc4ohd46rrjgusi6iisjm5tum2bs4sfgdocx5zjsqea
fingerprint_ignore_patterns: []
dependencies:
protobuf: {}
Loading

0 comments on commit a6dd84d

Please sign in to comment.