Skip to content

hylo.codeagents.bridge

Package: hylo-code-agents · Core contracts

bridge

The toolkit's Executor on top of the kernel (RFC-0006 part 4): a program moves the robot only through the kernel.

Two threads meet here. The kernel thread calls the agent (act, on_step, on_episode_end); the program thread (a model's turns, or a frozen solve(robot)) calls the Executor (observation, run, status) and finish:

program: robot.run(plan) -> bridge.run(actions) ---- posts a chunk, blocks ------------------+
kernel:  act(obs) blocks until a chunk is posted, returns it -> SafetyShield -> env.step x T |
         act(obs) again (the queue is empty): the chunk is done -> wakes the program <-------+
program: finish() -> a chunk marked END_EPISODE -> the kernel ends the episode ("agent_done")

While the program computes (or the model thinks) the kernel is blocked in act(): simulation time does not pass, and a robot runner holds. A chunk cut short (the shield modified an action and the kernel dropped the rest) wakes the program with interrupted: true. When the episode ends for any reason (task terminated, max_steps, an error, the operator), on_episode_end wakes the program: every later run() returns at once with ended: true. Needs the kernel's sync timing (realtime mode asks for chunks before the last one finished).

EpisodeBridge

EpisodeBridge(env_spec: EnvSpec, task: TaskInstance, *, expose_success: bool = False, act_wait_s: float = 1800.0)

One episode's handoff between the kernel thread and the program thread. Implements hylo.manip.Executor.

action_dim instance-attribute

action_dim = int(np.prod(env_spec.action.shape))

provenance instance-attribute

provenance: dict[str, Any] = {}

outcome instance-attribute

outcome: dict[str, Any] | None = None

chunks instance-attribute

chunks = 0

ended property

ended: bool

step property

step: int

act

act(observation: Observation) -> ActionChunk

on_step

on_step(result: StepResult) -> None

on_episode_end

on_episode_end(outcome: EpisodeOutcome) -> None

cancel

cancel() -> None

Unblock both sides for good (shutdown): the kernel gets an END_EPISODE chunk, the program ended.

wait_ready

wait_ready(timeout_s: float = 60.0) -> bool

Block until the kernel has the first observation (it is waiting in act) or the episode ended.

observation

observation() -> Observation

status

status() -> dict[str, Any]

run

run(actions: ndarray) -> dict[str, Any]

finish

finish(reason: str = '') -> dict[str, Any]

End the episode (END_EPISODE) and block until the kernel has ended it; returns the outcome record.

TimedExecutor

TimedExecutor(bridge: Any, sandbox: Any)

The Executor a program's toolkit gets: the bridge, with the sandbox clock paused while the robot moves.

observation

observation() -> Observation

status

status() -> dict[str, Any]

run

run(actions: ndarray) -> dict[str, Any]

LiveExecutor

LiveExecutor()

An Executor that forwards to whichever episode is live (research sessions keep one toolkit across resets).

bridge instance-attribute

bridge: EpisodeBridge | None = None

observation

observation() -> Observation

status

status() -> dict[str, Any]

run

run(actions: ndarray) -> dict[str, Any]

BridgeAgent

BridgeAgent(bridge: EpisodeBridge, name: str = 'code.research', components: Mapping[str, str] | None = None)

An Agent that is nothing but a bridge: the program runs elsewhere (a research session's model loop).

spec

spec() -> AgentSpec

reset

reset(ctx: EpisodeContext) -> None

act

act(observation: Observation) -> ActionChunk

on_step

on_step(result: StepResult) -> None

on_episode_end

on_episode_end(outcome: EpisodeOutcome) -> None

code_agent_spec

code_agent_spec(name: str, components: Mapping[str, str] | None = None) -> AgentSpec