Skip to content

Commit

Permalink
Merge pull request #2476 from fetchai/feature/agent_registration
Browse files Browse the repository at this point in the history
AEA-1494 Ensure Genus and Classification registration in all skills
  • Loading branch information
DavidMinarsch authored Apr 30, 2021
2 parents 4bc5ff0 + 5fb6e15 commit 70f07ce
Show file tree
Hide file tree
Showing 59 changed files with 2,395 additions and 511 deletions.
96 changes: 69 additions & 27 deletions docs/generic-skills-step-by-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Open the `behaviours.py` file (`my_generic_seller/skills/generic_seller/behaviou
``` python
from typing import Any, Optional, cast

from aea.helpers.search.models import Description
from aea.skills.behaviours import TickerBehaviour

from packages.fetchai.connections.ledger.base import (
Expand Down Expand Up @@ -163,14 +164,15 @@ class GenericServiceRegistrationBehaviour(TickerBehaviour):

self.failed_registration_msg = None

def _register_agent(self) -> None:
def _register(self, description: Description, logger_msg: str) -> None:
"""
Register the agent's location.
Register something on the SOEF.
:param description: the description of what is being registered
:param logger_msg: the logger message to print after the registration
:return: None
"""
strategy = cast(GenericStrategy, self.context.strategy)
description = strategy.get_location_description()
oef_search_dialogues = cast(
OefSearchDialogues, self.context.oef_search_dialogues
)
Expand All @@ -180,31 +182,51 @@ class GenericServiceRegistrationBehaviour(TickerBehaviour):
service_description=description,
)
self.context.outbox.put_message(message=oef_search_msg)
self.context.logger.info("registering agent on SOEF.")
self.context.logger.info(logger_msg)

def register_service_personality_classification(self) -> None:
def _register_agent(self) -> None:
"""
Register the agent's service, personality and classification.
Register the agent's location.
:return: None
"""
strategy = cast(GenericStrategy, self.context.strategy)
descriptions = [
strategy.get_register_service_description(),
strategy.get_register_personality_description(),
strategy.get_register_classification_description(),
]
oef_search_dialogues = cast(
OefSearchDialogues, self.context.oef_search_dialogues
description = strategy.get_location_description()
self._register(description, "registering agent on SOEF.")

def register_service(self) -> None:
"""
Register the agent's service.
:return: None
"""
strategy = cast(GenericStrategy, self.context.strategy)
description = strategy.get_register_service_description()
self._register(description, "registering agent's service on the SOEF.")

def register_genus(self) -> None:
"""
Register the agent's personality genus.
:return: None
"""
strategy = cast(GenericStrategy, self.context.strategy)
description = strategy.get_register_personality_description()
self._register(
description, "registering agent's personality genus on the SOEF."
)

def register_classification(self) -> None:
"""
Register the agent's personality classification.
:return: None
"""
strategy = cast(GenericStrategy, self.context.strategy)
description = strategy.get_register_classification_description()
self._register(
description, "registering agent's personality classification on the SOEF."
)
for description in descriptions:
oef_search_msg, _ = oef_search_dialogues.create(
counterparty=self.context.search_service_address,
performative=OefSearchMessage.Performative.REGISTER_SERVICE,
service_description=description,
)
self.context.outbox.put_message(message=oef_search_msg)
self.context.logger.info("registering service on SOEF.")

def _unregister_service(self) -> None:
"""
Expand Down Expand Up @@ -833,12 +855,32 @@ class GenericOefSearchHandler(Handler):
target_message.performative
== OefSearchMessage.Performative.REGISTER_SERVICE
):
if "location" in target_message.service_description.values:
registration_behaviour = cast(
GenericServiceRegistrationBehaviour,
self.context.behaviours.service_registration,
description = target_message.service_description
data_model_name = description.data_model.name
registration_behaviour = cast(
GenericServiceRegistrationBehaviour,
self.context.behaviours.service_registration,
)
if "location_agent" in data_model_name:
registration_behaviour.register_service()
elif "set_service_key" in data_model_name:
registration_behaviour.register_genus()
elif (
"personality_agent" in data_model_name
and description.values["piece"] == "genus"
):
registration_behaviour.register_classification()
elif (
"personality_agent" in data_model_name
and description.values["piece"] == "classification"
):
self.context.logger.info(
"the agent, with its genus and classification, and its service are successfully registered on the SOEF."
)
else:
self.context.logger.warning(
f"received soef SUCCESS message as a reply to the following unexpected message: {target_message}"
)
registration_behaviour.register_service_personality_classification()

def _handle_error(
self,
Expand Down
5 changes: 5 additions & 0 deletions docs/simple-oef-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ service_description = Description(
)
```

<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Currently, the soef does not allow for multiple registrations to be combined into a single command.
</div>

## Perform a search

To perform a search for services registered you have to define a search query consisting of constraints. The location constraints is required, personality pieces or services keys constraints are optional.
Expand Down
Loading

0 comments on commit 70f07ce

Please sign in to comment.