Skip to content

Feature: agent-job-level if:/ eeds: hook to gate the agent on a custom setup job #38564

Description

@Evangelink

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:

  1. 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).
  2. 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.
  3. 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

  • gh-aw: v0.75.x

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions