but keep in mind that: 1. I'd love to choose it while clicking "Run job", 2. List of available agents should be possible as a dropdown menu 3. By default it should use a random agent from pool
To achieve this in the YAML file, we could define two Runtime parameters, one of the parameter is used to select an specify agent from the dropdown list, one is used to decide whether to use a specific agent or the default a random agent.
in other words, we need use a parameter to select the demands and another parameter to disable/enable the previous demand. If we disable the previous demand, Azure devops will use a random agent by default.
I set following sample YAML file:
parameters:
- name: IfNeedDemands
type: boolean
default: False
- name: AgentSelect
displayName: Agent Select
type: string
values:
- VsAgent1
- VsAgent2
- VsAgent3
- VsAgent4
trigger: none
jobs:
- job: build
displayName: build
pool:
name: MyPrivateAgent
${{ if eq(parameters.IfNeedDemands, true) }}:
demands: Agent.Name -equals ${{ parameters.AgentSelect }}
steps:
- script: echo The value is ${{ parameters.AgentSelect }}
In above sample, parameter IfNeedDemands
with syntax ${{ if eq(parameters.IfNeedDemands, true) }}:
is used to determine the whether to enable demands.
Then the parameter AgentSelect
used to select the private agent.

I tested it works as I expected, you can check if it meets your needs.