Repository navigation
Description
We'd like a workflow to choose its routing level at run time through the model: field it already has, for example
model: ${{ inputs.level || 'router/balanced' }}, with the value resolved once at activation. Today a router value
has to be written literally, so a workflow is pinned to one level. Allowing it from an expression lets external
context, memory or a separate decision set the level, without adding another routing setting next to model: router/* and engine.model-routing.
The right level often depends on something only known when the run starts: which item an orchestrator is dispatching,
what a change touches, or how the last ten runs of this workflow went. model: router can't see any of that, because
its classifier only reads the prompt, and it judges how hard the task looks rather than how much a mistake would cost.
The only way to vary the level today is to keep one copy of the workflow per level. #76599 anticipated this: once
routing can be written as a model name, the places that take a model name can ask for routing without new settings.
Use cases
Each example below uses only existing frontmatter and compiles on main (3c70a0d). What's missing is the run-time
behavior: today each one stops before the agent starts as soon as the expression yields a router value. The examples
use ordinary Actions expressions. a || b gives a unless it is empty, and otherwise b; gh-aw's own lock files
already use it for the model variables (vars.GH_AW_MODEL_AGENT_COPILOT || vars.GH_AW_DEFAULT_MODEL_COPILOT || 'auto'). The fallback is optional, and without it an empty value falls back the way it does today. case(pred, a, b)
gives a when pred is true and b otherwise.
An orchestrator sets the level per item. A workflow that fans out a security review across hundreds of
repositories sends most items to economy and the few high-stakes ones to robust. The worker opts in to the input:
on:
workflow_dispatch:
inputs:
level: { type: string }
model: ${{ inputs.level || 'router/economy' }}A rule over the event. Pull requests labeled security get robust review and everything else economy, with no
extra step:
on:
pull_request:
types: [opened, labeled]
model: ${{ case(contains(github.event.pull_request.labels.*.name, 'security'), 'router/robust', 'router/economy') }}Context computed before the agent. A pull request reviewer runs a deterministic pre-activation step that inspects
the change, here by counting changed files, and prints a level:
on:
pull_request:
types: [opened, synchronize]
permissions:
pull-requests: read
steps:
- id: scope
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
run: |
files=$(gh pr diff "$PR" --repo "$GITHUB_REPOSITORY" --name-only | wc -l)
if [ "$files" -gt 20 ]; then echo "level=router/robust"; else echo "level=router/economy"; fi >> "$GITHUB_OUTPUT"
jobs:
pre-activation:
outputs:
level: ${{ steps.scope.outputs.level }}
model: ${{ needs.pre_activation.outputs.level || 'router/balanced' }}Adapting from history. A nightly workflow keeps its outcomes in repo-memory, which on.restore-memory: true
restores before the pre-activation steps. It moves to robust when two of the last five runs failed, and back to
balanced once they pass:
on:
schedule: daily
restore-memory: true
steps:
- id: adapt
run: |
fails=$(tail -n 5 /tmp/gh-aw/repo-memory/default/outcomes.jsonl 2>/dev/null | grep -c '"passed": *false' || true)
if [ "${fails:-0}" -ge 2 ]; then echo "level=router/robust"; else echo "level=router/balanced"; fi >> "$GITHUB_OUTPUT"
jobs:
pre-activation:
outputs:
level: ${{ steps.adapt.outputs.level }}
tools:
repo-memory: true
model: ${{ needs.pre_activation.outputs.level }}The prompt asks the agent to append {"date": ..., "passed": true or false} to outcomes.jsonl in its memory folder.
For a signal the agent can't influence, a small workflow on workflow_run can record the run's eval answer or CI result
instead.
Measuring which level a workflow needs. With router values as experiment variants, gh-aw assigns a level to each
run and gh aw experiments analyze reports the eval pass rate for each level, so a maintainer can pick the cheapest one
that works:
evals:
- id: solved
question: Does the test suite pass after the agent's change?
experiments:
level:
variants: [router/economy, router/balanced, router/robust]
metric: eval:solved
model: ${{ experiments.level }}A decision with the user's own criteria. A cheap triage workflow applies the rubric in its prompt and dispatches
the worker. Because the decision is itself a gh-aw run, it is metered, covered by the model policy and recorded. The
worker accepts a raise to robust and otherwise stays at its floor of balanced:
# triage.md
on:
issues:
types: [opened]
model: small
max-ai-credits: 20
safe-outputs:
dispatch-workflow: [fix-issue]
---
Read issue #${{ github.event.issue.number }}. Choose router/robust if it touches authentication, billing or data
migrations, router/economy for typos and docs, and router/balanced otherwise. Dispatch fix-issue with the issue
number and that level.# fix-issue.md
on:
workflow_dispatch:
inputs:
issue: { type: string, required: true }
level: { type: string }
model: ${{ case(inputs.level == 'router/robust', 'router/robust', 'router/balanced') }}Escalating on retry. A re-run gets the stronger level. Because "Re-run failed jobs" reuses activation's outputs,
escalation needs "Re-run all jobs" or a fresh dispatch:
model: ${{ case(fromJSON(github.run_attempt) > 1, 'router/robust', 'router/balanced') }}What happens today
The model-routing reference says that an expression or variable resolving to a router value "stops the run before the
agent starts." The compiler doesn't warn: model: ${{ inputs.level || 'router/balanced' }} compiles on main
(3c70a0d) with no routing in the lock file and fails only when the run starts.
There is also a bug that affects plain model names. The model: expression is copied into, and evaluated separately
by, the activation, agent and safe-outputs jobs. A model chosen in pre-activation is therefore empty in the agent job,
which only depends on activation. Compiling model: ${{ needs.pre_activation.outputs.next_model }} on main gives:
warning: [needs-consistency] Needs expression references a job outside direct needs; ... at jobs.agent.steps[27].env.COPILOT_MODEL
warning: [needs-consistency] Needs expression references a job outside direct needs; ... at jobs.safe_outputs.env.GH_AW_ENGINE_MODEL
Proposed design
- Where the main agent's model is a single
model:orengine.modelexpression, its value may berouter,
router/economy,router/balancedorrouter/robust, as well as anything accepted today. This applies on
Copilot, Claude and Codex workflows that would otherwise be eligible for default routing. - Activation evaluates the selector once, after experiment selection, and publishes the resolved value, whether
routing is on, and the mode. Every later job uses those outputs instead of re-evaluating the expression. This
also fixes the pre-activation bug for concrete models. Activation fixes the requested selector, not the model: the
router or alias resolution still picks the model and effort when the agent starts, and that is still reported from
the agent job. - For a dynamic selector the compiler emits both a routed and a non-routed path, as default routing already does,
with the mode supplied at run time. - An empty value falls back as it does today, to
GH_AW_MODEL_AGENT_<ENGINE>, thenGH_AW_DEFAULT_MODEL_<ENGINE>,
then the engine's own default, without routing. A workflow that wants a particular default writes it into the
expression. - The rules for literal router values carry over: router values can't be combined with an
engine.model-routing
block,engine.model-routing: falseorengine.fallback-models, and on those workflows nothing changes. Threat
detection, sub-agents and evals never receive a router value; on a routed run, threat detection uses its own
default. The routing goal iscost, andmodels.allowedandmodels.blockedstill narrow the choice. - Values are checked when activation resolves them:
router/fast,Router/Economyandrouter/economy?effort=high
are rejected before the agent starts. A dynamic model uses the declaredengine.model-provideror the engine's
default provider. aw_info.jsonrecords the requested selector and the routing mode as it does for literal values.
Why this design
It keeps one routing surface. The logic that picks a level, whether rules, memory or another model, lives in ordinary
workflow steps and dispatches, so it can grow without new frontmatter. It also reuses patterns gh-aw already has:
activation already decides default routing at run time, and experiments already pass a chosen model downstream as an
activation output.
A workflow that must not drop below a level enforces that in its own expression, as fix-issue does above: it accepts
only a recognized higher value and falls back to its floor otherwise.
We don't propose restricting which contexts model: may read. The resolved value is checked against the four router
values and the model policy, so a hostile input can at worst choose another allowed level or model, which a floor
bounds. The docs should still prefer comparisons over passing user-controlled text straight through.
Switching model family needs no new setting either. A decider can output a concrete model or alias that
models.allowed permits, so dynamic allowed-models isn't needed.
Out of scope
Router values in the GH_AW_MODEL_AGENT_<ENGINE> and GH_AW_DEFAULT_MODEL_<ENGINE> variables, which would let an
organization set a default level, are a natural follow-up, but threat detection and evals read the same variables, so
they need their own guards; until then a router value there still stops the run. Pi, whose routed path has no run-time
switch yet, is another follow-up. Also out of scope: expressions in allowed-models; new frontmatter for deciders,
floors or adaptation; a hook that calls a model before the agent; a routing goal from expressions; router values for
sub-agents; and changing the model during a run.
Docs and tests
The model-routing reference should describe choosing the level at run time and update its "Router value restrictions"
section, and the model alias specification should allow router values from a main-agent model expression.
Tests should cover:
- router, concrete and mixed experiment variants;
- an experiment named
model, so the new activation outputs can't be shadowed; - an empty value;
- threat detection on a routed run;
- the pre-activation output case above;
- an invalid router value from an input;
- the dual routed and non-routed paths on Copilot, Claude and Codex.
Activity