Seven things you can add, each with the smallest working example. Step-by-step versions for coding agents are in AGENT_HANDOFF.md.
#1. A base policy
import numpy as np
import x_harness as xh
def my_policy(obs, instruction):
state = np.asarray(obs["state"]) # what the benchmark gives its policy
return [0.0, 0.0, -0.01, 1.0] # one action row, in the benchmark's convention
benchmark = xh.make_benchmark("mock", policy=my_policy)Anything with predict(obs, instruction) works, and so does a server address. Runnable: examples/02_custom_policy_tool.py.
#2. A tool
@xh.register_tool(category="geometry")
def nearest_object(objects, xyz):
"The object of a scene graph nearest to a point [x, y, z], or None for an empty list."
if not objects:
return None
return min(objects, key=lambda o: sum((a - b) ** 2 for a, b in zip(o["xyz"], xyz)))Policy code calls vision.nearest_object(...); the model sees the function's signature and first docstring paragraph in its prompt. Keep tools pure: inputs in, result out, no simulator state.
#3. A benchmark
cp -r x_harness/benchmarks/_template x_harness/benchmarks/my_bench| File | Edit |
|---|---|
tasks.py | your tasks, TRAIN_SEEDS, TEST_SEEDS |
contract.py | your controls, bounds and caps in an ActionContract |
env.py | observe, execute, over, success, diagnostics around your simulator |
__init__.py | the BenchmarkSpec (with an honest status) and make |
xh.register_benchmark("my_bench", "x_harness.benchmarks.my_bench:make", "x_harness.benchmarks.my_bench:SPEC")Three rules: check the action with the contract before the simulator sees it; raise InfrastructureError when the simulator itself fails; import the simulator only in env.py. A complete one-file benchmark: examples/05_new_benchmark_demo.py.
#4. A model
vlm = xh.make_vlm("local", model="my-served-model") # any OpenAI-compatible server: vLLM, SGLang, Ollama
vlm = xh.CachedVLM(vlm, "replies.jsonl") # optional: repeated requests cost nothingFor another API, subclass VLMClient in x_harness/harness/vlm.py: build one request (request) and read one reply (parse); retries, image limits and timing come with the base class.
#5. A code form
The five structured forms are interpreters with the three contract methods. To add one: a GUIDE text for the model, an interpreter class built from the program's namespace, and an entry in INTERPRETERS (x_harness/program/forms.py). Run a program in a form with ProgramHost(source, form="rules") or xharness run --form rules.
#6. Rescue thresholds and triggers
from x_harness.harness.rescue import Rescue, Thresholds
mine = Thresholds(stagnation_steps=150, empty_jaw=0.004, noprog_grip=0.02) # your robot's readings
rescue = Rescue(vlm, thresholds=mine, arms_of=my_state_adapter, mode="full_watchdog")arms_of(obs) returns {arm: (x, y, z, gripper_reading)}. For a robot without Cartesian state, subclass Watchdog and judge stillness in your own space, as real_yam/runtime.py: JointWatchdog does with joint encoders.
#7. The selection gate
from x_harness.harness.evolution import EvolutionLoop, SelectionGate
loop = EvolutionLoop(benchmark, task, vlm, gate=SelectionGate(max_regressions=0)) # stricter
loop = EvolutionLoop(benchmark, task, vlm, gate=SelectionGate(ungated=True)) # the ablationTo evolve something other than the program, pass make_host: examples/03_evolve_and_toolbank.py evolves a tool bank around a frozen program this way.
#Before you send a change
pytest -q
python scripts/render_tables.py --checkCONTRIBUTING.md has the checklist.