-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from valory-xyz/feat/strategy
Implement tool selection strategy
- v0.21.4
- v0.21.3
- v0.21.2
- v0.21.1
- v0.21.0
- v0.20.0
- v0.19.1
- v0.19.0
- v0.18.8
- v0.18.7
- v0.18.6
- v0.18.5
- v0.18.4
- v0.18.3
- v0.18.2
- v0.18.1
- v0.18.0
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.5
- v0.16.4
- v0.16.3
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.1
- v0.14.0
- v0.13.1
- v0.13.0
- v0.12.9
- v0.12.8
- v0.12.7
- v0.12.6
- v0.12.5
- v0.12.4
- v0.12.3
- v0.12.2
- v0.12.1
- v0.12.0
- v0.11.7
- v0.11.6
- v0.11.5
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.14
- v0.9.13
- v0.9.12
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.2.post1
- v0.9.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.1.0-rc46.1
- test-v0.12.0
Showing
36 changed files
with
1,958 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""This module contains the support resources for the agent registry contract.""" |
1,046 changes: 1,046 additions & 0 deletions
1,046
packages/valory/contracts/agent_registry/build/AgentRegistry.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""This module contains the class to connect to the Agent Registry contract.""" | ||
|
||
from aea.common import JSONLike | ||
from aea.configurations.base import PublicId | ||
from aea.contracts.base import Contract | ||
from aea.crypto.base import LedgerApi | ||
|
||
|
||
class AgentRegistryContract(Contract): | ||
"""The Agent Registry contract.""" | ||
|
||
contract_id = PublicId.from_str("valory/agent_registry:0.1.0") | ||
|
||
@classmethod | ||
def get_hash( | ||
cls, | ||
ledger_api: LedgerApi, | ||
contract_address: str, | ||
agent_id: int, | ||
) -> JSONLike: | ||
"""Retrieve an operator given its agent instance.""" | ||
|
||
contract_instance = cls.get_instance(ledger_api, contract_address) | ||
res = contract_instance.functions.getHashes(agent_id).call() | ||
# ensure that the returned object has the expected format | ||
if len(res) != 2: | ||
msg = f"The `getHashes` method for {contract_address=} returned data in an unexpected format: {res}" | ||
return dict(error=msg) | ||
|
||
# get the agent hashes | ||
hashes = res.pop(-1) | ||
# ensure that there are hashes returned for the agent | ||
if len(hashes) == 0: | ||
msg = f"The `getHashes` method for {contract_address=} returned no hashes for {agent_id=}: {res}" | ||
return dict(error=msg) | ||
|
||
# get the most recent agent hash | ||
hash_ = hashes.pop(-1) | ||
# ensure that the hash is in bytes | ||
if not isinstance(hash_, bytes): | ||
msg = f"The `getHashes` method for {contract_address=} returned non-bytes {hash_=} for {agent_id=}: {res}" | ||
return dict(error=msg) | ||
|
||
# return the hash in hex | ||
return dict(hash=hash_.hex()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: agent_registry | ||
author: valory | ||
version: 0.1.0 | ||
type: contract | ||
description: Agent Registry contract | ||
license: Apache-2.0 | ||
aea_version: '>=1.0.0, <2.0.0' | ||
fingerprint: | ||
__init__.py: bafybeid3wfzglolebuo6jrrsopswzu4lk77bm76mvw3euizlsjtnt3wmgu | ||
build/AgentRegistry.json: bafybeicoe5elvvsv2neiirsdn4uddrilizmyib3x4mvpklr7olhj2kh4ue | ||
contract.py: bafybeihrv6blme3v6diwci6zxxn72qbg5sanzmfq5tobhs4375ebcuyday | ||
fingerprint_ignore_patterns: [] | ||
contracts: [] | ||
class_name: AgentRegistryContract | ||
contract_interface_paths: | ||
ethereum: build/AgentRegistry.json | ||
dependencies: | ||
open-aea-ledger-ethereum: | ||
version: ==1.38.0 | ||
open-aea-test-autonomy: | ||
version: ==0.12.0 | ||
open-aea-web3: | ||
version: ==6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
224 changes: 224 additions & 0 deletions
224
packages/valory/skills/decision_maker_abci/behaviours/tool_selection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""This module contains the behaviour of the skill which is responsible for selecting a mech tool.""" | ||
|
||
import json | ||
from typing import Any, Dict, Generator, List, Optional | ||
|
||
from packages.valory.contracts.agent_registry.contract import AgentRegistryContract | ||
from packages.valory.protocols.contract_api import ContractApiMessage | ||
from packages.valory.skills.abstract_round_abci.base import get_name | ||
from packages.valory.skills.decision_maker_abci.behaviours.base import ( | ||
CID_PREFIX, | ||
DecisionMakerBaseBehaviour, | ||
WaitableConditionType, | ||
) | ||
from packages.valory.skills.decision_maker_abci.models import AgentToolsSpecs | ||
from packages.valory.skills.decision_maker_abci.payloads import ToolSelectionPayload | ||
from packages.valory.skills.decision_maker_abci.policy import EGreedyPolicy | ||
from packages.valory.skills.decision_maker_abci.states.tool_selection import ( | ||
ToolSelectionRound, | ||
) | ||
|
||
|
||
class ToolSelectionBehaviour(DecisionMakerBaseBehaviour): | ||
"""A behaviour in which the agents select a mech tool.""" | ||
|
||
matching_round = ToolSelectionRound | ||
|
||
def __init__(self, **kwargs: Any) -> None: | ||
"""Initialize Behaviour.""" | ||
super().__init__(**kwargs) | ||
self._mech_id: int = 0 | ||
self._mech_hash: str = "" | ||
self._mech_tools: Optional[List[str]] = None | ||
|
||
@property | ||
def mech_id(self) -> int: | ||
"""Get the mech's id.""" | ||
return self._mech_id | ||
|
||
@mech_id.setter | ||
def mech_id(self, mech_id: int) -> None: | ||
"""Set the mech's id.""" | ||
self._mech_id = mech_id | ||
|
||
@property | ||
def mech_hash(self) -> str: | ||
"""Get the hash of the mech agent.""" | ||
return self._mech_hash | ||
|
||
@mech_hash.setter | ||
def mech_hash(self, mech_hash: str) -> None: | ||
"""Set the hash of the mech agent.""" | ||
self._mech_hash = mech_hash | ||
|
||
@property | ||
def mech_tools(self) -> List[str]: | ||
"""Get the mech agent's tools.""" | ||
if self._mech_tools is None: | ||
raise ValueError("The mech's tools have not been set.") | ||
return self._mech_tools | ||
|
||
@mech_tools.setter | ||
def mech_tools(self, mech_tools: List[str]) -> None: | ||
"""Set the mech agent's tools.""" | ||
self._mech_tools = mech_tools | ||
|
||
@property | ||
def utilized_tools(self) -> Dict[str, int]: | ||
"""Get the utilized tools.""" | ||
if self.is_first_period: | ||
return {} | ||
return self.synchronized_data.utilized_tools | ||
|
||
@property | ||
def mech_tools_api(self) -> AgentToolsSpecs: | ||
"""Get the mech agent api specs.""" | ||
return self.context.agent_tools | ||
|
||
def set_mech_agent_specs(self) -> None: | ||
"""Set the mech's agent specs.""" | ||
full_ipfs_hash = CID_PREFIX + self.mech_hash | ||
ipfs_link = self.params.ipfs_address + full_ipfs_hash | ||
# The url needs to be dynamically generated as it depends on the ipfs hash | ||
self.mech_tools_api.__dict__["_frozen"] = False | ||
self.mech_tools_api.url = ipfs_link | ||
self.mech_tools_api.__dict__["_frozen"] = True | ||
|
||
def _get_mech_id(self) -> WaitableConditionType: | ||
"""Get the mech's id.""" | ||
result = yield from self._mech_contract_interact( | ||
contract_callable="get_mech_id", | ||
data_key="id", | ||
placeholder=get_name(ToolSelectionBehaviour.mech_id), | ||
) | ||
|
||
return result | ||
|
||
def _get_mech_hash(self) -> WaitableConditionType: | ||
"""Get the mech's hash.""" | ||
result = yield from self.contract_interact( | ||
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore | ||
contract_address=self.params.agent_registry_address, | ||
contract_public_id=AgentRegistryContract.contract_id, | ||
contract_callable="get_hash", | ||
data_key="hash", | ||
placeholder=get_name(ToolSelectionBehaviour.mech_hash), | ||
agent_id=self.mech_id, | ||
) | ||
return result | ||
|
||
def _get_mech_tools(self) -> WaitableConditionType: | ||
"""Get the mech agent's tools from IPFS.""" | ||
self.set_mech_agent_specs() | ||
specs = self.mech_tools_api.get_spec() | ||
res_raw = yield from self.get_http_response(**specs) | ||
res = self.mech_tools_api.process_response(res_raw) | ||
|
||
if self.mech_tools_api.is_retries_exceeded(): | ||
error = "Retries were exceeded while trying to get the mech agent's data." | ||
self.context.logger.error(error) | ||
return True | ||
|
||
if res is None: | ||
msg = f"Could not get the mech agent's tools from {self.mech_tools_api.api_id}" | ||
self.context.logger.error(msg) | ||
self.mech_tools_api.increment_retries() | ||
return False | ||
|
||
self.context.logger.info(f"Retrieved the mech agent's tools: {res}.") | ||
# keep only the relevant mech tools, sorted | ||
# we sort the tools to avoid using dictionaries in the policy implementation, | ||
# so that we can easily assess which index corresponds to which tool | ||
res = sorted(set(res) - self.params.irrelevant_tools) | ||
self.context.logger.info(f"Relevant tools to the prediction task: {res}.") | ||
|
||
if len(res) == 0: | ||
self.context.logger.error("The relevant mech agent's tools are empty!") | ||
return False | ||
self.mech_tools = res | ||
self.mech_tools_api.reset_retries() | ||
return True | ||
|
||
def _get_tools( | ||
self, | ||
) -> Generator[None, None, None]: | ||
"""Get the Mech's tools.""" | ||
for step in ( | ||
self._get_mech_id, | ||
self._get_mech_hash, | ||
self._get_mech_tools, | ||
): | ||
yield from self.wait_for_condition_with_sleep(step) | ||
|
||
def _adjust_policy_tools(self) -> None: | ||
"""Add or remove tools from the policy to match the remote tools.""" | ||
local = self.synchronized_data.available_mech_tools | ||
|
||
# remove tools if they are not available anymore | ||
# process the indices in reverse order to avoid index shifting when removing the unavailable tools later | ||
reversed_idx = range(len(local) - 1, -1, -1) | ||
removed_idx = [idx for idx in reversed_idx if local[idx] not in self.mech_tools] | ||
self.policy.remove_tools(removed_idx) | ||
|
||
# add tools if there are new ones available | ||
# process the indices in reverse order to avoid index shifting when adding the new tools later | ||
reversed_idx = range(len(self.mech_tools) - 1, -1, -1) | ||
new_idx = [idx for idx in reversed_idx if self.mech_tools[idx] not in local] | ||
self.policy.add_new_tools(new_idx) | ||
|
||
def _set_policy(self) -> None: | ||
"""Set the E Greedy Policy.""" | ||
if self.is_first_period: | ||
n_relevant = len(self.mech_tools) | ||
self._policy = EGreedyPolicy.initial_state(self.params.epsilon, n_relevant) | ||
else: | ||
self._policy = self.synchronized_data.policy | ||
self._adjust_policy_tools() | ||
|
||
def _select_tool(self) -> Generator[None, None, Optional[int]]: | ||
"""Select a Mech tool based on an e-greedy policy and return its index.""" | ||
yield from self._get_tools() | ||
self._set_policy() | ||
selected = self.policy.select_tool() | ||
self.context.logger.info(f"Selected the mech tool {selected!r}.") | ||
return selected | ||
|
||
def async_act(self) -> Generator: | ||
"""Do the action.""" | ||
|
||
with self.context.benchmark_tool.measure(self.behaviour_id).local(): | ||
mech_tools = policy = utilized_tools = None | ||
selected_tool = yield from self._select_tool() | ||
if selected_tool is not None: | ||
mech_tools = json.dumps(self.mech_tools) | ||
policy = self.policy.serialize() | ||
utilized_tools = json.dumps(self.utilized_tools, sort_keys=True) | ||
|
||
payload = ToolSelectionPayload( | ||
self.context.agent_address, | ||
mech_tools, | ||
policy, | ||
utilized_tools, | ||
selected_tool, | ||
) | ||
|
||
yield from self.finish_behaviour(payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""This module contains an Epsilon Greedy Policy implementation.""" | ||
|
||
import json | ||
import random | ||
from dataclasses import asdict, dataclass, is_dataclass | ||
from typing import Any, List, Optional | ||
|
||
|
||
class DataclassEncoder(json.JSONEncoder): | ||
"""A custom JSON encoder for dataclasses.""" | ||
|
||
def default(self, o: Any) -> Any: | ||
"""The default JSON encoder.""" | ||
if is_dataclass(o): | ||
return asdict(o) | ||
return super().default(o) | ||
|
||
|
||
def argmax(li: List) -> int: | ||
"""Get the index of the max value within the provided list.""" | ||
return li.index((max(li))) | ||
|
||
|
||
@dataclass | ||
class EGreedyPolicy: | ||
"""An e-Greedy policy for the tool selection.""" | ||
|
||
eps: float | ||
counts: List[int] | ||
rewards: List[float] | ||
initial_value = 0 | ||
|
||
@classmethod | ||
def initial_state(cls, eps: float, n_tools: int) -> "EGreedyPolicy": | ||
"""Return an instance on its initial state.""" | ||
if n_tools <= 0 or eps > 1 or eps < 0: | ||
error = f"Cannot initialize an e Greedy Policy with {eps=} and {n_tools=}" | ||
raise ValueError(error) | ||
|
||
return EGreedyPolicy( | ||
eps, | ||
[cls.initial_value] * n_tools, | ||
[float(cls.initial_value)] * n_tools, | ||
) | ||
|
||
@classmethod | ||
def deserialize(cls, policy: str) -> "EGreedyPolicy": | ||
"""Deserialize a string to an `EGreedyPolicy` object.""" | ||
return EGreedyPolicy(**json.loads(policy)) | ||
|
||
@property | ||
def n_tools(self) -> int: | ||
"""Get the number of the policy's tools.""" | ||
return len(self.counts) | ||
|
||
@property | ||
def random_tool(self) -> int: | ||
"""Get the index of a tool randomly.""" | ||
return random.randrange(self.n_tools) # nosec | ||
|
||
@property | ||
def has_updated(self) -> bool: | ||
"""Whether the policy has ever been updated since its genesis or not.""" | ||
return sum(self.counts) > 0 | ||
|
||
@property | ||
def reward_rates(self) -> List[float]: | ||
"""Get the reward rates.""" | ||
return [ | ||
reward / count if count > 0 else 0 | ||
for reward, count in zip(self.rewards, self.counts) | ||
] | ||
|
||
@property | ||
def best_tool(self) -> int: | ||
"""Get the best tool.""" | ||
return argmax(self.reward_rates) | ||
|
||
def add_new_tools(self, indexes: List[int], avoid_shift: bool = False) -> None: | ||
"""Add new tools to the current policy.""" | ||
if avoid_shift: | ||
indexes = sorted(indexes, reverse=True) | ||
|
||
for i in indexes: | ||
self.counts.insert(i, self.initial_value) | ||
self.rewards.insert(i, float(self.initial_value)) | ||
|
||
def remove_tools(self, indexes: List[int], avoid_shift: bool = False) -> None: | ||
"""Remove the knowledge for the tools corresponding to the given indexes.""" | ||
if avoid_shift: | ||
indexes = sorted(indexes, reverse=True) | ||
|
||
for i in indexes: | ||
try: | ||
del self.counts[i] | ||
del self.rewards[i] | ||
except IndexError as exc: | ||
error = "Attempted to remove tools using incorrect indexes!" | ||
raise ValueError(error) from exc | ||
|
||
def select_tool(self) -> Optional[int]: | ||
"""Select a Mech tool and return its index.""" | ||
if self.n_tools == 0: | ||
return None | ||
|
||
if sum(self.counts) == 0 or random.random() < self.eps: # nosec | ||
return self.random_tool | ||
|
||
return self.best_tool | ||
|
||
def add_reward(self, index: int, reward: float) -> None: | ||
"""Add a reward for the tool corresponding to the given index.""" | ||
self.counts[index] += 1 | ||
self.rewards[index] += reward | ||
|
||
def serialize(self) -> str: | ||
"""Return the policy serialized.""" | ||
return json.dumps(self, cls=DataclassEncoder, sort_keys=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/valory/skills/decision_maker_abci/states/tool_selection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""This module contains the tool selection state of the decision-making abci app.""" | ||
|
||
from packages.valory.skills.abstract_round_abci.base import ( | ||
CollectSameUntilThresholdRound, | ||
get_name, | ||
) | ||
from packages.valory.skills.decision_maker_abci.payloads import ToolSelectionPayload | ||
from packages.valory.skills.decision_maker_abci.states.base import ( | ||
Event, | ||
SynchronizedData, | ||
) | ||
|
||
|
||
class ToolSelectionRound(CollectSameUntilThresholdRound): | ||
"""A round for selecting a Mech tool.""" | ||
|
||
payload_class = ToolSelectionPayload | ||
synchronized_data_class = SynchronizedData | ||
done_event = Event.DONE | ||
none_event = Event.NONE | ||
no_majority_event = Event.NO_MAJORITY | ||
selection_key = ( | ||
get_name(SynchronizedData.available_mech_tools), | ||
get_name(SynchronizedData.policy), | ||
get_name(SynchronizedData.utilized_tools), | ||
get_name(SynchronizedData.mech_tool_idx), | ||
) | ||
collection_key = get_name(SynchronizedData.participant_to_selection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters