Game Coordinator
Coordinator is the centerpiece of the game orchestration. It provides an interface between the agents and the worlds.
In detail it handles:
- World initialization
- Registration of new agents in the game
- Agent-World communication (message verification and forwarding)
- Recording (and storing) trajectories of agents (optional)
- Detection of episode ends (either by reaching timeout or agents reaching their respective goals)
- Assigning rewards for each action and at the end of each episode
- Removing agents from the game
- Registering the GameReset requests and handling the game resets.
To facilitate the communication the coordinator uses a TCP server to which agents connect. The communication is asynchronous and depends of the
Connection to other game components
Coordinator, having the role of the middle man in all communication between the agent and the world uses several queues for message passing and handling.
Action queueis a queue in which the agents submit their actions. It provides N:1 communication channel in which the coordinator receives the inputs.Answer queuesis a separate queue per agent in which the results of the actions are send to the agent.
Episode
The episode starts with sufficient amount of agents registering in the game. Each agent role has a maximum allowed number of steps defined in the task configuration. An episode ends if all agents reach the goal
netsecgame.game.coordinator.GameCoordinator(game_host, game_port, service_host, service_port, task_config_file)
Class for creation, and management of agent interactions in AI Dojo.
Attributes:
| Name | Type | Description |
|---|---|---|
host |
str
|
Host address for the game server. |
port |
int
|
Port number for the game server. |
logger |
Logger
|
Logger for the GameCoordinator. |
config_manager |
ConfigurationManager
|
Manager for game configuration. |
_tasks |
set
|
Set of active asyncio tasks. |
shutdown_flag |
Event
|
Event to signal shutdown. |
_reset_event |
Event
|
Event to signal game reset. |
_episode_end_event |
Event
|
Event to signal episode end. |
_episode_start_event |
Event
|
Event to signal episode start. |
_episode_rewards_condition |
Condition
|
Condition for episode rewards assignment. |
_reset_done_condition |
Condition
|
Condition for reset completion. |
_reset_lock |
Lock
|
Lock for reset operations. |
_agents_lock |
Lock
|
Lock for agent operations. |
_cyst_objects |
Lock
|
CYST simulator initialization objects. |
_cyst_object_string |
Lock
|
String representation of CYST objects. |
_agent_action_queue |
Queue
|
Queue for agent actions. |
_agent_response_queues |
dict
|
Mapping of agent addresses to their response queues. |
agents |
dict
|
Mapping of agent addresses to their information. |
_agent_steps |
dict
|
Step counters per agent address. |
_reset_requests |
dict
|
Reset requests per agent address. |
_randomize_topology_requests |
dict
|
Topology randomization requests per agent address. |
_agent_status |
dict
|
Status of each agent. |
_episode_ends |
dict
|
Episode end flags per agent address. |
_agent_observations |
dict
|
Observations per agent address. |
_agent_starting_position |
dict
|
Starting positions per agent address. |
_agent_states |
dict
|
Current states per agent address. |
_agent_goal_states |
dict
|
Goal states per agent address. |
_agent_last_action |
dict
|
Last actions played by agents. |
_agent_false_positives |
dict
|
False positives per agent. |
_agent_rewards |
dict
|
Rewards per agent address. |
_agent_trajectories |
dict
|
Trajectories per agent address. |
Source code in netsecgame/game/coordinator.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
add_false_positive(agent)
Method for adding false positive to the agent. Args: agent (tuple): The agent to add false positive to.
Source code in netsecgame/game/coordinator.py
764 765 766 767 768 769 770 771 772 773 774 775 | |
create_agent_queue(agent_addr)
async
Creates a queue for the given agent address if it doesn't already exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The agent address to create a queue for. |
required |
Source code in netsecgame/game/coordinator.py
139 140 141 142 143 144 145 146 147 148 | |
goal_check(agent_addr)
Check if the goal conditons were satisfied in a given game state
Source code in netsecgame/game/coordinator.py
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
is_agent_benign(agent_addr)
Check if the agent is benign (defender, normal)
Source code in netsecgame/game/coordinator.py
862 863 864 865 866 867 868 869 | |
register_agent(agent_id, agent_role, agent_initial_view, agent_win_condition_view)
async
Domain specific method of the environment. Creates the initial state of the agent.
Source code in netsecgame/game/coordinator.py
642 643 644 645 646 | |
remove_agent(agent_id, agent_state)
async
Domain specific method of the environment. Creates the initial state of the agent.
Source code in netsecgame/game/coordinator.py
648 649 650 651 652 | |
reset()
async
Domain specific method of the environment. Creates the initial state of the agent. Must be implemented by the domain specific environment.
Source code in netsecgame/game/coordinator.py
699 700 701 702 703 704 | |
run()
Wrapper for ayncio run function. Starts all tasks in AIDojo
Source code in netsecgame/game/coordinator.py
150 151 152 153 154 155 156 157 158 159 | |
run_game()
async
Main game loop task.
Responsible for reading messages from the agent queue, parsing them using _parse_action_message,
and dispatching them to the appropriate handler using _dispatch_action.
Source code in netsecgame/game/coordinator.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
shutdown_signal_handler()
async
Logs the signal reception and sets the shutdown flag to initiate graceful termination.
Source code in netsecgame/game/coordinator.py
132 133 134 135 136 137 | |
start_tasks()
async
High level funciton to start all the other asynchronous tasks. - Reads the conf of the coordinator - Creates queues - Start the main part of the coordinator - Start a server that listens for agents
Source code in netsecgame/game/coordinator.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
start_tcp_server()
async
Starts TPC sever for the agent communication.
Source code in netsecgame/game/coordinator.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
step(agent_id, agent_state, action)
async
Domain specific method of the environment. Creates the initial state of the agent. Must be implemented by the domain specific environment.
Source code in netsecgame/game/coordinator.py
692 693 694 695 696 697 | |
netsecgame.game.worlds.NetSecGame.NetSecGame(game_host, game_port, task_config, seed=None)
Bases: GameCoordinator
Source code in netsecgame/game/worlds/NetSecGame.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
reset()
async
Function to reset the state of the game and prepare for a new episode
Source code in netsecgame/game/worlds/NetSecGame.py
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | |