-
Notifications
You must be signed in to change notification settings - Fork 2
461 lines (423 loc) · 18.3 KB
/
Copy pathreusable.yml
File metadata and controls
461 lines (423 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# Copyright Advanced Micro Devices, Inc.
#
# SPDX-License-Identifier: MIT
name: reusable
# Grade a repo's skills, one runner per skill.
#
# jobs:
# evals:
# uses: amd/skillscope/.github/workflows/reusable.yml@v0.1.3
# secrets:
# api_key: ${{ secrets.ANTHROPIC_API_KEY }}
# with:
# skills: TraceLens/Agent/Analysis/skills/analysis-orchestrator
#
# That is a whole caller. Everything else has a default, and the defaults are
# the strict answer: every step runs, and every step can fail the run.
#
# discover --> structural --> routing (one runner per skill)
# --> behavioral (one runner per skill)
# --> results
#
# `skills` is a directory or a glob matching several, one per line or comma-
# separated, and every skill it names is graded on a runner of its own. Ten
# skills is ten routing legs and ten behavioral legs, all at once, each with its
# own check and its own report -- not one job walking a list, where the ninth
# skill waits on the eighth and the first failure buries the rest.
#
# Each step is `required`, `optional`, or `off`:
#
# with:
# skills: skills/*
# routing: optional # graded and reported, but cannot fail the run
# behavioral: off # not run at all
#
# `optional` is for a bar you have not met yet: the leg runs, the report lands
# in the step summary, and a red leg leaves the run green. `off` does not run it
# at all. Both are one-word diffs a reviewer can see, which is the point: a step
# nobody can see being dropped is a step nobody notices is gone.
#
# Every routing leg installs one skill, so it asks the half of the routing
# question a skill can be asked alone -- does it fire on its own prompts, and
# does it stay quiet on its own near misses and on the shared negatives? It
# cannot ask the other half, whether this skill answers a prompt that belongs to
# its neighbour, because the neighbour is not in the room. When two skills in a
# repo could plausibly be confused for one another, that second half is the
# whole point, and .github/workflows/skill-evals.yml is the pipeline that grades
# it: it pools their datasets into one routing run, and adds change-based
# selection and scoped hardware besides.
#
# The structural checks are one job rather than one per skill. They cost
# nothing, and half of what they check is about the set -- two skills claiming
# the same name, two datasets claiming the same case id -- which a job that
# could only see one skill would have to miss.
#
# The caller maps one secret onto `api_key`, so this workflow never learns
# anything else in the vault. `secrets: inherit` still works if you would rather
# pass the vault and name the key with `api_key_secret`; it is more than this
# workflow needs. A key issued by a gateway rather than the provider also needs
# `api_base_url`, and `api_custom_headers` if the gateway reads the key from a
# header of its own:
#
# with:
# api_base_url: https://gateway.example.com/anthropic
# api_custom_headers: |
# Ocp-Apim-Subscription-Key: $API_KEY
#
# The `uses:` pin on this workflow is the harness that runs. GitHub does not
# let a reusable workflow interpolate that pin into `uses: amd/skillscope@...`,
# so each job checks out this repository at `job.workflow_sha` (the commit the
# caller referenced) and runs the composite action from that tree. Pinning
# `@v0.1.3` grades with v0.1.3, `@main` grades with main, and a branch grades
# with that branch -- so there is no release ritual and nothing to keep in step.
on:
workflow_call:
inputs:
skills:
description: >-
The skills to grade: a directory, or a glob matching several, one per
line or comma-separated, relative to the repository root. Each one is
graded on a runner of its own. The default is every directory at the
root; a repo that keeps its skills together says so with `skills/*`.
type: string
default: "./*"
structural:
description: >-
Skill folders, datasets, and the references their markdown makes. No
agent, no tokens. `required`, `optional`, or `off`.
type: string
default: required
routing:
description: >-
Whether a skill fires on its own prompts and stays quiet on its near
misses. `required`, `optional`, or `off`.
type: string
default: required
behavioral:
description: >-
What a skill does once it has fired. `required`, `optional`, or `off`.
type: string
default: required
runner:
description: "`runs-on` for every job: one label, or a JSON array of them."
type: string
default: ubuntu-latest
min_accuracy:
description: >-
Fail a routing leg below this accuracy (0-1). The default fails on any
wrong routing decision; `0` reports the score without gating on it.
type: string
default: "1"
api_key_secret:
description: >-
Name of the secret holding the model API key when the caller uses
`secrets: inherit`. Prefer mapping that secret onto `api_key` instead.
Blank means the runner is already authenticated and no key is exported.
type: string
default: ANTHROPIC_API_KEY
api_base_url:
description: >-
ANTHROPIC_BASE_URL for the routing and behavioral legs, for a key that
belongs to a gateway rather than to the provider. Blank uses the
provider default.
type: string
default: ""
api_custom_headers:
description: >-
ANTHROPIC_CUSTOM_HEADERS for the routing and behavioral legs, one
`Name: value` per line. `$API_KEY` is replaced with the key, so a
gateway that wants the key in its own header needs no second secret.
type: string
default: ""
secrets:
api_key:
description: >-
Model API key for the routing and behavioral legs. Map your repository
secret here; this workflow does not need the rest of the vault. Leave
it unset if the runner is already authenticated, or if you pass
`secrets: inherit` and name the key with `api_key_secret`.
required: false
permissions:
contents: read
jobs:
# Which skills are there, and are the three step inputs words this workflow
# knows? Both answers are wanted before a runner installs anything, and a
# mistyped path has to be an error rather than an empty matrix -- a run that
# graded nothing would otherwise pass, which is the one way a green check can
# lie about a skill.
discover:
name: Discover Skills
# A label or a JSON array, so `runner: ubuntu-latest` and
# `runner: '["self-hosted", "gpu"]'` both say what they look like.
runs-on: ${{ startsWith(inputs.runner, '[') && fromJSON(inputs.runner) || inputs.runner }}
outputs:
skills: ${{ steps.matrix.outputs.skills }}
count: ${{ steps.matrix.outputs.count }}
globs: ${{ steps.globs.outputs.globs }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Check out skillscope
uses: actions/checkout@v4
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .skillscope-action
# One glob per line is how a list wants to be written in YAML, and commas
# are what every skillscope flag takes. Accept both, pass on one.
- name: Read the skill list
id: globs
shell: python
env:
SKILLS: ${{ inputs.skills }}
run: |
import os
import sys
raw = os.environ.get("SKILLS", "")
globs = ",".join(
part.strip() for part in raw.replace("\n", ",").split(",") if part.strip()
)
if not globs:
sys.exit("error: 'skills' is empty, so there is nothing to grade.")
print("skills: " + globs)
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out:
out.write("globs=" + globs + "\n")
# The harness answers this, rather than a glob walk written here: which
# directories are skills, and which of those ship a dataset, are questions
# about the repo under test that the CLI already answers the same way for
# everything else that runs against it.
- name: List the skills
id: found
uses: ./.skillscope-action
with:
command: list-skills
skills: ${{ steps.globs.outputs.globs }}
- name: Build the matrix
id: matrix
shell: python
env:
FOUND: ${{ steps.found.outputs.stdout }}
GLOBS: ${{ steps.globs.outputs.globs }}
STRUCTURAL: ${{ inputs.structural }}
ROUTING: ${{ inputs.routing }}
BEHAVIORAL: ${{ inputs.behavioral }}
run: |
import json
import os
import sys
MODES = ("required", "optional", "off")
steps = {
name: os.environ[name.upper()]
for name in ("structural", "routing", "behavioral")
}
wrong = [f"{k}: {v!r}" for k, v in steps.items() if v not in MODES]
if wrong:
sys.exit(
"error: every step is `required`, `optional`, or `off`, in "
"lowercase. Got " + "; ".join(wrong) + "."
)
skills = json.loads(os.environ["FOUND"])
if not skills:
sys.exit(
f"error: no skill with a dataset under {os.environ['GLOBS']}. "
"A skill is a directory holding a SKILL.md, and it is graded "
"here once it also has an evals/evals.json beside it -- "
"`skillscope template` prints one to start from. Check the "
"paths in `skills`, which are relative to the repository root."
)
print(f"{len(skills)} skill(s), one runner each: " + ", ".join(skills))
print("steps: " + ", ".join(f"{k} {v}" for k, v in steps.items()))
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out:
out.write("skills=" + json.dumps(skills, separators=(",", ":")) + "\n")
out.write(f"count={len(skills)}\n")
summary = os.environ.get("GITHUB_STEP_SUMMARY", "")
if summary:
with open(summary, "a", encoding="utf-8") as out:
out.write(
"### skillscope\n\n"
+ " · ".join(f"{k}: **{v}**" for k, v in steps.items())
+ "\n\n| skill |\n| --- |\n"
+ "\n".join(f"| `{skill}` |" for skill in skills)
+ "\n\n"
)
# Free and offline, so it runs before anything that spends a token and gates
# it: a malformed dataset should not be found halfway through a paid run.
structural:
name: Structural Tests
needs: discover
if: inputs.structural != 'off'
runs-on: ${{ startsWith(inputs.runner, '[') && fromJSON(inputs.runner) || inputs.runner }}
# `optional` changes nothing about the run except what it can do to the
# result: the checks still run, and the report still lands.
continue-on-error: ${{ inputs.structural != 'required' }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Check out skillscope
uses: actions/checkout@v4
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .skillscope-action
- name: Check every skill's structure
uses: ./.skillscope-action
with:
command: structural
skills: ${{ needs.discover.outputs.globs }}
routing:
name: Routing Tests (${{ matrix.skill }})
needs: [discover, structural]
# Read as: run unless routing is off, or the structural checks were meant to
# gate it and did not pass. `!cancelled()` rather than `success()` so that a
# structural job which is allowed to fail cannot hold this one back.
if: >-
${{ !cancelled()
&& needs.discover.result == 'success'
&& inputs.routing != 'off'
&& (inputs.structural != 'required' || needs.structural.result != 'failure') }}
runs-on: ${{ startsWith(inputs.runner, '[') && fromJSON(inputs.runner) || inputs.runner }}
continue-on-error: ${{ inputs.routing != 'required' }}
timeout-minutes: 40
strategy:
# One skill's score should not hide the others'.
fail-fast: false
matrix:
skill: ${{ fromJSON(needs.discover.outputs.skills) }}
env:
ANTHROPIC_API_KEY: ${{ secrets.api_key || secrets[inputs.api_key_secret] }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Check out skillscope
uses: actions/checkout@v4
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .skillscope-action
- name: Resolve the model credentials
env:
EXPECT_KEY: ${{ inputs.routing != 'off' && (inputs.api_key_secret != '' || secrets.api_key != '') }}
API_BASE_URL: ${{ inputs.api_base_url }}
API_CUSTOM_HEADERS: ${{ inputs.api_custom_headers }}
run: python .skillscope-action/skillscope/credentials.py --reusable
- name: Run the routing eval for ${{ matrix.skill }}
uses: ./.skillscope-action
with:
command: routing
# One skill in the room, named, so the score is about this skill alone
# whatever else the repo ships. A wrong routing decision fails the leg
# by default; `min_accuracy` lowers that bar and `routing: optional`
# removes it.
args: >-
--routing-room '${{ matrix.skill }}'
--min-accuracy '${{ inputs.min_accuracy }}'
--output routing-report.json
--keep-logs routing-logs
skills: ${{ needs.discover.outputs.globs }}
install-claude: "true"
- name: Upload the routing report
if: always()
uses: actions/upload-artifact@v4
with:
name: routing-${{ matrix.skill }}
path: |
routing-report.json
routing-logs/
if-no-files-found: warn
behavioral:
name: Behavioral Tests (${{ matrix.skill }})
needs: [discover, structural]
if: >-
${{ !cancelled()
&& needs.discover.result == 'success'
&& inputs.behavioral != 'off'
&& (inputs.structural != 'required' || needs.structural.result != 'failure') }}
runs-on: ${{ startsWith(inputs.runner, '[') && fromJSON(inputs.runner) || inputs.runner }}
continue-on-error: ${{ inputs.behavioral != 'required' }}
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
skill: ${{ fromJSON(needs.discover.outputs.skills) }}
env:
ANTHROPIC_API_KEY: ${{ secrets.api_key || secrets[inputs.api_key_secret] }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Check out skillscope
uses: actions/checkout@v4
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: .skillscope-action
- name: Resolve the model credentials
env:
EXPECT_KEY: ${{ inputs.behavioral != 'off' && (inputs.api_key_secret != '' || secrets.api_key != '') }}
API_BASE_URL: ${{ inputs.api_base_url }}
API_CUSTOM_HEADERS: ${{ inputs.api_custom_headers }}
run: python .skillscope-action/skillscope/credentials.py --reusable
- name: Run the behavioral cases for ${{ matrix.skill }}
uses: ./.skillscope-action
with:
command: behavioral
args: >-
--skill '${{ matrix.skill }}'
--output behavioral-report.json
skills: ${{ needs.discover.outputs.globs }}
install-claude: "true"
- name: Upload the behavioral report
if: always()
uses: actions/upload-artifact@v4
with:
name: behavioral-${{ matrix.skill }}
path: behavioral-report.json
if-no-files-found: warn
# One check to read, and the one to point branch protection at: what ran, what
# it did, and whether anything that was allowed to fail did.
results:
name: Results
needs: [discover, structural, routing, behavioral]
if: ${{ !cancelled() }}
runs-on: ${{ startsWith(inputs.runner, '[') && fromJSON(inputs.runner) || inputs.runner }}
steps:
- name: Verify the results
shell: python
env:
DISCOVER: ${{ needs.discover.result }}
SKILLS: ${{ needs.discover.outputs.count }}
STRUCTURAL: ${{ needs.structural.result }}
ROUTING: ${{ needs.routing.result }}
BEHAVIORAL: ${{ needs.behavioral.result }}
STRUCTURAL_MODE: ${{ inputs.structural }}
ROUTING_MODE: ${{ inputs.routing }}
BEHAVIORAL_MODE: ${{ inputs.behavioral }}
run: |
import os
import sys
discover = os.environ["DISCOVER"]
if discover != "success":
sys.exit(
f"The discover job did not succeed ({discover}), so nothing was graded."
)
steps = [
(name, os.environ[name.upper() + "_MODE"], os.environ[name.upper()])
for name in ("structural", "routing", "behavioral")
]
print("skills graded: " + os.environ.get("SKILLS", ""))
print(f"{'step':<12} {'mode':<10} result")
for name, mode, result in steps:
print(f"{name:<12} {mode:<10} {result}")
# A required step that failed fails the run here as well as on its own
# job, so this one check is the whole answer. A skipped step is not
# judged: either it is off, or the structural checks it waited on
# failed and have already said so.
failed = False
for name, mode, result in steps:
if mode == "required" and result not in ("success", "skipped"):
print(f"::error::{name} is required and did not pass ({result}).")
failed = True
elif mode != "required" and result == "failure":
print(f"::warning::{name} failed, and is {mode}, so it does not fail the run.")
if failed:
sys.exit(1)
print("Every required step passed.")