Summary
Provide a first-class way to make the agent job depend on (and be conditionally skipped by) a user-defined custom job declared in the workflow frontmatter — equivalent to an agent.needs: / agent.if: knob.
Motivation
Today the only ways to gate the AI agent on the outcome of work that must happen before the agent runs are:
- Put all the setup logic inline in
steps:/pre-agent-steps: and accept that the agent boots even when the setup signals "nothing to do" (wastes Copilot/AI budget, spams report-failure-as-issue).
- Reach into the compiled
*.lock.yml and add a custom job + wire needs: / if: onto the agent job by hand — which we obviously can't do because gh-aw owns that file.
- Use the
pre_activation.needs: trick + a top-level if: on the workflow to cascade-skip activation → agent. This works but is non-obvious, undocumented, and breaks down the moment you also want the agent to see the upstream job's outputs cleanly.
We hit this concretely on a build-failure-analysis workflow that should only invoke an AI agent when the build is red. To get there we ended up with a ~100-line custom build: job in the workflow source, plus this pattern in the frontmatter:
on:
needs: [build] # pre_activation / activation now wait for `build`
if: needs.build.outputs.outcome == 'failure' # cascades to activation → agent skipped
That works, but:
Workaround reference: microsoft/testfx#8738 — "Skip build-failure-analysis agent on green builds".
Proposed solution
Add explicit frontmatter:
jobs:
build: { ... custom job ... }
agent:
needs: [build]
if: needs.build.outputs.outcome == 'failure'
…that compiles to needs: and if: directly on the generated agent job, with needs.build.outputs.* resolvable in the agent prompt's env injection. This eliminates the pre_activation.needs + top-level-if: cascade trick.
Related
Environment
Summary
Provide a first-class way to make the
agentjob depend on (and be conditionally skipped by) a user-defined custom job declared in the workflow frontmatter — equivalent to anagent.needs:/agent.if:knob.Motivation
Today the only ways to gate the AI agent on the outcome of work that must happen before the agent runs are:
steps:/pre-agent-steps:and accept that the agent boots even when the setup signals "nothing to do" (wastes Copilot/AI budget, spamsreport-failure-as-issue).*.lock.ymland add a custom job + wireneeds:/if:onto theagentjob by hand — which we obviously can't do because gh-aw owns that file.pre_activation.needs:trick + a top-levelif:on the workflow to cascade-skipactivation→agent. This works but is non-obvious, undocumented, and breaks down the moment you also want the agent to see the upstream job's outputs cleanly.We hit this concretely on a build-failure-analysis workflow that should only invoke an AI agent when the build is red. To get there we ended up with a ~100-line custom
build:job in the workflow source, plus this pattern in the frontmatter:That works, but:
on.needs:cascading intoactivationis undocumented and surprising (and reportedly was the cause of Bug: on.needs directive leaks into emitted on: block (invalid Actions YAML) #35943).if:is repurposed to mean "skip the agent" — there is no real "agent-job-levelif:".Workaround reference: microsoft/testfx#8738 — "Skip build-failure-analysis agent on green builds".
Proposed solution
Add explicit frontmatter:
…that compiles to
needs:andif:directly on the generatedagentjob, withneeds.build.outputs.*resolvable in the agent prompt's env injection. This eliminates thepre_activation.needs+ top-level-if:cascade trick.Related
on.needsleaking into emittedon:block; the workaround above relies on a related (still surprising) behavior.Environment