Recipes

SPADE

A task generator for SPADE (self play in adaptive synthetic executable environments): one policy writes Harbor tasks as the Environment Designer and learns in them as the Reasoning Agent. Reference code: spade-rl/spade. The recipe is beta (issue #422; the pieces are in #482 and #498).

What it trains#

The served model's weights, on tasks that the served model writes. Each round of the built-in generated-task recipe is one SPADE generation: the Designer writes count tasks through the generator, and Harbor's oracle and nop agents check each one. The recipe trains the policy on the rollouts of the train tasks, with their verifier rewards, and the objective that the deployment names. Then the generator plays each task with its hint and reports each proposal's regret, the hint reward minus the plain reward (0 for a refused proposal), against the Designer's call. The next generation's prompt lists the tasks of the last generation by regret: the frontier, the mastered and the out of reach. generator.py and generation.py give the details.

When to use it#

  • Self play on tasks that the policy writes for itself from a description, with no tasks of your own.
  • To rebuild tasks from recorded coding sessions, use AutoEnvScaling. To build tasks from the failures of live traffic, use continual environments.

Known limitations:

  • Nothing trains on the Designer's regret reports yet.
  • The Designer makes one model call per task. It does not read files with tools or revise a task after a failed check.
  • When it rebuilds a task from records, the oracle check does not show that the task is faithful to the original.

Requirements#

  • A Reef checkout with the Tinker extra: uv pip install -e '.[tinker]' -e ./third_party/reef-client.
  • A Tinker account with access to Qwen/Qwen3-8B, and its key in TINKER_API_KEY.
  • Docker and the harbor command line on the host of the generator and on the training host. The tasks root must be under a path that Docker shares with the host (on macOS, under the home directory).
  • A Tinker objective of your own for recipe.config.job_parameters.objective. The example names the placeholder my_methods.objectives:MyObjective; replace it.

Run the example#

Shell
export TINKER_API_KEY=... REEF_TOKEN=reef-local REEF_SPADE_STATE_DIR="$PWD/work/spade"
reef serve -c recipes/beta/spade/examples/tinker/serve.yaml
curl -s -X POST -H "Authorization: Bearer $REEF_TOKEN" -H "Content-Type: application/json" \
  -d '{"name": "spade"}' http://127.0.0.1:8900/reef/scenarios

The POST creates the scenario, and round 0 starts when the training pipeline first asks for job data. Each generation's report is the state document report/<n> of the scenario's task store generated-tasks. To read the report of generation 0:

Shell
sqlite3 "$REEF_SPADE_STATE_DIR/agent-record/$(printf spade | shasum -a 256 | cut -d' ' -f1).sqlite3" \
  "select document from task_state_document where store_name = 'generated-tasks' and document_key = 'report/00000'"

To rebuild one task from selected records, call SpadeTaskGenerator.generate with a TaskGenerationRequest that holds the records and the local files the Designer may read, then validate.

Configuration#

The generator's keys, in recipe.samples.generator.config:

  • generator_url (required): the generator, ${endpoints.generator}.
  • count (8): the Designer's proposals in each generation.
  • skills (none): the skills that the proposals cycle through.
  • difficulty (medium): easy, medium or hard, the difficulty that the Designer aims for.
  • turn_limit (12): the turn limit that the Designer writes for.
  • grounding_path (none): a text file added to the Designer's prompt.
  • hint_plays (2): the rollouts of each task with its hint; 0 turns the hint arm off.
  • designer_report (true): report each proposal's regret against the Designer's call.
  • served_model (the deployment's): the model that the Designer and the hint plays ask for.

The deployment also sets the rounds (rounds, jobs-per-round, description), the split (eval-fraction, split-seed; keep both fixed for the life of a scenario), the generator section (generator.designer-url and generator.designer-model send the Designer to another model), and the rollouts in recipe.config.job_parameters.rollout. See generated tasks and the settings reference.

Results#

No measured results. The tests check the generator against stand-ins, not learning.

Files#

Text
spade/
  __init__.py            exports SpadeTaskGenerator and the generation records
  generator.py           SpadeTaskGenerator: the Designer's generations, the hint plays and the regret reports
  generation.py          the experience section of the prompt, and the records of one generation
  examples/tinker/
    serve.yaml           a Tinker deployment with the generator and the generated-task recipe

The tests are in tests/recipes/spade/.