practice / AUTHORING.md
birgermoell's picture
Add Practice generators, indices, verification and documentation
2983a9c verified
|
Raw History Blame Contribute Delete
5.98 kB

Authoring a practice environment

Each environment teaches a language-model agent a piece of real work from one field of study. The agent gets a folder of files and an instruction, works in a terminal, and writes answer.json. A hidden, deterministic verifier scores it from 0 to 1. envs/ward_round/ is the reference implementation: read env.toml, gen.py and oracle.py there before writing anything, and copy its shape.

Files in envs/<name>/ (folder name uses underscores)

  • __init__.py: empty.
  • env.toml: name (kebab-case), title, isced (4-digit ISCED-F 2013 code), summary (one sentence, max 160 characters, says what the agent does), task_type (2 to 4 words), good_for (1 to 3 short phrases), families (list).
  • gen.py: generate(seed, difficulty, family=None) -> practice.core.Task. Difficulty is 1, 2 or 3. With family=None the family is sorted(FAMILIES)[seed % len(FAMILIES)]. Three or four families per environment, each a different piece of the field's real work.
  • oracle.py: standalone script, Python standard library only, that reads the task files from the current directory exactly as an agent would and writes answer.json. It must not import gen.py or practice. It must work out which family it is facing from the files present.
  • validators.py: only if an answer is not unique (a plan, an ordering, a counterexample). Standalone, standard library only. Each function is name(answer, args) -> bool (or a float in [0, 1]) and must never raise on malformed answers: return False.

Rules that make the reward trustworthy

  1. Two code paths. gen.py computes the expected values from its in-memory data. oracle.py recomputes them from the files. They share no code. If they disagree, the instruction or the file format is ambiguous: fix that, do not paper over it.
  2. The instruction is the contract. It names every answer key in backticks, with its unit, type and rounding, and gives every rule, formula, constant and threshold the agent needs, either in the instruction or in a reference file in the task folder (as Ward Round ships news2_rules.md). Never rely on the agent recalling a constant. Say how to round ("round half up" where it matters) and that numbers are accepted within one unit of the last decimal asked for.
  3. No knife edges. When a value decides a category, a flag, a ranking or a rounding, regenerate until it is clearly away from the boundary (see clear_of, and the while True loops in Ward Round). No ties in rankings or allocations unless the instruction gives a tie-break and the tie-break is tested.
  4. Every check has teeth. Prefer numeric and structural answers. Avoid checks an agent could pass by guessing (a lone yes/no). Where a boolean or category is needed, also check the numbers behind it. Weight summary checks (a set of flagged ids) 2.
  5. The work must be real. Files should look like the records a practitioner handles: unsorted rows, irrelevant columns or rows that must be filtered out, units to convert, a rule document to apply. Difficulty 1 is a clean small case; difficulty 2 adds volume and one complication; difficulty 3 adds a second complication and a derived or cross-record answer. Do not make it hard by making it vague.
  6. No leaks. Expected values never appear in the task files. Reference files give rules, never answers.
  7. Synthetic data only. No real persons. Real public methods, formulas and constants are welcome and should be named in the module docstring with their source. If you are not certain of a published constant, put the constant in the task's reference file as "use these values" so correctness does not depend on your memory of it.
  8. Determinism. All randomness comes from rng_for(ENV + "/" + family, seed, difficulty). No clocks, no global random, no set-ordering dependence (sort before choosing).
  9. Compatibility. gen.py and tools run on Python 3.9; oracle.py and validators.py run on 3.9 to 3.12. Standard library only everywhere. No f-string nesting tricks, no match, no X | Y type syntax.
  10. Plain language. Instructions are short, concrete and in British English. No emoji, no em dashes.

Checks

Build them with the helpers in practice/core.py: c_int, c_num(path, value, decimals), c_str, c_bool, c_list, c_set, c_custom(name, args). Paths are dotted (patients.P03.score). Keys in paths must not contain dots. The answer is always one JSON object. Aim for 6 to 40 checks per task.

For a non-unique answer, a c_custom validator must check every constraint of the problem against the answer itself (not compare with a stored solution), and args carries the problem data the validator needs. Also add ordinary checks for any unique derived values.

Self-test (must pass before you finish)

python3 tools/selftest.py <folder_name> 60

It checks, for 180 tasks: determinism, oracle scores exactly 1.0 from the files alone, junk answers score 0, every non-custom check fails when its value is changed, no leaks, and every top-level answer key is named in the instruction.

Then add tests/test_<folder_name>.py (plain asserts, runnable with python3 tests/test_<folder_name>.py) with:

  • at least three hand-worked cases per family: small inputs whose correct answers you derived by hand or from a published worked example, asserted against the generator's formula functions. This is the guard against a formula that is consistently wrong in both code paths, so take it seriously and show the arithmetic in comments.
  • for each custom validator: at least four wrong answers that must be rejected (each violating a different constraint) and one right answer accepted.

Report back

When done, report only: the families, the formulas and constants used with their sources, anything you were unsure about, and the self-test and unit-test output lines. Touch only your own envs/<name>/ folders and tests/test_<name>.py.