#2869 - Changes to agent refactor config schema, removal of state variables that aren't necessary to be in config

This commit is contained in:
Charlie Crane
2024-12-13 11:05:24 +00:00
parent 86ad872cba
commit 4ac90c3c10
5 changed files with 24 additions and 25 deletions

View File

@@ -98,6 +98,8 @@ class AbstractAgent(BaseModel, ABC, identifier="Abstract_Agent"):
_registry: ClassVar[Dict[str, Type[AbstractAgent]]] = {}
config: "AbstractAgent.ConfigSchema"
agent_name: str = "Abstact_Agent"
logger: AgentLog = AgentLog(agent_name)
class ConfigSchema(BaseModel):
"""
@@ -115,9 +117,6 @@ class AbstractAgent(BaseModel, ABC, identifier="Abstract_Agent"):
:type agent_settings: Optional[AgentSettings]
"""
type: str
agent_name: str = "Abstact_Agent"
logger: AgentLog = AgentLog(agent_name)
history: List[AgentHistoryItem] = []
action_manager: Optional[ActionManager] = None
observation_manager: Optional[ObservationManager] = None

View File

@@ -11,11 +11,11 @@ class AbstractTAPAgent(AbstractScriptedAgent, identifier="Abstract_TAP"):
"""Base class for TAP agents to inherit from."""
config: "AbstractTAPAgent.ConfigSchema"
agent_name: str = "Abstract_TAP"
class ConfigSchema(AbstractScriptedAgent.ConfigSchema):
"""Configuration schema for Abstract TAP agents."""
agent_name: str = "Abstract_TAP"
starting_node_name: str
next_execution_timestep: int
@@ -40,4 +40,4 @@ class AbstractTAPAgent(AbstractScriptedAgent, identifier="Abstract_TAP"):
num_nodes = len(self.config.action_manager.node_names)
starting_node_idx = random.randint(0, num_nodes - 1)
self.starting_node_name = self.config.action_manager.node_names[starting_node_idx]
self.config.logger.debug(f"Selected Starting node ID: {self.starting_node_name}")
self.logger.debug(f"Selected Starting node ID: {self.starting_node_name}")

View File

@@ -10,15 +10,15 @@ class DataManipulationAgent(AbstractTAPAgent, identifier="Data_Manipulation_Agen
"""Agent that uses a DataManipulationBot to perform an SQL injection attack."""
config: "DataManipulationAgent.ConfigSchema"
agent_name: str = "Data_Manipulation_Agent"
class ConfigSchema(AbstractTAPAgent.ConfigSchema):
"""Configuration Schema for DataManipulationAgent."""
starting_application_name: str
agent_name: str = "Data_Manipulation_Agent"
def __init__(self) -> None:
"""Meh."""
"""Initialise DataManipulationAgent."""
self.setup_agent()
@property

View File

@@ -14,11 +14,11 @@ class ProbabilisticAgent(AbstractScriptedAgent, identifier="Probabilistic_Agent"
"""Scripted agent which randomly samples its action space with prescribed probabilities for each action."""
config: "ProbabilisticAgent.ConfigSchema"
agent_name: str = "Probabilistic_Agent"
class ConfigSchema(AbstractScriptedAgent.ConfigSchema):
"""Configuration schema for Probabilistic Agent."""
agent_name: str = "Probabilistic_Agent"
action_space: ActionManager
action_probabilities: Dict[int, float]
"""Probability to perform each action in the action map. The sum of probabilities should sum to 1."""

View File

@@ -31,27 +31,27 @@ class RandomAgent(AbstractScriptedAgent, identifier="Random_Agent"):
class PeriodicAgent(AbstractScriptedAgent, identifier="Periodic_Agent"):
"""Agent that does nothing most of the time, but executes application at regular intervals (with variance)."""
config: "PeriodicAgent.ConfigSchema"
config: "PeriodicAgent.ConfigSchema" = {}
class ConfigSchema(AbstractScriptedAgent.ConfigSchema):
"""Configuration Schema for Periodic Agent."""
agent_name = "Periodic_Agent"
"""Name of the agent."""
start_step: int = 20
"The timestep at which an agent begins performing it's actions."
start_variance: int = 5
"Deviation around the start step."
frequency: int = 5
"The number of timesteps to wait between performing actions."
variance: int = 0
"The amount the frequency can randomly change to."
max_executions: int = 999999
"Maximum number of times the agent can execute its action."
num_executions: int = 0
"""Number of times the agent has executed an action."""
next_execution_timestep: int = 0
"""Timestep of the next action execution by the agent."""
agent_name = "Periodic_Agent"
"""Name of the agent."""
start_step: int = 20
"The timestep at which an agent begins performing it's actions."
start_variance: int = 5
"Deviation around the start step."
frequency: int = 5
"The number of timesteps to wait between performing actions."
variance: int = 0
"The amount the frequency can randomly change to."
max_executions: int = 999999
"Maximum number of times the agent can execute its action."
num_executions: int = 0
"""Number of times the agent has executed an action."""
next_execution_timestep: int = 0
"""Timestep of the next action execution by the agent."""
@property
def num_executions(self) -> int: