Dynamically target agent when creating build

When calling a pipeline via the REST API, is it possible to dynamically define the criteria for selecting an agent, rather than having an agent section in the pipeline yaml steps? Put another way, I’d like to be able to define a pipeline that will sometimes run only on an agent that has a metadata attribute “color=blue”. But I’d also sometimes like that same pipeline to run only on agents where the color attribute == red (“color=red”.)

I see that I can pass in metadata with a build request. I’d like to be able to pass in blue or red there to define what agents get targeted by the build when a pipeline runs. Is this possible?

Thanks

I’ve kind of sorted this, am just using env vars to configure the agent section of the pipeline.