Skip to main content
There are two megan surfaces and they are not versions of each other.Pick the hosted one for milestone and anticipation work you want metered and managed. Pick this one when you need megan reasoning about the relation between a gripper and the things it is acting on. The hosted API has no relational routes, which is why this surface is local — not a preference.

Install

That pulls in megantk and numpy. The core CLI and the hosted client need neither, and nothing is imported until you touch Megan.

The whole loop

Instructions must parse

megan plans from a verb with an object, and a destination when something is being placed:
An unparseable instruction yields zero subgoals, so megan has no relation to enforce and will never act. That is indistinguishable from megan deciding your policy needs no help — the same silent output for opposite reasons. The constructor warns, and you can check:
Pass warn=False to silence the warning; parsed still tells the truth.

Teach every entity, including the gripper

aligned, near and over are relations between the hand and an object. With no prototype for the hand they cannot be evaluated, megan reports blind on every frame, and you see no guidance at all.
Teach from whatever your perception already gives you — a click, a colour blob centroid, a detector box. One point in one frame is enough:
Pass rgb=True if your frame is already RGB. Exactly one of uv, xy, box.
teach writes both halves of the appearance model — a colour example and a normalised-cross-correlation template in feature space — because the template alone does not create the prototype, and colour alone cannot separate two objects that share it. It also registers the bare noun phrase alongside the article form (red block as well as the red block), so a lookup cannot miss by an article.

Stepping

Action width is handled for you, and this one bites hard otherwise. megan reads the commanded gripper from proposed[:, 6] — six pose degrees of freedom then the gripper. A narrower action vector (a 5-joint arm plus a gripper, say) raises IndexError from deep inside a risk evaluation, a long way from the cause. step pads into the expected layout and mirrors your last column into the gripper slot, so commanded_grip reads what you meant.

Diagnosing a quiet megan

A megan that produces no guidance is either satisfied or blind, and they need opposite fixes.
If blind() is True on every step, you are missing a prototype — check untaught() before concluding megan has nothing to offer.

The wake gate

megan can learn when intervening is worth it, from a run in which it did not intervene. Build features from its risk reports, label the frames where help was about to be needed, and fit:
A refusal is a finding, not an error. fit_gate runs a permutation test against shuffled labels and refuses unless your features beat chance, leaving an untrained gate that licenses every wake. fit_gate returns that verdict — including z, held_out_loss, shuffled_loss, and how many of your features actually vary — so you can tell a fitted gate from an unfitted one.Two refusals look identical and mean opposite things:
  • the features carry no signal → change the features
  • the baseline barely failed → there was nothing to learn from; make the baseline run harder
Check the positive-label rate to tell them apart. Measured on a real tracking task, the same feature set scored z = 9.87 on a baseline with 142 failure frames and z = 0.09 on one with 32 — the gate can only learn to predict failures that happened.

Reference

Megan(instruction, *, grounder=None, experience=None, warn=True, **governor_kwargs)

Errors

MeganUnavailable (a RuntimeError) when megantk is not importable, kept distinct from a bare ImportError so you can tell “megan is not installed” from a bug in your own imports. relational_available() checks without raising.