#2869 - Some additional test updates to amend failures. Pre-commit tbd and some cleanup
This commit is contained in:
@@ -9,6 +9,7 @@ from gymnasium.core import ObsType
|
|||||||
|
|
||||||
from primaite.game.agent.scripted_agents.interface import AbstractAgent, AbstractScriptedAgent
|
from primaite.game.agent.scripted_agents.interface import AbstractAgent, AbstractScriptedAgent
|
||||||
|
|
||||||
|
__all__ = ("AbstractTAPAgent")
|
||||||
|
|
||||||
class AbstractTAPAgent(AbstractScriptedAgent, identifier="Abstract_TAP"):
|
class AbstractTAPAgent(AbstractScriptedAgent, identifier="Abstract_TAP"):
|
||||||
"""Base class for TAP agents to inherit from."""
|
"""Base class for TAP agents to inherit from."""
|
||||||
@@ -22,11 +23,6 @@ class AbstractTAPAgent(AbstractScriptedAgent, identifier="Abstract_TAP"):
|
|||||||
|
|
||||||
starting_node_name: Optional[str] = None
|
starting_node_name: Optional[str] = None
|
||||||
|
|
||||||
# @property
|
|
||||||
# def next_execution_timestep(self) -> int:
|
|
||||||
# """Returns the agents next execution timestep."""
|
|
||||||
# return self.next_execution_timestep
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]:
|
def get_action(self, obs: ObsType, timestep: int = 0) -> Tuple[str, Dict]:
|
||||||
"""Return an action to be taken in the environment."""
|
"""Return an action to be taken in the environment."""
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from gymnasium.core import ObsType
|
|||||||
|
|
||||||
from primaite.game.agent.scripted_agents.abstract_tap import AbstractTAPAgent
|
from primaite.game.agent.scripted_agents.abstract_tap import AbstractTAPAgent
|
||||||
|
|
||||||
|
__all__ = ("DataManipulationAgent")
|
||||||
|
|
||||||
class DataManipulationAgent(AbstractTAPAgent, identifier="RedDatabaseCorruptingAgent"):
|
class DataManipulationAgent(AbstractTAPAgent, identifier="RedDatabaseCorruptingAgent"):
|
||||||
"""Agent that uses a DataManipulationBot to perform an SQL injection attack."""
|
"""Agent that uses a DataManipulationBot to perform an SQL injection attack."""
|
||||||
@@ -17,11 +18,6 @@ class DataManipulationAgent(AbstractTAPAgent, identifier="RedDatabaseCorruptingA
|
|||||||
|
|
||||||
starting_application_name: Optional[str] = None
|
starting_application_name: Optional[str] = None
|
||||||
|
|
||||||
# def __init__(self, **kwargs: Any) -> None:
|
|
||||||
# """Initialise DataManipulationAgent."""
|
|
||||||
# self.setup_agent()
|
|
||||||
# super().__init_subclass__(**kwargs)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def starting_node_name(self) -> str:
|
def starting_node_name(self) -> str:
|
||||||
"""Returns the agents starting node name."""
|
"""Returns the agents starting node name."""
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ from primaite.interface.request import RequestFormat, RequestResponse
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
__all__ = ("AgentHistoryItem",
|
||||||
|
"AgentStartSettings",
|
||||||
|
"AbstractAgent",
|
||||||
|
"AbstractScriptedAgent",
|
||||||
|
"ProxyAgent")
|
||||||
|
|
||||||
class AgentHistoryItem(BaseModel):
|
class AgentHistoryItem(BaseModel):
|
||||||
"""One entry of an agent's action log - what the agent did and how the simulator responded in 1 step."""
|
"""One entry of an agent's action log - what the agent did and how the simulator responded in 1 step."""
|
||||||
@@ -116,7 +121,7 @@ class AbstractAgent(BaseModel):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
|
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
|
||||||
agent_name: Optional[str] = "Abstract_Agent"
|
agent_name: ClassVar[str] = "Abstract_Agent" # TODO: Make this a ClassVar[str] like verb in actions?
|
||||||
history: List[AgentHistoryItem] = []
|
history: List[AgentHistoryItem] = []
|
||||||
_logger: AgentLog = AgentLog(agent_name=agent_name)
|
_logger: AgentLog = AgentLog(agent_name=agent_name)
|
||||||
action_manager: ActionManager
|
action_manager: ActionManager
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from gymnasium.core import ObsType
|
|||||||
|
|
||||||
from primaite.game.agent.scripted_agents.interface import AbstractScriptedAgent, AgentSettings
|
from primaite.game.agent.scripted_agents.interface import AbstractScriptedAgent, AgentSettings
|
||||||
|
|
||||||
|
__all__ = ("ProbabilisticAgent")
|
||||||
|
|
||||||
class ProbabilisticAgent(AbstractScriptedAgent, identifier="ProbabilisticAgent"):
|
class ProbabilisticAgent(AbstractScriptedAgent, identifier="ProbabilisticAgent"):
|
||||||
"""Scripted agent which randomly samples its action space with prescribed probabilities for each action."""
|
"""Scripted agent which randomly samples its action space with prescribed probabilities for each action."""
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from gymnasium.core import ObsType
|
|||||||
|
|
||||||
from primaite.game.agent.scripted_agents.interface import AbstractScriptedAgent
|
from primaite.game.agent.scripted_agents.interface import AbstractScriptedAgent
|
||||||
|
|
||||||
|
__all__ = ("RandomAgent", "PeriodicAgent")
|
||||||
|
|
||||||
class RandomAgent(AbstractScriptedAgent, identifier="Random_Agent"):
|
class RandomAgent(AbstractScriptedAgent, identifier="Random_Agent"):
|
||||||
"""Agent that ignores its observation and acts completely at random."""
|
"""Agent that ignores its observation and acts completely at random."""
|
||||||
@@ -38,18 +39,25 @@ class PeriodicAgent(AbstractScriptedAgent, identifier="Periodic_Agent"):
|
|||||||
|
|
||||||
agent_name: str = "Periodic_Agent"
|
agent_name: str = "Periodic_Agent"
|
||||||
"""Name of the agent."""
|
"""Name of the agent."""
|
||||||
|
|
||||||
|
# TODO: This is available in config.agent_settings.start_settings.start_step
|
||||||
start_step: int = 20
|
start_step: int = 20
|
||||||
"The timestep at which an agent begins performing it's actions."
|
"The timestep at which an agent begins performing it's actions."
|
||||||
start_variance: int = 5
|
start_variance: int = 5
|
||||||
"Deviation around the start step."
|
"Deviation around the start step."
|
||||||
|
|
||||||
|
# TODO: This is available in config.agent_settings.start_settings.frequency
|
||||||
frequency: int = 5
|
frequency: int = 5
|
||||||
"The number of timesteps to wait between performing actions."
|
"The number of timesteps to wait between performing actions."
|
||||||
|
|
||||||
|
# TODO: This is available in config.agent_settings.start_settings.variance
|
||||||
variance: int = 0
|
variance: int = 0
|
||||||
"The amount the frequency can randomly change to."
|
"The amount the frequency can randomly change to."
|
||||||
max_executions: int = 999999
|
max_executions: int = 999999
|
||||||
"Maximum number of times the agent can execute its action."
|
"Maximum number of times the agent can execute its action."
|
||||||
num_executions: int = 0
|
num_executions: int = 0
|
||||||
"""Number of times the agent has executed an action."""
|
"""Number of times the agent has executed an action."""
|
||||||
|
#TODO: Also in abstract_tap - move up and inherit? Add to AgentStartSettings?
|
||||||
next_execution_timestep: int = 0
|
next_execution_timestep: int = 0
|
||||||
"""Timestep of the next action execution by the agent."""
|
"""Timestep of the next action execution by the agent."""
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ agents:
|
|||||||
start_step: 5
|
start_step: 5
|
||||||
frequency: 4
|
frequency: 4
|
||||||
variance: 3
|
variance: 3
|
||||||
|
action_probabilities:
|
||||||
|
0: 0.6
|
||||||
|
1: 0.4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ agents:
|
|||||||
start_step: 5
|
start_step: 5
|
||||||
frequency: 4
|
frequency: 4
|
||||||
variance: 3
|
variance: 3
|
||||||
|
action_probabilities:
|
||||||
|
0: 0.4
|
||||||
|
1: 0.6
|
||||||
|
|
||||||
|
|
||||||
- ref: defender
|
- ref: defender
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ agents:
|
|||||||
start_step: 5
|
start_step: 5
|
||||||
frequency: 4
|
frequency: 4
|
||||||
variance: 3
|
variance: 3
|
||||||
|
action_probabilities:
|
||||||
|
0: 0.4
|
||||||
|
1: 0.6
|
||||||
|
|
||||||
|
|
||||||
- ref: defender
|
- ref: defender
|
||||||
|
|||||||
Reference in New Issue
Block a user