Run agent at configured timesteps

This commit is contained in:
Jake Walker
2023-11-21 13:41:38 +00:00
parent d8154bbebd
commit 48af022963

View File

@@ -1,4 +1,5 @@
"""Interface for agents."""
import random
from abc import ABC, abstractmethod
from typing import Dict, List, Optional, Tuple, TYPE_CHECKING, TypeAlias, Union
@@ -178,10 +179,13 @@ class DataManipulationAgent(AbstractScriptedAgent):
"""Agent that uses a DataManipulationBot to perform an SQL injection attack."""
data_manipulation_bots: List["DataManipulationBot"] = []
next_execution_timestep: int = 0
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.next_execution_timestep = self.agent_settings.start_settings.start_step
# get node ids that are part of the agent's observation space
node_ids: List[str] = [n.where[-1] for n in self.observation_space.obs.nodes]
# get all nodes from their ids
@@ -207,10 +211,19 @@ class DataManipulationAgent(AbstractScriptedAgent):
"""
# TODO: Move this to the appropriate place
# return self.action_space.get_action(self.action_space.space.sample())
timestep = self.action_space.session.step_counter
if timestep < self.next_execution_timestep:
return "DONOTHING", {"dummy": 0}
var = random.randint(-self.agent_settings.start_settings.variance, self.agent_settings.start_settings.variance)
self.next_execution_timestep = timestep + self.agent_settings.start_settings.frequency + var
for bot in self.data_manipulation_bots:
bot.execute()
return ("DONOTHING", {"dummy": 0})
return "DONOTHING", {"dummy": 0}
class AbstractGATEAgent(AbstractAgent):