Skip to content

Commit

Permalink
Merge pull request #37 from dvilelaf/feat/round-info
Browse files Browse the repository at this point in the history
Feat/round info
  • Loading branch information
dvilelaf authored Dec 3, 2024
2 parents dde0bdc + 6c8a231 commit da099be
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/dvilela/agents/memeooorr/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeihq2yenstblmaadzcjousowj5kfn5l7ns5pxweq2gcrsczfyq5wzm
- valory/registration_abci:0.1.0:bafybeicnth5q4httefsusywx3zrrq4al47owvge72dqf2fziruicq6hqta
- valory/reset_pause_abci:0.1.0:bafybeievjciqdvxhqxfjd4whqs27h6qbxqzrae7wwj7fpvxlvmtw3x35im
- dvilela/memeooorr_abci:0.1.0:bafybeihlhmxryhaahfifxatt3lejqpsrbhm3a2ipamm2fygnybhy62olzu
- dvilela/memeooorr_chained_abci:0.1.0:bafybeiczw2uly5awhzmpzjbdmbhsu6hhfsigqsseivxwk3ooe7ssvyfoo4
- dvilela/memeooorr_abci:0.1.0:bafybeigfhi5k3fiodiyjbhy54lqcjjgiojtljlnzfnbhfkilg7slcz6ocu
- dvilela/memeooorr_chained_abci:0.1.0:bafybeie4vem72o3m5iryggjbzfkukdcyqrj74ov7qdyjwc4wmxycu6n44u
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down
2 changes: 1 addition & 1 deletion packages/dvilela/services/memeooorr/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeiaekcmielp6mb4qvmo2twwkpmoun36bqajrh7wnnkcpdnia45ycl4
fingerprint_ignore_patterns: []
agent: dvilela/memeooorr:0.1.0:bafybeiczczqg7ubzk5k2r5zu4esdjxo4fdq3qomseplf2mirgzugmgjuje
agent: dvilela/memeooorr:0.1.0:bafybeiempli5guocheudowojeqlh335zoe4lpuxas6f3cecxbcwhx2ia6q
number_of_agents: 1
deployment:
agent:
Expand Down
34 changes: 34 additions & 0 deletions packages/dvilela/skills/memeooorr_abci/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@
import re
from datetime import datetime
from enum import Enum
from pathlib import Path
from typing import Callable, Dict, List, Optional, Tuple, Union, cast
from urllib.parse import urlparse

import yaml
from aea.configurations.data_types import PublicId
from aea.protocols.base import Message

from packages.dvilela.protocols.kv_store.message import KvStoreMessage
from packages.dvilela.skills.memeooorr_abci.dialogues import HttpDialogue, HttpDialogues
from packages.dvilela.skills.memeooorr_abci.models import SharedState
from packages.dvilela.skills.memeooorr_abci.rounds import SynchronizedData
from packages.dvilela.skills.memeooorr_abci.rounds_info import ROUNDS_INFO
from packages.valory.connections.http_server.connection import (
PUBLIC_ID as HTTP_SERVER_PUBLIC_ID,
)
Expand Down Expand Up @@ -70,6 +73,24 @@
IpfsHandler = BaseIpfsHandler


def camel_to_snake(camel_str: str) -> str:
"""Converts from CamelCase to snake_case"""
snake_str = re.sub(r"(?<!^)(?=[A-Z])", "_", camel_str).lower()
return snake_str


def load_fsm_spec() -> Dict:
"""Load the chained FSM spec"""
with open(
Path(__file__).parent.parent
/ "memeooorr_chained_abci"
/ "fsm_specification.yaml",
"r",
encoding="utf-8",
) as spec_file:
return yaml.safe_load(spec_file)


class SrrHandler(AbstractResponseHandler):
"""A class for handling SRR messages."""

Expand Down Expand Up @@ -141,6 +162,18 @@ def setup(self) -> None:
self.json_content_header = "Content-Type: application/json\n" # pylint: disable=attribute-defined-outside-init
self.html_content_header = "Content-Type: text/html\n" # pylint: disable=attribute-defined-outside-init

# Load round info for the healthcheck
fsm = load_fsm_spec()

self.rounds_info: Dict = { # pylint: disable=attribute-defined-outside-init
camel_to_snake(k): v for k, v in ROUNDS_INFO.items()
}
for source_info, target_round in fsm["transition_func"].items():
source_round, event = source_info[1:-1].split(", ")
self.rounds_info[camel_to_snake(source_round)]["transitions"][
event.lower()
] = camel_to_snake(target_round)

@property
def synchronized_data(self) -> SynchronizedData:
"""Return the synchronized data."""
Expand Down Expand Up @@ -307,6 +340,7 @@ def _handle_get_health(
"reset_pause_duration": self.context.params.reset_pause_duration,
"rounds": rounds,
"is_transitioning_fast": is_transitioning_fast,
"rounds_info": self.rounds_info,
}

self._send_ok_response(http_msg, http_dialogue, data)
Expand Down
159 changes: 159 additions & 0 deletions packages/dvilela/skills/memeooorr_abci/rounds_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2024 David Vilela Freire
#
# 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 information about the rounds that is used by the Http handler."""


ROUNDS_INFO = {
"ActionDecisionRound": {
"name": "Taking a decision on what to do with the token",
"description": "Takes a decision about whether to interact with other tokens",
"transitions": {},
},
"ActionPreparationRound": {
"name": "Preparing the token action transaction",
"description": "Prepares a transaction to unleash, hearth, collect or burn a token",
"transitions": {},
},
"ActionTweetRound": {
"name": "Tweeting about the token action",
"description": "Publishes a tweet announcing the performed token action",
"transitions": {},
},
"AnalizeFeedbackRound": {
"name": "Analyzing Twitter feedback",
"description": "Analyzes responses to agent tweets and extracts feedback from them",
"transitions": {},
},
"CheckFundsRound": {
"name": "Checking funds",
"description": "Checks the agetn has enough funds to send a transaction",
"transitions": {},
},
"CheckLateTxHashesRound": {
"name": "Checking late transaction hashes",
"description": "Checks late transaction hashes",
"transitions": {},
},
"CheckTransactionHistoryRound": {
"name": "Checking the transaction history",
"description": "Checks the transaction history",
"transitions": {},
},
"CollectFeedbackRound": {
"name": "Collecting feedback from Twitter",
"description": "Collects responses to agent tweets",
"transitions": {},
},
"CollectSignatureRound": {
"name": "Collecting agent signatures",
"description": "Collects agent signatures for a transaction",
"transitions": {},
},
"DeploymentRound": {
"name": "Preparing a token deployment",
"description": "Prepares a token deployment transaction",
"transitions": {},
},
"EngageRound": {
"name": "Engaging with other agents",
"description": "Responds to tweets from other agents",
"transitions": {},
},
"FinalizationRound": {
"name": "Sending a transaction",
"description": "Sends a transaction for mining",
"transitions": {},
},
"LoadDatabaseRound": {
"name": "Loading the database",
"description": "Loads the database",
"transitions": {},
},
"PostAnnouncementRound": {
"name": "Twitting about the token deployment",
"description": "Publishes a tweet about the token deployment",
"transitions": {},
},
"PostTweetRound": {
"name": "Publishing a tweet",
"description": "Publishes a tweet",
"transitions": {},
},
"PullMemesRound": {
"name": "Pulling other tokens from the subgraph",
"description": "Pulls other tokens from the subgraph",
"transitions": {},
},
"RandomnessTransactionSubmissionRound": {
"name": "Getting some randomness",
"description": "Gets randomness from a decentralized randomness source",
"transitions": {},
},
"RegistrationRound": {
"name": "Registering agents ",
"description": "Initializes the agent registration process",
"transitions": {},
},
"RegistrationStartupRound": {
"name": "Registering agents at startup",
"description": "Initializes the agent registration process",
"transitions": {},
},
"ResetAndPauseRound": {
"name": "Cleaning up and sleeping for some time",
"description": "Cleans up and sleeps for some time before running again",
"transitions": {},
},
"ResetRound": {
"name": "Cleaning up and resetting",
"description": "Cleans up and resets the agent",
"transitions": {},
},
"SelectKeeperTransactionSubmissionARound": {
"name": "Selecting an agent to send the transaction",
"description": "Selects an agent to send the transaction",
"transitions": {},
},
"SelectKeeperTransactionSubmissionBAfterTimeoutRound": {
"name": "Selecting an agent to send the transaction",
"description": "Selects an agent to send the transaction",
"transitions": {},
},
"SelectKeeperTransactionSubmissionBRound": {
"name": "Selecting an agent to send the transaction",
"description": "Selects an agent to send the transaction",
"transitions": {},
},
"SynchronizeLateMessagesRound": {
"name": "Synchronizing late messages",
"description": "Synchronizes late messages",
"transitions": {},
},
"TransactionMultiplexerRound": {
"name": "Selecting next round",
"description": "Decides where to transition next based on the state previous to the transaction",
"transitions": {},
},
"ValidateTransactionRound": {
"name": "Validating the transaction",
"description": "Checks that the transaction was succesful",
"transitions": {},
},
}
5 changes: 4 additions & 1 deletion packages/dvilela/skills/memeooorr_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ fingerprint:
behaviours.py: bafybeibdbimezloiomvsv3zgfdug4tw276gt7tb5agnezl2nuqcfcplscu
dialogues.py: bafybeiaygigeleloplgrsg2sovv463uvzk3zc2tupgazn4ak2vqcangksu
fsm_specification.yaml: bafybeidqesafw5vtekw2dtffjznuchdjllo52najwmmkj2npfdyaouigfa
handlers.py: bafybeia3ew422w57ot7jpbrhmagepm7pcoqkkc53p5w4jm4co4yh4tz7em
handlers.py: bafybeigdxkm45w27sh7cpgiwuperjldql6oupbhxqtizhbwfv7abxe3dku
models.py: bafybeid7ngfjyc3ck65yuzriy7y7eppz5kn7m7nsrilcvtqhqsfu54cn5e
payloads.py: bafybeif5ycv3aaim4sbfkmx5jnwjm5yvx562zkykhng5on63zfeqskddse
prompts.py: bafybeicww22zga6ximcfjb3h4hwhqfupuapc3uxl3bmev4hjfgd7cymzea
rounds.py: bafybeickhz2scrsecxhooytqf2q32kp2sck6clv433bxqlcpfv3lrok2ia
rounds_info.py: bafybeieqaemvqwiwku7nlxkdebsqzldpvvidijf6wcwy7e3xbyz335jr6i
subgraph.py: bafybeigme6r3cwiiu5l7r55rcbj7y37b62cxtlsnewpkbjqcbadwte32xm
fingerprint_ignore_patterns: []
connections:
Expand Down Expand Up @@ -181,5 +182,7 @@ dependencies:
version: ==3.0.0
textblob:
version: '>=0.18.0.post0'
PyYAML:
version: '>=3.10,<=6.0.1'
is_abstract: true
customs: []
2 changes: 1 addition & 1 deletion packages/dvilela/skills/memeooorr_chained_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeievjciqdvxhqxfjd4whqs27h6qbxqzrae7wwj7fpvxlvmtw3x35im
- valory/transaction_settlement_abci:0.1.0:bafybeihq2yenstblmaadzcjousowj5kfn5l7ns5pxweq2gcrsczfyq5wzm
- valory/termination_abci:0.1.0:bafybeid54buqxipiuduw7b6nnliiwsxajnltseuroad53wukfonpxca2om
- dvilela/memeooorr_abci:0.1.0:bafybeihlhmxryhaahfifxatt3lejqpsrbhm3a2ipamm2fygnybhy62olzu
- dvilela/memeooorr_abci:0.1.0:bafybeigfhi5k3fiodiyjbhy54lqcjjgiojtljlnzfnbhfkilg7slcz6ocu
behaviours:
main:
args: {}
Expand Down
8 changes: 4 additions & 4 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"contract/dvilela/meme_factory/0.1.0": "bafybeihh2fty6e3w2bvhn6y6jwa3yyssnn6yttopmmjczpgsudwrd7q4hq",
"contract/dvilela/meme/0.1.0": "bafybeihubei6hbhbyiwwyxcbredb5mhomhwfktxlwufmqxrzo4jj4ohweq",
"connection/dvilela/twikit/0.1.0": "bafybeiawfdnjxlcpdfrlqayhzymwlyumsp4ingnat6t4cluiswkduf3kk4",
"skill/dvilela/memeooorr_abci/0.1.0": "bafybeihlhmxryhaahfifxatt3lejqpsrbhm3a2ipamm2fygnybhy62olzu",
"skill/dvilela/memeooorr_chained_abci/0.1.0": "bafybeiczw2uly5awhzmpzjbdmbhsu6hhfsigqsseivxwk3ooe7ssvyfoo4",
"agent/dvilela/memeooorr/0.1.0": "bafybeiczczqg7ubzk5k2r5zu4esdjxo4fdq3qomseplf2mirgzugmgjuje",
"service/dvilela/memeooorr/0.1.0": "bafybeic6qec2szhrxfwdcbtml6skrt6ayocig4kn65toy3n6l3nd2hduj4"
"skill/dvilela/memeooorr_abci/0.1.0": "bafybeigfhi5k3fiodiyjbhy54lqcjjgiojtljlnzfnbhfkilg7slcz6ocu",
"skill/dvilela/memeooorr_chained_abci/0.1.0": "bafybeie4vem72o3m5iryggjbzfkukdcyqrj74ov7qdyjwc4wmxycu6n44u",
"agent/dvilela/memeooorr/0.1.0": "bafybeiempli5guocheudowojeqlh335zoe4lpuxas6f3cecxbcwhx2ia6q",
"service/dvilela/memeooorr/0.1.0": "bafybeihpd6ub2sacptilitj4htdqo2vqpj4mwufmsxlukqmqpamu3ff6ry"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down

0 comments on commit da099be

Please sign in to comment.