Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.17.0]: Update the policy's logic #296

Merged
merged 9 commits into from
Jul 19, 2024
12 changes: 6 additions & 6 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"contract/valory/staking_token/0.1.0": "bafybeig4fl35dn7d5gnprux2nwsqbirm7zkiujz3xvrwcjuktz6hkq4as4",
"contract/valory/relayer/0.1.0": "bafybeihzgjyvhtorugjw3yldznqsbwo3aqpxowm7k2nrvj6qtwpsc7jl7u",
"skill/valory/market_manager_abci/0.1.0": "bafybeig44vtxcq7aarqkg2mskly3zwwnyfc45rtdvorwz6ywspwg3obqn4",
"skill/valory/decision_maker_abci/0.1.0": "bafybeiejbfkl4im6srigta53ysan3tu5hlbb44cbd2mgryp2hsanyxpdge",
"skill/valory/trader_abci/0.1.0": "bafybeigfccxw5v76pectrmh2a3ibd4gt2hhtskkqay6an3g7lgdyotuz34",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiaiek6b3p7dro45qjoecmgseznhixhrgqgxfiap7lqw4rbi5fyhvy",
"skill/valory/decision_maker_abci/0.1.0": "bafybeibsopt3ku7bfaawek4ooudmroywbvmgz3znpazlzcobrfhops4xg4",
"skill/valory/trader_abci/0.1.0": "bafybeidksx7jjlcvc2lvwotbu3jnq2zowzhsye7vm4ikmetlaib6zzvnzy",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeifxc2e6iqmwm62kpta4rpdflrf4icoxyven4lxhid5v4nfrjaarvq",
"skill/valory/staking_abci/0.1.0": "bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeiboctfgetji6xlzw2buts5zsejnlrrhqkppme2p6fwzu26zznb324",
"agent/valory/trader/0.1.0": "bafybeiaxm4ts4odvhmbltyaa7rngm6jio7b4fdwvwszahw2ndfjdpd547a",
"service/valory/trader/0.1.0": "bafybeig3dk2wuzspnu7aeop2wbxd7sfe5yjlsj3yreen6v6vrtqwj4htyq",
"service/valory/trader_pearl/0.1.0": "bafybeicnm3uxoo7xfotbuhiafqalhfai2etkj5pqha6v4gejy4ilg5lcom"
"agent/valory/trader/0.1.0": "bafybeig5lan2wtms67e45yfc4fv2d5rck4af2jwerurenk5xeq7udunlne",
"service/valory/trader/0.1.0": "bafybeib6y2vqiehxxaffhf3odzjdws2wzqguajcwwbqnbc7d2szl3dvr6q",
"service/valory/trader_pearl/0.1.0": "bafybeidpooqfqb55y3yrfnez6mpagewuvj654zgnedictt4xio6y6mnmdq"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
6 changes: 3 additions & 3 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeiameewywqigpupy3u2iwnkfczeiiucue74x2l5lbge74rmw6bgaie
- valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq
- valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaiek6b3p7dro45qjoecmgseznhixhrgqgxfiap7lqw4rbi5fyhvy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifxc2e6iqmwm62kpta4rpdflrf4icoxyven4lxhid5v4nfrjaarvq
- valory/market_manager_abci:0.1.0:bafybeig44vtxcq7aarqkg2mskly3zwwnyfc45rtdvorwz6ywspwg3obqn4
- valory/decision_maker_abci:0.1.0:bafybeiejbfkl4im6srigta53ysan3tu5hlbb44cbd2mgryp2hsanyxpdge
- valory/trader_abci:0.1.0:bafybeigfccxw5v76pectrmh2a3ibd4gt2hhtskkqay6an3g7lgdyotuz34
- valory/decision_maker_abci:0.1.0:bafybeibsopt3ku7bfaawek4ooudmroywbvmgz3znpazlzcobrfhops4xg4
- valory/trader_abci:0.1.0:bafybeidksx7jjlcvc2lvwotbu3jnq2zowzhsye7vm4ikmetlaib6zzvnzy
- valory/staking_abci:0.1.0:bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be
- valory/check_stop_trading_abci:0.1.0:bafybeiboctfgetji6xlzw2buts5zsejnlrrhqkppme2p6fwzu26zznb324
- valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/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: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeiaxm4ts4odvhmbltyaa7rngm6jio7b4fdwvwszahw2ndfjdpd547a
agent: valory/trader:0.1.0:bafybeig5lan2wtms67e45yfc4fv2d5rck4af2jwerurenk5xeq7udunlne
number_of_agents: 4
deployment:
agent:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader_pearl/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeiaxm4ts4odvhmbltyaa7rngm6jio7b4fdwvwszahw2ndfjdpd547a
agent: valory/trader:0.1.0:bafybeig5lan2wtms67e45yfc4fv2d5rck4af2jwerurenk5xeq7udunlne
number_of_agents: 1
deployment:
agent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def _next_dataset_row(self) -> Optional[Dict[str, str]]:
self._rows_exceeded = True
return None

next_row: Optional[Dict[str, str]] = next(reader, {})
if not next_row:
self.shared_state.last_benchmarking_has_run = True

msg = f"Processing question in row with index {next_mock_data_row}: {row_with_headers}"
self.context.logger.info(msg)
return row_with_headers
Expand Down
14 changes: 6 additions & 8 deletions packages/valory/skills/decision_maker_abci/behaviours/reedem.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def _set_block_number(self, trade: Trade) -> Generator:
f"Chose block number {self.earliest_block_number!r} as closest to timestamp {timestamp!r}"
)

def _try_update_policy(self, tool: str) -> None:
def _try_update_policy(self, tool: str, winning: bool) -> None:
"""Try to update the policy."""
try:
self.policy.update_accuracy_store(tool)
self.policy.update_accuracy_store(tool, winning)
except KeyError:
self.context.logger.warning(
f"The stored utilized tools seem to be outdated as no {tool=} was found. "
Expand All @@ -134,9 +134,7 @@ def _update_policy(self, update: Trade) -> None:

# we try to avoid an ever-increasing dictionary of utilized tools by removing a tool when not needed anymore
del self.utilized_tools[update.transactionHash]
if not update.is_winning:
return
self._try_update_policy(tool)
self._try_update_policy(tool, update.is_winning)

def update_redeem_info(self, chunk: list) -> Generator:
"""Update the redeeming information using the given chunk."""
Expand Down Expand Up @@ -932,9 +930,9 @@ def _build_payload(self, redeem_tx_hex: Optional[str] = None) -> RedeemPayload:

def _benchmarking_act(self) -> RedeemPayload:
"""The act of the agent while running in benchmarking mode."""
if self.mock_data.is_winning:
tool = self.synchronized_data.mech_tool
self._try_update_policy(tool)
tool = self.synchronized_data.mech_tool
winning = self.mock_data.is_winning
self._try_update_policy(tool, winning)
return self._build_payload()

def _normal_act(self) -> Generator[None, None, Optional[RedeemPayload]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def async_act(self) -> Generator:
if selected_tool is not None:
# the period will increment when the benchmarking finishes
benchmarking_running = self.synchronized_data.period_count == 0
if self.benchmarking_mode.enabled and benchmarking_running:
if (
self.benchmarking_mode.enabled
and benchmarking_running
and not self.shared_state.last_benchmarking_has_run
):
self.policy.tool_used(selected_tool)
mech_tools = json.dumps(self.mech_tools)
policy = self.policy.serialize()
Expand Down
2 changes: 2 additions & 0 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def __init__(self, *args: Any, skill_context: SkillContext, **kwargs: Any) -> No
# latest liquidity information (only relevant to the benchmarking mode)
self.liquidity_amounts: Dict[str, List[int]] = {}
self.liquidity_prices: Dict[str, List[float]] = {}
# whether this is the last run of the benchmarking mode
self.last_benchmarking_has_run: bool = False

@property
def mock_question_id(self) -> Any:
Expand Down
17 changes: 11 additions & 6 deletions packages/valory/skills/decision_maker_abci/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ def best_tool(self) -> str:
def update_weighted_accuracy(self) -> None:
"""Update the weighted accuracy for each tool."""
self.weighted_accuracy = {
tool: (acc_info.accuracy / 100)
* (acc_info.requests - acc_info.pending)
/ self.n_requests
tool: acc_info.accuracy
Adamantios marked this conversation as resolved.
Show resolved Hide resolved
+ ((acc_info.requests - acc_info.pending) / self.n_requests * 2)
for tool, acc_info in self.accuracy_store.items()
}

Expand All @@ -155,10 +154,16 @@ def tool_used(self, tool: str) -> None:
self.accuracy_store[tool].pending += 1
self.update_weighted_accuracy()

def update_accuracy_store(self, tool: str) -> None:
def update_accuracy_store(self, tool: str, winning: bool) -> None:
"""Update the accuracy store for the given tool."""
self.accuracy_store[tool].requests += 1
self.accuracy_store[tool].pending -= 1
acc_info = self.accuracy_store[tool]
total_correct_answers = acc_info.accuracy * acc_info.requests
if winning:
total_correct_answers += 1

acc_info.requests += 1
acc_info.pending -= 1
acc_info.accuracy = total_correct_answers / acc_info.requests
self.update_weighted_accuracy()

def serialize(self) -> str:
Expand Down
10 changes: 5 additions & 5 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ fingerprint:
behaviours/blacklisting.py: bafybeibofq3emoxxcndkozupsyo2xrigewy6ojvzfdvzwruvsvgyilokbu
behaviours/check_benchmarking.py: bafybeiao2lyj7apezkqrpgsyzb3dwvrdgsrgtprf6iuhsmlsufvxfl5bci
behaviours/claim_subscription.py: bafybeihv5dg74deifzk46ppdwcvz6lgamgl6m7qr6sgqv2zie35j2576ca
behaviours/decision_receive.py: bafybeib465wlp74vq2jdaed53irnuqq22vdjj6punkjg4kyh6dovxf764u
behaviours/decision_receive.py: bafybeiay7cbzzngvtatswrgxczt5257jgwc6ppfi43fwc6rso36kipxmr4
behaviours/decision_request.py: bafybeiabjzzcwcfbfmtoftjhewmkgbhxfnigbc5cwmmxl6cob5gv64jwwa
behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm
behaviours/order_subscription.py: bafybeibl5ktq5lcwzr3komg77o67yebiokqyii7r3fsshatpww5tr5r3ke
behaviours/randomness.py: bafybeidmr33teizrs4uxlo5tdz766ds6os4pe5lttstm7jpmhgmjz5ti3q
behaviours/reedem.py: bafybeigddys4zqpztjma3rakgcmkrk55hiskgivhq2cgxsqnhl5wikmrym
behaviours/reedem.py: bafybeiaszvuwfamdq5m7zaxf3tvbyp6wocsksezfajqv5xpkh43r62cj6u
behaviours/round_behaviour.py: bafybeibvhobpvzzd37ecleuyp2jrbed6nontcw7urtsilbbzvqsmmupx64
behaviours/sampling.py: bafybeibtkli72qsvotkrsepkgpiumtr5sershtkpb427oygnszs3dpgxry
behaviours/storage_manager.py: bafybeifelwjwstg5dwrnzeav5mumz47kqrlmv4crfn27a3vliomychd2x4
behaviours/tool_selection.py: bafybeiat3mqtki55dnjmrrzpahjv3n26y5b45iehqx6tycqra76wtp7gxq
behaviours/tool_selection.py: bafybeienlxcgjs3ogyofli3d7q3p5rst3mcxxcnwqf7qolqjeefjtixeke
dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm
fsm_specification.yaml: bafybeicvrvzcjt4hg5jyr2eleoajpbb7q2fbq2bopmbnwy33fsjdblzygu
handlers.py: bafybeigod6gbjrxy4mbmulbzsbokeaoycoqys64vqtxnumishfukzf73za
io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq
io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa
models.py: bafybeif76bwktyx6i4h7gqunn33q2s4fjlstm4xb5hhsj3zmq4jsofmq4i
models.py: bafybeiafif3kzzyvvme2t6eck4sbpz6saam26jzjg46as2bqm5r5gvd4fq
payloads.py: bafybeia32ds4ks5g3rhd43w6siy74vi5inaheuxhswiy5ndykxtgncoeu4
policy.py: bafybeihp4lzv4ejyu6k5reukbpa6kamglicpymxfx6obm5pgugik4vc63y
policy.py: bafybeigno4dvvwr4z2tec7n62q4xhpwkfk7ptxxkq3o7hfdnradlbzplea
redeem_info.py: bafybeifiiix4gihfo4avraxt34sfw35v6dqq45do2drrssei2shbps63mm
rounds.py: bafybeieffmnu3sivnagmhrhcufnh5zun6pxligc6wp26me43u6cjy2y3xi
states/__init__.py: bafybeid23llnyp6j257dluxmrnztugo5llsrog7kua53hllyktz4dqhqoy
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote
- valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq
- valory/market_manager_abci:0.1.0:bafybeig44vtxcq7aarqkg2mskly3zwwnyfc45rtdvorwz6ywspwg3obqn4
- valory/decision_maker_abci:0.1.0:bafybeiejbfkl4im6srigta53ysan3tu5hlbb44cbd2mgryp2hsanyxpdge
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaiek6b3p7dro45qjoecmgseznhixhrgqgxfiap7lqw4rbi5fyhvy
- valory/decision_maker_abci:0.1.0:bafybeibsopt3ku7bfaawek4ooudmroywbvmgz3znpazlzcobrfhops4xg4
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifxc2e6iqmwm62kpta4rpdflrf4icoxyven4lxhid5v4nfrjaarvq
- valory/staking_abci:0.1.0:bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be
- valory/check_stop_trading_abci:0.1.0:bafybeiboctfgetji6xlzw2buts5zsejnlrrhqkppme2p6fwzu26zznb324
- valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protocols:
- valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni
skills:
- valory/abstract_round_abci:0.1.0:bafybeiar2yhzxacfe3qqamqhaihtlcimquwedffctw55sowx6rac3cm3ui
- valory/decision_maker_abci:0.1.0:bafybeiejbfkl4im6srigta53ysan3tu5hlbb44cbd2mgryp2hsanyxpdge
- valory/decision_maker_abci:0.1.0:bafybeibsopt3ku7bfaawek4ooudmroywbvmgz3znpazlzcobrfhops4xg4
- valory/staking_abci:0.1.0:bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be
- valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e
behaviours:
Expand Down
Loading