Recipes

Reefine

A beta harness evolution recipe that refines a coding harness from plain-language requests. It stays in recipes/beta/ until it has complete, reproducible results (RFC #938).

What it trains#

The harness: skills, rules, agent commands and, on pi, extensions. Each request (POST /reef/train) starts one job. On pi, where the host can isolate it, a pi coding agent edits the job's tree, checks it, runs the changed harness in trials, and stops. Otherwise the served model writes a design and the files, and a second call reviews them against the request, up to three answers. A job without a request learns one skill from failing reports. The evaluation runs a health task: it checks that the tree still works, not that the change does what was asked. The job page shows the design and the review, and a person activates each tree that changes an extension. method.py, agent.py and answer.py describe the job.

When to use it#

  • To turn a person's instructions into harness changes that the person reviews.
  • On pi for extensions; on claude, codex, opencode, hermes, dsh and terminus for rules, skills, commands and config.

To improve a harness on fixed tasks with a scorer, use GEPA or Meta-Harness. To learn from sessions without requests, use ACE or ReasoningBank.

Requirements#

  • A Reef checkout, with PYTHONPATH set to it: the recipe is not in the reef-infra wheel. Node.js, npm, rg and fd for pi; Reef installs its pinned pi at startup when evolution.binary is unset.
  • A model endpoint with tool calls: Chat Completions, Responses or Anthropic. No GPU.
  • To isolate the agent: bwrap and pasta (the passt package) for a non-root service with user namespaces, or Seatbelt on macOS, or a cloud sandbox (reef-infra[e2b] with E2B_API_KEY, or reef-infra[modal] with Modal's credentials). Without one, the served model answers in text.
  • Optional: an OpenRouter key in REEF_MULTIMODAL_API_KEY, for image, speech, embedding and decision models.

Run the example#

From the repository root:

Shell
export PYTHONPATH="$PWD${PYTHONPATH:+:$PYTHONPATH}"
reef serve -c recipes/beta/reefine/examples/configs/serve.yaml \
  --inference.upstream-url http://127.0.0.1:11434 \
  --inference.upstream-model gemma4:26b \
  --inference.upstream-api-key dummy

In another terminal, create a scenario and send a request:

Shell
curl -sS -H "Content-Type: application/json" -d '{"name": "my-harness"}' http://127.0.0.1:8901/reef/scenarios
curl -sS -H "x-reef-scenario: my-harness" -H "Content-Type: application/json" \
  -d '{"text": "when I ask you to fix a bug, reproduce it with a failing test first", "session": "me", "artifact_id": ""}' \
  http://127.0.0.1:8901/reef/train

The reply's page_path is the request's page. It shows the job's state, then the result with the design, how to use the change, and the review. A tree that changes an extension stays inactive until you set it as served with POST /reef/scenarios/my-harness/update. The example walks through these steps, and its run.sh runs scripted demos.

Configuration#

The settings reference describes the recipe.config.evolution keys. A deployment sets:

  • recipe.implementation: recipes.beta.reefine:ReefineRecipe, whose defaults are in recipe.py. reef.recipe.harness:HarnessEvolutionRecipe with ReefineMethod runs the method without them.
  • recipe.config.training-mode: manual (the default) runs one job per request; auto learns from failing reports.
  • evolution.adapter: pi in the example. Serve claude with --inference.upstream-api anthropic and codex with responses. terminus needs pip install -e recipes/meta_harness/examples/terminal_bench. harness_facts/ holds what the prompts say about each adapter other than pi.
  • evolution.agent: sandbox and timeout_s (1800 s) of the agent, as agent_settings reads them. null answers in text, as configs/deployment.yaml does.
  • evolution.method.config: trial_timeout_s (300 s) and multimodal (preset, url, api_key or api_key_env; see multimodal.py).
  • evolution.evaluation: the floor policy on the health task by default. Set tasks, a scorer and policy: compare to require a better score on your own tasks.
  • evolution.max_model_calls_per_step: the most model calls of one request. The agent makes one per turn.
  • evolution.state_dir: with sandbox: none, keep it outside every directory with an AGENTS.md or CLAUDE.md above it, because pi reads them.
  • activation: by default, a person activates each tree that changes an extension file.
  • REEF_REEFINE_CALL_TIMEOUT_S, REEF_REEFINE_CALL_MAX_TOKENS: the time and reply tokens of each model call that the method makes itself.

Results#

No measured results. The example's historical runs used an older evaluation.

Files#

Text
beta/reefine/
  __init__.py          exports ReefineRecipe, ReefineMethod and AnswerScorer
  recipe.py            ReefineRecipe: Reefine's defaults for the evolution section
  method.py            ReefineMethod: answers a request, or learns one skill from failing traces
  answer.py            the text answer: the design, the files, the review and the retries
  prompts/             the text answer's and the agent's prompt templates, and their words per harness
  agent.py             the agent answer: pi edits, checks and tries the job's tree
  agent_gateway.py     the loopback gateway through which the agent and its trials reach models
  agent_rules.md       the agent's instructions
  agent_tools.ts       the agent's tools: harness_check, harness_trial and harness_progress
  trial.py             the check of a scripted trial
  trial_driver.mjs     the scripted trial runner on the pi SDK
  pi_extension_api.md  the summary of pi's extension API that the agent reads
  harness_facts/       the facts of each adapter other than pi (<adapter>.yaml)
  multimodal.py        the image, speech, embedding and decision gateway settings
  scorer.py            AnswerScorer, the health task's scorer
  seed/                the first tree of a new scenario: one starter skill
  health/              the health task as a Harbor task directory, for terminus
  examples/            the example: configs, scripted demos, run.sh and run.py

The tests are in tests/recipes/reefine/.