rlmesh.RunHooks

classfrom rlmesh import RunHooks[source]

Observer callbacks for a run; every default is a no-op.

Subclass and override any subset, then pass an instance as hooks= to rlmesh.run(), Model.run, or Session.run(). Both loops fire the same callbacks in the same per- episode order. Hook exceptions propagate and abort the run with their own type; on_run_end() still fires exactly once with the completed episodes. Hooks run inline, so a slow hook slows the loop.

on_run_start

function[source]
on_run_start(context: RunContext)

Called once per run, before the first episode (no-op by default).

Receives the run’s RunContext (the Session itself on the session loop) so a hook can read roles off observations and discover the env’s frame sources without the caller wiring anything in.

on_episode_start

function[source]
on_episode_start(*, episode: int, seed: int | None)

Called after each episode’s reset returns (no-op by default).

Parameters

NameTypeDescription
episodeint0-based episode index (equals EpisodeResult.index).
seedint | NoneThe seed the episode was reset with, or None.

on_step

function[source]
on_step(event: StepEvent)

Called after each env step with its StepEvent (no-op by default).

on_episode_end

function[source]
on_episode_end(result: EpisodeResult)

Called with each completed episode’s EpisodeResult (no-op by default).

on_run_end

function[source]
on_run_end(result: RunResult)

Called exactly once when the run ends (no-op by default).

Fires even on an exception or interrupt, with the possibly-partial RunResult of the episodes that completed.