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 on the world's implementation.
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 sent 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 or if the maximum number of steps is reached.
netsecgame.game.coordinator.GameCoordinator
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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
_add_step_to_trajectory
Adds a single step (state, action, reward) to the agent's trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
action
|
Action
|
The action performed. |
required |
reward
|
float
|
The reward received. |
required |
next_state
|
GameState
|
The resulting state. |
required |
end_reason
|
Optional[str]
|
An optional reason if the episode ended. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | |
_assign_rewards_episode_end
async
Task that waits for all agents to finish and then assigns final rewards.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
_dispatch_action
Dispatches an Action to the appropriate processing method based on its type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent performing the action. |
required |
action
|
Action
|
The Action object to be processed. |
required |
Source code in netsecgame/game/coordinator.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
_handle_invalid_reset
async
Handles an invalid reset request by notifying agents and shutting down.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_msg
|
str
|
The error message explaining why the reset is invalid. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
_handle_valid_reset
async
Handles a valid reset request by resetting the world and agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Optional[int]
|
The random seed to use for the new episode. |
required |
topology_change
|
Optional[bool]
|
Whether to randomize the topology. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
_initialize
Initializes the environment state and components.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
913 914 915 916 917 918 919 920 | |
_initialize_new_player
Initializes a new player's state and data upon joining the game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
agent_current_state
|
GameState
|
The initial state assigned to the agent. |
required |
agent_current_goal_state
|
GameState
|
The goal state assigned to the agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Observation |
Observation
|
The initial observation for the agent. |
Source code in netsecgame/game/coordinator.py
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | |
_parse_action_message
Parses a JSON message from an agent into an Action object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent sending the message (used for logging context). |
required |
message
|
str
|
The raw JSON string message received from the agent. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Action]
|
Optional[Action]: The parsed Action object if successful, None otherwise. |
Source code in netsecgame/game/coordinator.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
_process_game_action
async
Processes a generic game action (Scan, Exploit, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
action
|
Action
|
The Action object to process. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
_process_join_game_action
async
Processes an Action of type ActionType.JoinGame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
action
|
Action
|
The JoinGame Action object. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
_process_quit_game_action
async
Processes an Action of type ActionType.QuitGame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
_process_reset_game_action
async
Processes an Action of type ActionType.ResetGame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
reset_action
|
Action
|
The ResetGame Action object. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
_remove_agent_from_game
async
Removes a player from the GameCoordinator's tracking and returns their final info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing final agent statistics and state. |
Source code in netsecgame/game/coordinator.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
_reset_game
async
Task that waits for all agents to request resets and coordinates the process.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
711 712 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 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
_reset_trajectory
Resets and initializes a new trajectory dictionary for an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: The initial trajectory dictionary. |
Source code in netsecgame/game/coordinator.py
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 | |
_respond_on_bad_request
async
Sends a response to the agent indicating that the request was bad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
message
|
str
|
The descriptive error message. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
_spawn_task
Helper function to make sure all tasks are registered for proper termination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coroutine
|
Coroutine
|
The coroutine function to schedule. |
required |
*args
|
tuple
|
Positional arguments to pass to the coroutine. |
()
|
**kwargs
|
dict
|
Keyword arguments to pass to the coroutine. |
{}
|
Returns:
| Type | Description |
|---|---|
Task
|
asyncio.Task: The created task object. |
Source code in netsecgame/game/coordinator.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
_store_trajectory_to_file
Stores the collected trajectory for an agent to a JSONL file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
location
|
str
|
The directory where the file should be saved. |
'./logs/trajectories'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 | |
_update_agent_episode_end
Update the episode end status of an agent. Args: agent (tuple): The agent to update the episode end status of.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the episode has ended, False otherwise. |
Source code in netsecgame/game/coordinator.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 | |
_update_agent_status
Update the status of an agent based on reaching the goal, timeout or detection. Args: agent (tuple): The agent to update the status of.
Returns:
| Name | Type | Description |
|---|---|---|
AgentStatus |
AgentStatus
|
The new status of the agent. |
Source code in netsecgame/game/coordinator.py
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 | |
add_false_positive
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
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | |
create_agent_queue
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
162 163 164 165 166 167 168 169 170 171 | |
goal_check
Checks if the goal conditions for specific agent were satisfied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the goal is reached, False otherwise. |
Source code in netsecgame/game/coordinator.py
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | |
is_agent_benign
Checks if the agent has a benign role (Defender or Benign).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_addr
|
tuple
|
The address of the agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the agent is benign, False otherwise. |
Source code in netsecgame/game/coordinator.py
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 | |
is_detected
Checks if the agent's last action was detected by the global defender.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
tuple
|
The address of the agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if detected, False otherwise. |
Source code in netsecgame/game/coordinator.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | |
is_timeout
Checks if the agent has reached its maximum step limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
tuple
|
The address of the agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if timeout reached, False otherwise. |
Source code in netsecgame/game/coordinator.py
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | |
register_agent
async
Domain-specific method to register an agent and create its initial and goal states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
tuple
|
The identifier for the agent. |
required |
agent_role
|
AgentRole
|
The role of the agent. |
required |
agent_initial_view
|
Dict[str, Any]
|
The initial starting view for the agent. |
required |
agent_win_condition_view
|
Dict[str, Any]
|
The win conditions for the agent. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[GameState, GameState]
|
Tuple[GameState, GameState]: A tuple containing (initial_state, goal_state). |
Source code in netsecgame/game/coordinator.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
remove_agent
async
Domain-specific method to remove an agent from the environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
tuple
|
The identifier for the agent. |
required |
agent_state
|
GameState
|
The last known state of the agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if removal was successful, False otherwise. |
Source code in netsecgame/game/coordinator.py
818 819 820 821 822 823 824 825 826 827 828 829 | |
reset
async
Domain specific method of the environment. Creates the initial state of the agent. Must be implemented by the domain specific environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int
|
Seed for the random number generator. Defaults to None. |
None
|
Source code in netsecgame/game/coordinator.py
903 904 905 906 907 908 909 910 911 | |
reset_agent
async
Domain-specific method to reset an agent's state for a new episode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
tuple
|
The identifier for the agent. |
required |
agent_role
|
AgentRole
|
The role of the agent. |
required |
agent_initial_view
|
Dict[str, Any]
|
The new starting view for the agent. |
required |
agent_win_condition_view
|
Dict[str, Any]
|
The win conditions for the agent. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[GameState, GameState]
|
Tuple[GameState, GameState]: A tuple containing (new_state, new_goal_state). |
Source code in netsecgame/game/coordinator.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 | |
run
Wrapper for asyncio run function. Starts all tasks in AIDojo.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
173 174 175 176 177 178 179 180 181 182 183 184 185 | |
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
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
shutdown_signal_handler
async
Logs the signal reception and sets the shutdown flag to initiate graceful termination.
Source code in netsecgame/game/coordinator.py
155 156 157 158 159 160 | |
start_tasks
async
High level function to start all asynchronous tasks.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
start_tcp_server
async
Starts the TCP server for agent communication.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in netsecgame/game/coordinator.py
187 188 189 190 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 | |
step
async
Domain-specific method to perform an action in the environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
tuple
|
The identifier for the agent. |
required |
agent_state
|
GameState
|
The current state of the agent. |
required |
action
|
Action
|
The action to perform. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GameState |
GameState
|
The new state of the agent after the action. |
Source code in netsecgame/game/coordinator.py
889 890 891 892 893 894 895 896 897 898 899 900 901 | |