# Agent selection sequence

**URL:** https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411
**Category:** Discussion
**Created:** [September 28, 2023, 8:46am UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411 "2023-09-28T08:46:20Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![k3tchup](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/k3tchup/32/2162_2.png) [@k3tchup](https://www.finalbuilder.com/forums/u/k3tchup)
#### Post date: [September 28, 2023, 8:46am UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/1 "2023-09-28T08:46:20Z")

</div>

I am using agent selection mechanism at stage level:  
`$Agent.Hostname.ToLower()$ | In | $Utils.GetString(%BuildAgents%).SplitWithQuotes(",","double",true)$`  
Which ofcourse works properly, but I was wondering what is the mechanism behind it and is it possible to prioritize certain agents (which might have better HW).

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [September 28, 2023, 12:28pm UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/2 "2023-09-28T12:28:37Z")

</div>

Hi Michal,

Agents are selected in order of capacity available. This value is based on the number of stages currently running on agent and the concurrent stage limit for that agent.

e.g. agentCapacityAvailable = 100 - ((activeStagesOnAgent / concurrentStageLimit) \* 100)

Therefore you can prioritise an agent by increasing its concurrent stage limit in relation to other agents.

---

<div class="post-metadata">

### Author: ![k3tchup](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/k3tchup/32/2162_2.png) [@k3tchup](https://www.finalbuilder.com/forums/u/k3tchup)
#### Post date: [September 29, 2023, 8:10am UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/3 "2023-09-29T08:10:24Z")

</div>

Hello,  
we currently we have setting of 1 concurrent stage per agent, as we mostly do compilation there.  
So I understand that all have the same “capacity”, but I am guessing that agent list is somehow sorted ? Or is it randomized ?

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [September 30, 2023, 12:39am UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/4 "2023-09-30T00:39:33Z")

</div>

Hi Michal,

Providing the agents all have the same capacity, they are ordered alphabetically by hostname. We are considering making this configurable in the future but it’s not currently a priority.

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [October 12, 2023, 9:28am UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/5 "2023-10-12T09:28:05Z")

</div>

An agent priority field has been to the Agent Requirements tab of the Stage Options dialog for [v1.9.2.1199](https://www.finalbuilder.com/forums/t/continua-ci-v1-9-2-1199-released/7415). This can be used specify the order in which an agent is selected for the associated stage.

---

<div class="post-metadata">

### Author: ![k3tchup](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/k3tchup/32/2162_2.png) [@k3tchup](https://www.finalbuilder.com/forums/u/k3tchup)
#### Post date: [October 13, 2023, 12:20pm UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/6 "2023-10-13T12:20:19Z")

</div>

would it be possible to have this option globally ?

---

<div class="post-metadata">

### Author: ![k3tchup](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/k3tchup/32/2162_2.png) [@k3tchup](https://www.finalbuilder.com/forums/u/k3tchup)
#### Post date: [October 13, 2023, 1:00pm UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/7 "2023-10-13T13:00:33Z")

</div>

You know what, I somehow though this is a list of agents to be looked for.  
But that is not the case ?  
It seems I do not understand how to use this feature 🙂

Can you elaborate on how to configure this ?

---

<div class="post-metadata">

### Author: ![k3tchup](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/k3tchup/32/2162_2.png) [@k3tchup](https://www.finalbuilder.com/forums/u/k3tchup)
#### Post date: [October 13, 2023, 2:39pm UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/8 "2023-10-13T14:39:45Z")

</div>

After some testing I think I got it. But it’s not that obvious.  
Also I added new properties for each agent but it was not visible in the agenet priority setting, does that require server restart ?

Better description (with example could be added). Explaining how priority numbers are treated.

---

<div class="post-metadata">

### Author: ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)
#### Post date: [October 14, 2023, 4:15am UTC](https://www.finalbuilder.com/forums/t/agent-selection-sequence/7411/9 "2023-10-14T04:15:44Z")

</div>

Hi Michal,

There is a new agent property collector (on the Property Collectors page in the Admin section), which is called `Priority`. As this is a simple numerical property collector, it generates a `Priority.Value` property on each agent with a default value of 0. You can edit the `Priority` property on each agent to provide the global priority value for all stages where the Agent Priority is set to `$Agent.Priority.Value$`. This is the default priority for new stages - we didn’t change existing stages as this may be a breaking change for anyone relying on the current order.

If you want to use a different priority for a stage or set of stages, then add a new agent property collector. Agent property collectors appear in the autocomplete list as `$Agent.PropertyNamespace.PropertyName$`. Properties added to individual agents don’t appear in the autocomplete list as some agents may not have the property.

We’ll update the documentation on Monday - we had to release before updating the documentation to quickly fix for bug which was a showstopper for one user.
