Dynamically Allocate Agents

Coming soon!

We're cooking something up that will make it even easier to dynamically allocate agents, powered by AI. Read more »

By default, when you set up Nx Agents you specify the number and type of agents to use.

.github/workflows/main.yaml
1... 2jobs: 3 - job: main 4 displayName: Main Job 5 ... 6 steps: 7 ... 8 - run: npx nx-cloud start-ci-run --distribute-on="8 linux-medium-js" --stop-agents-after="e2e-ci" 9 - ... 10

This works great but may not be the most cost-effective way to run your tasks. The goal is to balance cost and speed. For example, you might want to run a small PR on a few agents to save costs, but use many agents for a large PR to get the fastest possible build time.

Configure Dynamic Agents based on PR size

Instead of using a static configuration of agents (like the one shown above), you can also configure to use a different number and type of agents based on the size of your PR.

Create a file called dynamic-changesets.yaml in the .nx/workflows directory of your repo.

.nx/workflows/dynamic-changesets.yaml
1distribute-on: 2 small-changeset: 3 linux-medium-js 3 medium-changeset: 6 linux-medium-js 4 large-changeset: 10 linux-medium-js 5
How is the size of the PR determined?

You can then reference it in your CI pipeline configuration:

.github/workflows/main.yaml
1... 2jobs: 3 - job: main 4 displayName: Main Job 5 ... 6 steps: 7 ... 8 - run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --stop-agents-after="e2e-ci" 9 - ... 10

Now, PRs that affect a small percentage of the repo will run on 3 agents, mid-size PRs will use 6 agents, and large PRs will use 10 agents. This feature helps save costs on smaller PRs while maintaining the high performance necessary for large PRs.