Skip to content

Commit

Permalink
fix: adjust the tools after loading them from the store
Browse files Browse the repository at this point in the history
After retrieving the tools from the store, we must make adjustments in case any of them have been removed or if there are new tools available.
  • Loading branch information
Adamantios committed Oct 20, 2023
1 parent 2c64703 commit faaf8b9
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ def _get_tools(
):
yield from self.wait_for_condition_with_sleep(step)

def _adjust_policy_tools(self) -> None:
def _adjust_policy_tools(self, local: List[str]) -> 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)
Expand All @@ -196,11 +194,12 @@ def _set_policy(self) -> None:
"""Set the E Greedy Policy."""
if self.is_first_period:
self._policy = self._get_init_policy()
recovered_tools = self._try_recover_mech_tools()
self.mech_tools = list(set(self.mech_tools + recovered_tools))
local_tools = self._try_recover_mech_tools()
else:
self._policy = self.synchronized_data.policy
self._adjust_policy_tools()
local_tools = self.synchronized_data.available_mech_tools

self._adjust_policy_tools(local_tools)

def _get_init_policy(self) -> EGreedyPolicy:
"""Get the initial policy"""
Expand Down

0 comments on commit faaf8b9

Please sign in to comment.