Scaffold experiment

From niznik-dev/cruijff_kit · View interactive version

Scaffold experiment is an AI agent skill from the GitHub repository niznik-dev/cruijff_kit. Set up complete experimental infrastructure for all runs in a designed experiment. Orchestrates parallel generation of fine-tuning configs (via scaffold-torchtune) and evaluation configs (via scaffold-inspect). Use after design-experiment to prepare configs before running experiments.

How to use this skill

Skill file

Scaffold Experiment

You help users automatically set up the complete experimental infrastructure - both fine-tuning and evaluation configurations - for all runs in a designed experiment.

Your Task

Orchestrate the scaffolding process by reading tool specifications from experiment_summary.yaml and launching the appropriate subagents:

  1. Read experiment_summary.yaml to identify which tools are being used
  2. Launch the preparation subagent (scaffold-torchtune) only if at least one run has type: "fine-tuned" (see "Deciding Which Subagents to Launch" below)
  3. Launch the evaluation subagent (scaffold-inspect)
  4. Wait for the launched subagent(s) to complete and report their results

This ensures the entire experiment is ready to execute from training through evaluation. When both subagents are launched they run in parallel in separate context windows since their outputs do not depend on one another.

Deciding Which Subagents to Launch

Preparation (training) is only needed for runs that train in this experiment. Eval-only experiments — where every run is a base model (type: "control") or a pre-existing checkpoint (type: "eval-only") — have nothing to fine-tune, so launching scaffold-torchtune would do nothing.

Rule: Launch scaffold-torchtune if and only if at least one run has type: "fine-tuned". Always launch scaffold-inspect.

import yaml
with open(f"{experiment_dir}/experiment_summary.yaml") as f:
    config = yaml.safe_load(f)
runs = config.get("runs", []) or []
finetuned_runs = [r for r in runs if isinstance(r, dict) and r.get("type") == "fine-tuned"]
needs_torchtune = len(finetuned_runs) > 0

Post-decision assert (cheap insurance against a silent miss): after deciding, confirm the partition is correct — if needs_torchtune is false, assert that finetuned_runs is genuinely empty before skipping. A wrongly-skipped fine-tuned run would silently lose its training configs and only surface as a failure at run-experiment. If the assert ever trips, do not skip — launch scaffold-torchtune.

Current tool support:

Future tool support: This orchestrator is designed to route to different worker subagents based on tool choices documented in experiment_summary.yaml. Future iterations may support additional frameworks.

Dependency version check

Run before proceeding to catch stale envs (user pulled new pins but didn't re-run pip install -e .):

python scripts/check_env.py

Workflow

  1. Locate experiment - Find the experiment directory (usually current directory or ask user)
  2. Verify experiment_summary.yaml exists - Ensure design phase is complete
  3. Read tool specifications - Parse experiment_summary.yaml to identify preparation and evaluation tools
  4. Validate tool support - Ensure the specified tools have corresponding worker subagents
  5. Prepare data (if applicable) - If data.data_generation block is present, run src/tools/experiment/prepare_data.py to materialize the declared dataset before subagents launch
  6. Launch preparation and evaluation subagents in parallel - Use Task tool to launch both simultaneously
  7. Wait for both subagents to complete - Each will report back when done
  8. Create orchestration log - Document the scaffolding process in logs/scaffold-experiment.log
  9. Report combined summary - Show user complete status of both scaffolding phases

Finding the Experiment

If user runs skill without arguments:

If user provides a path:

Verification Before Starting

Before beginning scaffolding, perform minimal structural validation:

  1. experiment_summary.yaml exists:

```bash

ls {experiment_dir}/experiment_summary.yaml

```

If missing, report error and suggest running design-experiment skill first.

DO NOT launch subagents.

  1. experiment_summary.yaml is readable:

```python

import yaml

with open(f"{experiment_dir}/experiment_summary.yaml") as f:

config = yaml.safe_load(f)

```

If unreadable or invalid YAML, report error. DO NOT launch subagents.

Note on validation division:

The subagents (scaffold-torchtune, scaffold-inspect) will perform complete validation of:

Tool to Subagent File Mapping

This orchestrator routes to different subagent specifications based on tool choices in experiment_summary.yaml:

Preparation tools:

Evaluation tools:

Adding new tools: Create the corresponding agent file (optimizers/{tool}_agent.md or evaluators/{tool}_agent.md) and add to this mapping.

Reading Tool Specifications

Read experiment_summary.yaml to determine which subagents to launch.

See parsing.md for:

Orchestration Steps

How to Launch Worker Subagents

IMPORTANT: Use the Task tool to launch worker subagents (NOT the SlashCommand tool).

Correct approach for parallel execution:

Launch both subagents in a single message with multiple Task tool calls. This runs them in parallel.

Example:

I'll launch both the torchtune and inspect-ai scaffolding subagents in parallel.

[Use Task tool with subagent_type="scaffold-torchtune"]
[Use Task tool with subagent_type="scaffold-inspect"]

Subagent prompts should:

Why this matters:

Step 0: Prepare Data (if applicable)

If experiment_summary.yaml contains a data.data_generation block, run the prepare_data tool before launching any subagents:

python -m cruijff_kit.tools.experiment.prepare_data {experiment_dir}

Behavior:

Currently supported generators:

Step 1: Launch Preparation Subagent (only if there are fine-tuned runs)

First check needs_torchtune (see "Deciding Which Subagents to Launch" above). If no run has type: "fine-tuned", skip this step entirely — the experiment is eval-only — and proceed to Step 2 with scaffold-inspect alone.

Otherwise, invoke the preparation subagent based on tool specification in experiment_summary.yaml.

For torchtune: See optimizers/torchtune_agent.md for:

Launch the subagent using the Task tool with the prompt template from the agent file.

Step 2: Launch Evaluation Subagent

Invoke the appropriate evaluation subagent based on tool specification in experiment_summary.yaml.

For inspect-ai: See evaluators/inspect_agent.md for:

Launch the subagent using the Task tool with the prompt template from the agent file.

Step 3: Wait for Subagent Completion

After launching both subagents in parallel:

Processing subagent reports:

  1. Read the response from scaffold-torchtune subagent
  1. Read the response from scaffold-inspect subagent
  1. Verify both subagents completed successfully or note failures

Logging

Create an orchestration log at {experiment_dir}/logs/scaffold-experiment.log that records the high-level scaffolding process.

See logging.md for:

Key principle: The orchestration log tracks coordination and timing. Detailed implementation goes in subagent logs (logs/scaffold-torchtune.log, logs/scaffold-inspect.log).

Error Handling

If experiment_summary.yaml not found:

If optimization subagent fails:

If evaluation subagent fails:

If both subagents fail:

If a subagent doesn't report back:

Output Summary

After completing orchestration, provide a comprehensive summary:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.