-
Notifications
You must be signed in to change notification settings - Fork 190
eval: skill comparison script #3070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JasonYeMSFT (JasonYeMSFT)
wants to merge
22
commits into
main
Choose a base branch
from
chuye/no-skill-compare-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+508
−6
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b8eb58c
test compare script
JasonYeMSFT dfc5835
tweak input and output format
JasonYeMSFT c71556c
analyze-comparison-tests skill
JasonYeMSFT 5291e8f
use input for azure-resource-lookup
JasonYeMSFT d148627
update sample output to match sample input
JasonYeMSFT 0d4dc2c
fix compare script for boolean input
JasonYeMSFT aa0cc30
update artifacts layout in analyze-comparison-tests skill
JasonYeMSFT 3df58d3
rewrite collect-artifacts script in TS
JasonYeMSFT c039c89
azure-resource-lookup comparison report
JasonYeMSFT e19e18c
sample per stimuli comparison reports
JasonYeMSFT 1e9ce2d
move files to comparison folder
JasonYeMSFT de608c7
compare against different branches
JasonYeMSFT 6d5a5b4
update shortcut command
JasonYeMSFT 26a971a
delete temporary files
JasonYeMSFT adb424c
revert test change
JasonYeMSFT f5aeda8
update analyze-comparison-tests skill
JasonYeMSFT abc194e
delete sample files
JasonYeMSFT 875eaa9
uncomment all models in default comparison config
JasonYeMSFT 227b620
fix lint
JasonYeMSFT dc622f8
address copilot feedback
JasonYeMSFT 8c93dd1
execSync -> execFileSync
JasonYeMSFT c8ed45c
Potential fix for pull request finding
JasonYeMSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| name: analyze-comparison-tests | ||
| description: "Collects comparison test run artifacts and answers the user's questions based on the trajectories of each run. WHEN TO USE: collect comparison test artifacts" | ||
| license: MIT | ||
| metadata: | ||
| author: Microsoft | ||
| version: "1.0.0" | ||
| --- | ||
|
|
||
| # Steps | ||
|
|
||
| 1. Collect run artifacts | ||
|
|
||
| Execute the collect-artifacts script to download the test run artifacts. | ||
|
|
||
| The user must provide an JSON file to correlate each comparison test run with the GitHub Actions run. The script expects one input argument as the path to this JSON file. The JSON input is supposed to be the JSON output when queuing the comparison test runs using the `npm run compare:run` command. | ||
|
|
||
| ```bash | ||
| cd tests/ | ||
| npm run compare:collect -- input.json | ||
| ``` | ||
|
|
||
| The collect-artifacts script will download the test run artifacts to a directory named `comparison-artifacts` in the current working directory. Before executing the script, check if there is already such an directory. If so, skip executing the script and proceed to step 2. | ||
|
|
||
| 2. Extract insights | ||
|
|
||
| The downloaded artifacts will have the following folder structure: | ||
|
|
||
| ```text | ||
| comparison-artifacts/ | ||
| ├── <branch-name>/ | ||
| │ ├── <stimulus-name-1>/ | ||
| │ │ ├── <model>-with-skill/ | ||
| │ │ │ ├── agent-metadata-<date-string-1>.md | ||
| │ │ │ ├── agent-metadata-<date-string-2>.md | ||
| │ │ │ └── ... | ||
| │ │ └── <model>-without-skill/ | ||
| │ │ ├── agent-metadata-<date-string-1>.md | ||
| │ │ ├── agent-metadata-<date-string-2>.md | ||
| │ │ └── ... | ||
| │ └── <stimulus-name-2>/ | ||
| │ ├── <model>-with-skill/ | ||
| │ │ └── agent-metadata-*.md | ||
| │ └── <model>-without-skill/ | ||
| │ └── agent-metadata-*.md | ||
| └── <branch-name-2>/ | ||
| └── ... | ||
| ``` | ||
|
|
||
| Each `<branch-name>/<stimulus-name>/<model>-with-skill` or `<branch-name>/<stimulus-name>/<model>-without-skill` directory contains the test run trajectories for that stimulus and model on that branch, with or without skills. Each trajectory is a markdown file that records user prompts, tool call requests, tool execution results, assistant responses that happened during the run. It also contains statistics such as token usage and turns. Based on the trajectories, answer the user's questions for each test run. Generate a report following the [report-template](./references/report-template.md) to show your answers. | ||
19 changes: 19 additions & 0 deletions
19
.github/skills/analyze-comparison-tests/references/report-template.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Comparison Report | ||
|
|
||
| Skill: {plugin dirname/skill name} | ||
|
|
||
| ## Answers | ||
|
|
||
| ### {User question 1} | ||
|
|
||
| {Answer to question 1} | ||
|
|
||
| ### {User question 2} | ||
|
|
||
| {Answer to question 2} | ||
|
|
||
| ...... | ||
|
|
||
| ### {User question N} | ||
|
|
||
| {Answer to question N} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| reports/ | ||
| node_modules/ | ||
| coverage/ | ||
| comparison-artifacts/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| /** | ||
| * collect-artifacts.ts — download comparison test trajectories from Azure Storage. | ||
| * | ||
| * Usage: tsx collect-artifacts.ts <input.json> | ||
| * | ||
| * Exit codes: | ||
| * 0 = success (all runs collected) | ||
| * 1 = a step failed (missing dependency, Azure error, or no blobs found) | ||
| * 2 = usage/argument error | ||
| */ | ||
|
|
||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { execFileSync } from "child_process"; | ||
| import type { CompareRunOutput } from "./run-compare"; | ||
|
|
||
| const STORAGE_ACCOUNT = "strdashboarddevveobvk"; | ||
| const CONTAINER = "manual-integration-reports"; | ||
| const OUTPUT_ROOT = "comparison-artifacts"; | ||
|
|
||
| function usage(): void { | ||
| console.log(`Usage: collect-artifacts.ts <input.json> | ||
|
|
||
| Exit codes: | ||
| 0 = success (all runs collected) | ||
| 1 = a step failed (missing dependency, Azure error, or no blobs found) | ||
| 2 = usage/argument error`); | ||
| } | ||
|
|
||
| function encodeBranchName(branch: string) { | ||
| return branch.replaceAll("/", "_"); | ||
| } | ||
|
|
||
| function run(): void { | ||
| const args = process.argv.slice(2); | ||
|
|
||
| if (args.length === 1 && (args[0] === "-h" || args[0] === "--help")) { | ||
| usage(); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| if (args.length !== 1) { | ||
| console.error( | ||
| "Error: expected exactly one argument (path to the input JSON file)." | ||
| ); | ||
| usage(); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| const inputFile = args[0]; | ||
|
|
||
| if (!fs.existsSync(inputFile)) { | ||
| console.error(`Error: input file not found: ${inputFile}`); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| let input: CompareRunOutput; | ||
| try { | ||
| const content = fs.readFileSync(inputFile, "utf-8"); | ||
| input = JSON.parse(content); | ||
| } catch (err: unknown) { | ||
| const msg = err instanceof Error ? err.message : "unknown error"; | ||
| console.error(`Error: failed to parse input JSON: ${msg}`); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| const date = input.date || ""; | ||
| const skillName = input.skill?.name || ""; | ||
|
|
||
| if (!date || !skillName) { | ||
| console.error("Error: input JSON must define 'date' and 'skill.name'."); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| if (!input.results || input.results.length === 0) { | ||
| console.error("Error: input JSON contains no runs."); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| // Create output directory | ||
| if (!fs.existsSync(OUTPUT_ROOT)) { | ||
| fs.mkdirSync(OUTPUT_ROOT, { recursive: true }); | ||
| } | ||
|
|
||
| let failed = 0; | ||
|
|
||
| for (const result of input.results) { | ||
| const branch = result.branch; | ||
| const runs = result.runs; | ||
| for (const run of runs) { | ||
| const model: string = run.model; | ||
| const withSkill: boolean = run.withSkill; | ||
| const runUrl: string = run.run; | ||
|
|
||
| if (!model) continue; | ||
|
|
||
| // Extract run ID from GitHub Actions URL | ||
| const runId = runUrl.split("/").pop(); | ||
| if (!runId) { | ||
| console.error(`Error: could not extract run id from URL: ${runUrl}`); | ||
| failed = 1; | ||
| continue; | ||
| } | ||
|
|
||
| const skillSuffix = withSkill ? "with-skill" : "without-skill"; | ||
|
|
||
| // Discover stimuli for this run | ||
| const prefix = `${date}/${runId}/${skillName}/${skillName}_`; | ||
| console.log( | ||
| `Discovering stimuli for run ${runId} under ${CONTAINER}/${prefix} ...` | ||
| ); | ||
|
|
||
| let discoveryResult: string; | ||
| try { | ||
| discoveryResult = execFileSync("az", [ | ||
| "storage", "blob", "list", | ||
| "--account-name", STORAGE_ACCOUNT, | ||
| "--container-name", CONTAINER, | ||
| "--prefix", prefix, | ||
| "--auth-mode", "login", | ||
| "--query", "[?ends_with(name, '.md')].name", | ||
| "-o", "tsv" | ||
| ], { | ||
| encoding: "utf-8", | ||
| stdio: ["pipe", "pipe", "ignore"] | ||
| }) as string; | ||
|
JasonYeMSFT marked this conversation as resolved.
|
||
| } catch { | ||
| console.error(`Error: failed to discover blobs for run ${runId}.`); | ||
| failed = 1; | ||
| continue; | ||
| } | ||
|
|
||
| // Extract unique stimuli names from blob paths | ||
| const blobLines = discoveryResult.trim().split("\n").filter((line: string) => line); | ||
| const stimuliSet: Set<string> = new Set(); | ||
|
|
||
| for (const blob of blobLines) { | ||
| const regexPattern = new RegExp(`/${skillName}_([^/]+)/`); | ||
| const match = blob.match(regexPattern); | ||
| if (match) { | ||
| stimuliSet.add(match[1]); | ||
| } | ||
| } | ||
|
|
||
| if (stimuliSet.size === 0) { | ||
| console.warn( | ||
| `Warning: no stimuli directories discovered for run ${runId}` | ||
| ); | ||
| continue; | ||
| } | ||
|
JasonYeMSFT marked this conversation as resolved.
|
||
|
|
||
| console.log( | ||
| `Discovered stimuli for run ${runId}: ${Array.from(stimuliSet).join(", ")}` | ||
| ); | ||
|
|
||
| for (const stimuliPart of stimuliSet) { | ||
| const stimuliOutputDir = path.join( | ||
| OUTPUT_ROOT, | ||
| encodeBranchName(branch), | ||
| stimuliPart, | ||
| `${model}-${skillSuffix}` | ||
| ); | ||
| const blobPrefix = `${date}/${runId}/${skillName}/${skillName}_${stimuliPart}/agent-metadata-`; | ||
|
|
||
| console.log( | ||
| `Listing blobs for stimuli '${stimuliPart}' in run ${runId} ...` | ||
| ); | ||
|
|
||
| let blobs: string; | ||
| try { | ||
| blobs = execFileSync("az", [ | ||
| "storage", "blob", "list", | ||
| "--account-name", STORAGE_ACCOUNT, | ||
| "--container-name", CONTAINER, | ||
| "--prefix", blobPrefix, | ||
| "--auth-mode", "login", | ||
| "--query", "[?ends_with(name, '.md')].name", | ||
| "-o", "tsv" | ||
| ], { | ||
| encoding: "utf-8", | ||
| stdio: ["pipe", "pipe", "ignore"] | ||
| }) as string; | ||
| } catch { | ||
| console.error( | ||
| `Error: failed to list blobs for run ${runId}, stimuli ${stimuliPart}.` | ||
| ); | ||
| failed = 1; | ||
| continue; | ||
| } | ||
|
|
||
| const blobList = blobs.trim().split("\n").filter((line: string) => line); | ||
| if (blobList.length === 0) { | ||
| console.error( | ||
| `Warning: no trajectory blobs found for run ${runId}, stimuli ${stimuliPart}.` | ||
| ); | ||
| continue; | ||
| } | ||
|
|
||
| // Create output directory | ||
| if (!fs.existsSync(stimuliOutputDir)) { | ||
| fs.mkdirSync(stimuliOutputDir, { recursive: true }); | ||
| } | ||
|
|
||
| for (const blob of blobList) { | ||
| const fileName = path.basename(blob); | ||
| console.log(` downloading ${fileName} -> ${stimuliOutputDir}`); | ||
|
|
||
| try { | ||
| const outputPath = path.join(stimuliOutputDir, fileName); | ||
| execFileSync("az", [ | ||
| "storage", "blob", "download", | ||
| "--account-name", STORAGE_ACCOUNT, | ||
| "--container-name", CONTAINER, | ||
| "--name", blob, | ||
| "--file", outputPath, | ||
| "--auth-mode", "login", | ||
| "--overwrite", | ||
| "--no-progress", | ||
| "-o", "none" | ||
| ], { stdio: "ignore" }); | ||
| } catch { | ||
| console.error(`Error: failed to download blob ${blob}`); | ||
| failed = 1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (failed !== 0) { | ||
| console.error( | ||
| `Completed with errors. Partial artifacts are in ${OUTPUT_ROOT}` | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(`Artifacts collected in ${OUTPUT_ROOT}`); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| run(); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.