Question about ai Action priorities

So, jumping from file to file to learn about the a.i. I reached this:

The AI Component uses a special election process to determine which Action gets to run. Specifically:

  1. All Actions are asked to “start_thinking” simultaneously. “start_thinking” is the mechanism by which an Action is informed that the AI Component would like to run it.
  2. The Action which returns a result first is immediately run.
  3. If multiple Actions all return a result simultaneously, the one with the highest priority gets run.
  4. If multiple Actions all have the same priority, they are weighted by the “weight” field in their header and a random Action is chosen.

About the second step:
Does it means that even if my a.i. have a higher priority this does not guarantee that it will run because another task can be completed first?

And if that is the case, what exactly makes it return first? Just the code “heaviness”? A code full of loops and functions calls would probably take longer to return than a simple check with an if statement.

Pretty close. The way you should think of this is that the subgraph with the highest priority is always run. start_thinking may be called on an action at any time, and an action may set_think_output any time after start_thinking is called. If an action with a higher priority than its siblings sets its think output it will interrupt the current action and run instead.

This type of structure actually has a name and is called a Hierarchical Task Network.