armnet-runtime API Reference¶
armnet_runtime
¶
armnet runtime SDK — used inside customer containers on a cell.
Customer-facing surface: a @main decorator and a :class:Context. The
container's entrypoint is the armnet-runtime console script
(installed by this package); it loads the user's file, finds the
@main-decorated function, builds the context, and calls it.
Typical use::
from armnet_runtime import main, Context
@main
def run(ctx: Context):
seed = ctx.args.get("seed", 0)
ctx.report_progress("starting")
...
return {"success_rate": 1.0}
Wire types (Embodiment, Task, JobSpec, JobResult, ...) are
re-exported from :mod:armnet_core for ergonomics, so customer code
never needs to know about the core package directly.
TerminalStatus
module-attribute
¶
TerminalStatus = frozenset({JobStatus.SUCCEEDED, JobStatus.FAILED, JobStatus.TIMEOUT, JobStatus.CANCELLED})
Job
¶
Bases: BaseModel
The orchestrator's view of a job (response body of GET /jobs/{id}).
Source code in core/src/armnet_core/models.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
created_at
class-attribute
instance-attribute
¶
created_at: datetime = Field(default_factory=_utcnow)
updated_at
class-attribute
instance-attribute
¶
updated_at: datetime = Field(default_factory=_utcnow)
cell_id
class-attribute
instance-attribute
¶
cell_id: Optional[str] = Field(default=None, description='ID of the cell that picked up the job, set on dispatch.')
dispatched
class-attribute
instance-attribute
¶
dispatched: Optional[bool] = Field(default=None, description="Only set on the POST /jobs response: True if the job was dispatched to a cell immediately, False if it was accepted but queued (no matching cell was free). None on all other responses. Clients can use this to decide whether to wait for logs/result or just report 'queued'.")
is_terminal
¶
is_terminal() -> bool
Source code in core/src/armnet_core/models.py
534 535 | |
JobResult
¶
Bases: BaseModel
Terminal result published by a cell on the results subject.
Also returned (embedded in :class:Job) by GET /jobs/{id} once the
job is in a terminal state.
Source code in core/src/armnet_core/models.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
status
class-attribute
instance-attribute
¶
status: JobStatus = Field(..., description='One of the terminal statuses (succeeded/failed/timeout/cancelled).')
exit_code
class-attribute
instance-attribute
¶
exit_code: Optional[int] = Field(default=None, description='Container process exit code if the container ran to completion.')
stdout
class-attribute
instance-attribute
¶
stdout: str = Field(default='', description='Captured container stdout.')
stderr
class-attribute
instance-attribute
¶
stderr: str = Field(default='', description='Captured container stderr.')
error
class-attribute
instance-attribute
¶
error: Optional[str] = Field(default=None, description="Short, infra-side reason this job didn't run user code to completion: image pull failure, docker error, timeout, etc. Mutually exclusive with `traceback` in practice (one is a platform failure, the other is a user-code failure).")
traceback
class-attribute
instance-attribute
¶
traceback: Optional[str] = Field(default=None, description="Python traceback from the customer's `@main`-decorated function if it raised. Extracted by the cell from the `[armnet:traceback]:json` marker line in stdout. Capped at ~64 KiB on the cell side; the full untruncated traceback is also in `stderr` for power users. None for successful jobs and for infra-side failures (those go in `error` instead).")
return_value
class-attribute
instance-attribute
¶
return_value: Optional[Any] = Field(default=None, description="Value returned by the customer's `@main`-decorated function. Extracted by the cell from the marker line that the `armnet-runtime` entrypoint prints to stdout. None if the function returned None or did not run to completion.")
raise_for_status
¶
raise_for_status() -> None
Raise :class:RemoteExecutionError iff this result isn't SUCCEEDED.
The httpx-style "opt-in raising" pattern. Use it when you'd rather
bail than branch on result.status::
result = execute(...)
result.raise_for_status()
do_thing(result.return_value)
For successful results this is a no-op.
Source code in core/src/armnet_core/models.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
JobSpec
¶
Bases: BaseModel
The fields a client supplies when creating a job.
This is the body of POST /jobs. The orchestrator wraps it into a
:class:Job (assigning id, status, timestamps) before
persisting.
Source code in core/src/armnet_core/models.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
image
class-attribute
instance-attribute
¶
image: str = Field(..., description='Fully-qualified container image reference, e.g. `ghcr.io/my-org/my-image:tag` or `my-image:latest` for local M0.5.')
args
class-attribute
instance-attribute
¶
args: dict[str, Any] = Field(default_factory=dict, description="Keyword arguments passed to the customer's @main-decorated function as `ctx.args`. JSON-encoded into the `ARMNET_ARGS` env var by the cell; decoded by the `armnet-runtime` entrypoint before calling user code. Must be JSON-serialisable.")
embodiment
class-attribute
instance-attribute
¶
embodiment: Embodiment = Field(..., description='Required robot embodiment. The orchestrator routes the job onto the NATS subject for this embodiment+task pair, where the matching cell picks it up.')
task
class-attribute
instance-attribute
¶
task: Optional[Task] = Field(default=None, description='Optional task. When set, only cells configured for this (embodiment, task) pair run the job. When omitted, any cell of the embodiment may pick it up regardless of its configured task.')
timeout_seconds
class-attribute
instance-attribute
¶
timeout_seconds: int = Field(default=120, ge=1, description='Wall-clock cap on container execution.')
secrets
class-attribute
instance-attribute
¶
secrets: dict[str, str] = Field(default_factory=dict, description="Mapping of environment variable name to user secret name. Example: {'HF_TOKEN': 'huggingface-token'} resolves the authenticated user's secret and injects it as HF_TOKEN.")
detach
class-attribute
instance-attribute
¶
detach: bool = Field(default=False, description='If false, losing the client log WebSocket requests graceful job cancellation. If true, the job keeps running after client disconnect.')
username
class-attribute
instance-attribute
¶
username: Optional[str] = Field(default=None, description='Authenticated armnet username. Set by the orchestrator from the API key; clients should not rely on supplied values being preserved.')
JobStatus
¶
Bases: str, Enum
Job lifecycle states.
Mirrors the design doc §3.5 state machine. A job is created SUBMITTED;
if the target cell isn't available it becomes QUEUED (run when the cell
next comes online — the
scheduler is a later phase), otherwise it is DISPATCHED to a cell, then
RUNNING, then a terminal state.
Source code in core/src/armnet_core/models.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
RemoteExecutionError
¶
Bases: RuntimeError
Raised by :meth:JobResult.raise_for_status for non-succeeded results.
The exception's __str__ includes the underlying status, any
platform-side error, and the user's traceback (if any), so an
unhandled raise prints all the diagnostic context an operator needs.
The original :class:JobResult is available as :attr:result for
structured access.
Source code in core/src/armnet_core/models.py
496 497 498 499 500 501 502 503 504 505 506 507 508 | |
Cell
dataclass
¶
Handle to the physical cell the user code is running on.
M0.5 stub: there is no real cell yet, so robot_port is always None
and :meth:reset is a no-op. The shape is fixed now so the spec
example compiles end-to-end and so M2/M3 can fill in the
implementation without touching customer-facing imports.
Source code in runtime/src/armnet_runtime/context.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
robot_port
class-attribute
instance-attribute
¶
robot_port: Optional[str] = None
Robot port value to pass into LeRobot robot configs.
In container-backed remote execution this is the connector endpoint, not the host's physical serial path. The SDK's import-system swap routes that endpoint through the cell-side connector, which then opens the real robot port configured on the cell host.
robot_id
class-attribute
instance-attribute
¶
robot_id: Optional[str] = None
Stable robot id used by LeRobot to find calibration data.
calibration_dir
class-attribute
instance-attribute
¶
calibration_dir: Optional[Path] = None
Calibration store path visible inside the customer container.
calibration_file_path
class-attribute
instance-attribute
¶
calibration_file_path: Optional[Path] = None
Exact LeRobot calibration file path visible inside the customer container.
language_instruction
class-attribute
instance-attribute
¶
language_instruction: Optional[str] = None
Task instruction provided by the cell.
local_control_endpoint
class-attribute
instance-attribute
¶
local_control_endpoint: Optional[str] = None
Developer local-container control endpoint for keyboard-driven state.
operator_call_endpoint
class-attribute
instance-attribute
¶
operator_call_endpoint: Optional[str] = None
Operator-call endpoint served by the cell program for human-in-the-loop
calls (manual reset confirmation). Distinct from robot_port, which is the
robot/bus connector (potentially a headless edge device).
is_local_container
class-attribute
instance-attribute
¶
is_local_container: bool = False
True when running a Docker image locally for development.
safety_limit
class-attribute
instance-attribute
¶
safety_limit: Optional[float] = None
Relative action safety limit exposed by the cell, if applicable.
arms
class-attribute
instance-attribute
¶
arms: dict[str, RuntimeArm] = field(default_factory=dict)
Named arms for bimanual/multi-arm cells.
arm
¶
arm(name: str) -> RuntimeArm
Source code in runtime/src/armnet_runtime/context.py
194 195 196 197 198 | |
prepare_bimanual_calibration_dir
¶
prepare_bimanual_calibration_dir() -> BimanualCalibrationLayout
Create a temp calibration dir using LeRobot's <base>_<arm>.json names.
Each arm's source calibration is resolved (in order) from its own
calibration_file_path, its own calibration_dir keyed by the arm's
robot_id, or—when the arm declares neither—the cell-level
calibration_dir keyed by the arm's robot_id (<robot_id>.json).
This mirrors how the cell's per-arm health check resolves calibration
(arm.calibration_dir or cell.calibration_dir), so a config that only
sets a top-level calibration_dir (per-arm robot_id only) works.
Source code in runtime/src/armnet_runtime/context.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
reset
¶
reset() -> None
Return the robot to rest, then block until the operator confirms.
Two concerns, two endpoints:
- Returning the arm to its rest position is a low-level bus operation,
so it is sent to the robot connector (
robot_port), which may be a headless edge device. - Operator confirmation is a human-in-the-loop concern, so it is sent
to the
operator_call_endpointserved by thearmnet-cellprocess, whose stdin is the operator's terminal.
The operator-facing prompt is owned by the cell, not by job code: job code only signals that a reset point has been reached.
Source code in runtime/src/armnet_runtime/context.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
is_complete
¶
is_complete(*, block: bool = False) -> CompletionStatus
Return whether the current episode is complete, and its success.
Returns a :class:CompletionStatus (complete, success):
- A human-reported outcome (an operator hitting success/fail in the
FMS during a live rollout) takes precedence and ends the episode
immediately, with
successset to the operator's choice. This is how an operator stops a dangerous rollout without stopping the job. - Otherwise the cell's automated completion monitor is consulted; a
task scored complete is reported as a success (
success == complete). Passblock=Truefor a final episode check that waits for the cell to score the latest cached frames before returning.
bool(status) is status.complete for backwards compatibility.
Source code in runtime/src/armnet_runtime/context.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
rollout_begin
¶
rollout_begin(*, index: Optional[int] = None, total: Optional[int] = None, outcome_controls: bool = True) -> None
Tell the platform a rollout/episode in this job's loop has started.
The cell publishes this to the FMS, which shows the loop progress
("rollout N / M") for the live job. Pass index (1-based) and, when
known, total so operators see how far along the loop is.
outcome_controls controls whether the FMS also shows operator
success/fail buttons: keep the default True for policy evals; pass
False for progress-only loops such as teleop data collection, where
a human verdict doesn't apply. Best-effort: a failed notification never
breaks the rollout. Pair with :meth:rollout_end.
Source code in runtime/src/armnet_runtime/context.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
rollout_end
¶
rollout_end() -> None
Tell the platform the current rollout has ended (hides FMS buttons).
Source code in runtime/src/armnet_runtime/context.py
375 376 377 | |
is_shutting_down
¶
is_shutting_down() -> bool
Return True once the cell has entered the job's post-timeout grace window.
When a job exceeds its timeout_seconds the cell does not kill the
container straight away: it trips the robot interlock (so any further
robot-bus calls fail) and opens a short grace window during which this
returns True, before force-killing the container. Poll it in your loop
and break out to finalize gracefully — e.g. save/push a dataset — instead
of being killed mid-write::
for episode in range(n):
if ctx.cell.is_shutting_down():
break # finalize below
...
Resilient by design: returns False when no cell/operator endpoint is attached or the status can't be read, so it never stalls or crashes the control loop.
Source code in runtime/src/armnet_runtime/context.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
should_stop
¶
should_stop() -> bool
Return True when local/remote control asks user code to stop safely.
Source code in runtime/src/armnet_runtime/context.py
419 420 421 422 423 424 425 426 427 428 | |
get_teleop_action
¶
get_teleop_action() -> Optional[dict[str, float]]
Return the freshest remote-teleoperation action for this job, or None.
The client samples a local leader arm and pushes actions to the cell, which keeps only the most recent one (older messages are dropped). This reads that most-recent-value register over the operator-call endpoint.
Returns None when no teleop has been received yet (or no operator
endpoint is attached), so a control loop can hold position until the
operator starts driving. The returned dict is keyed for LeRobot's
send_action (e.g. {"shoulder_pan.pos": 12.3, ...}).
Source code in runtime/src/armnet_runtime/context.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
get_teleop_event
¶
get_teleop_event() -> Optional[str]
Return the next pending recording-control event, or None.
While teleoperating, the client can send discrete recording-control
events alongside the action stream — LeRobot's standard dataset
recording shortcuts: "next_episode" (Right Arrow: save the episode
and move on), "rerecord_episode" (Left Arrow: discard and redo) and
"stop_recording" (Esc: end the session). The cell queues them in
arrival order; each call pops at most one.
Like :meth:get_teleop_action, a wedged channel never stalls the
control loop: errors log (throttled), drop the connection so the next
call reconnects, and return None.
Source code in runtime/src/armnet_runtime/context.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
CompletionStatus
¶
Bases: NamedTuple
Result of :meth:Cell.is_complete: whether the episode is over and how.
complete is True once the current rollout/episode should end (the task
was scored complete by the automated monitor, or a human operator reported
an outcome). success is the verdict — for automated completion it equals
complete (a task scored complete is a success); for a human-reported
outcome it is the operator's success/fail choice, so an operator can end a
rollout as a failure (e.g. the robot behaved dangerously).
Backwards-compatible truthiness: bool(status) is status.complete, so
existing if ctx.cell.is_complete(): ... callers keep working, while new
code can unpack complete, success = ctx.cell.is_complete().
Source code in runtime/src/armnet_runtime/context.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Context
dataclass
¶
Everything a @main-decorated function needs from the platform.
Source code in runtime/src/armnet_runtime/context.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
camera_configs
class-attribute
instance-attribute
¶
camera_configs: dict[str, Any] = field(default_factory=dict)
report_progress
¶
report_progress(message: str) -> None
Surface a progress message back to the platform.
M0.5: prints to stdout with a discoverable marker so the cell's captured stdout shows progress in order with other prints. M1+ will also publish a NATS message so the orchestrator can stream progress back to the client without waiting for the job to terminate.
Source code in runtime/src/armnet_runtime/context.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
is_shutting_down
¶
is_shutting_down() -> bool
Whether the cell has entered the job's post-timeout grace window.
Convenience delegate for :meth:Cell.is_shutting_down. Poll it in long
loops and break out to finalize gracefully before the cell kills the
container.
Source code in runtime/src/armnet_runtime/context.py
685 686 687 688 689 690 691 692 | |
log_rerun_data
¶
log_rerun_data(observation: dict[str, Any] | None = None, action: dict[str, Any] | None = None, *, compress_images: bool = True, jpeg_quality: int = 75) -> None
Stream observation/action data to a Rerun viewer on the client.
Mirrors LeRobot's log_rerun_data: scalars are logged as Rerun
scalars, image-like arrays as images, and other arrays as per-element
scalars. Keys are namespaced with observation. / action. when
not already.
Unlike the LeRobot helper, this does not call rr.log in-process
(the cell container has no viewer). Instead it serializes a protobuf
packet and emits it on stdout behind a marker; the cell republishes it
on logs.<job_id>.rerun and the client's orchestrate script replays
it into the viewer it started with rr.init(...).
Images are JPEG-compressed by default to keep the NATS stream light;
set compress_images=False to send raw RGB. opencv is required for
compression and numpy for any array handling; both are imported lazily.
Non-blocking: the snapshot is handed to a background worker thread that
does the encoding and stdout write, so the calling control loop never
stalls on visualization. The worker's queue is bounded and drops the
oldest pending frame under backpressure (tune with
ARMNET_RERUN_QUEUE_MAXSIZE), so a slow consumer sheds frames
rather than slowing the robot loop.
Source code in runtime/src/armnet_runtime/context.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
ResetTimeoutException
¶
Bases: RuntimeError
Raised by ctx.cell.reset() when a manual reset is not actioned in time.
The cell waits for an operator to confirm the reset (via the Fleet Management System). If no confirmation arrives within the cell's reset timeout, the cell trips its safety interlock (no further robot commands are allowed, as with a safety violation) and this exception is raised into the job code. Catch it to shut down gracefully — e.g. commit a dataset that was being recorded — before letting the job fail::
try:
ctx.cell.reset()
except ResetTimeoutException:
dataset.push_to_hub() # save what we collected
raise
Source code in runtime/src/armnet_runtime/context.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
MainRegistrationError
¶
Bases: RuntimeError
Raised when @main is used incorrectly (multiple times, etc.).
Source code in runtime/src/armnet_runtime/decorator.py
31 32 | |
require_so101_embodiment
¶
require_so101_embodiment(ctx: 'Context', runtime_name: str) -> bool
Validate the job's embodiment is a (single or bimanual) SO-101.
The embodiment is the source of truth for how many arms the robot has —
lerobot/so-101 is a single arm, lerobot/bimanual_so101 is two — and
the orchestrator only routes a job to a cell of the matching embodiment.
Returns True for the bimanual embodiment (so the caller builds a two-arm
robot), False for single-arm.
Raises :class:NotImplementedError for any other embodiment, and
:class:RuntimeError if the embodiment's arm count disagrees with the cell's
actual wiring (ctx.cell.is_bimanual) — a misrouted or misconfigured cell.
Source code in runtime/src/armnet_runtime/context.py
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
main
¶
main(fn: EntryPoint) -> EntryPoint
Decorator: mark fn as the script's entry point.
The function is invoked with a :class:~armnet_runtime.Context by
the armnet-runtime entrypoint. It may return any
JSON-serialisable value; the value becomes
:attr:~armnet_core.JobResult.return_value.
Source code in runtime/src/armnet_runtime/decorator.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
armnet_runtime.context
¶
Job context surfaced to @main-decorated functions.
The cell program injects job env vars plus a JSON-encoded cell config when it
starts the container; :func:build_context reads them and constructs the
:class:Context object that the armnet-runtime entrypoint passes to
the user's @main function.
ResetTimeoutException
¶
Bases: RuntimeError
Raised by ctx.cell.reset() when a manual reset is not actioned in time.
The cell waits for an operator to confirm the reset (via the Fleet Management System). If no confirmation arrives within the cell's reset timeout, the cell trips its safety interlock (no further robot commands are allowed, as with a safety violation) and this exception is raised into the job code. Catch it to shut down gracefully — e.g. commit a dataset that was being recorded — before letting the job fail::
try:
ctx.cell.reset()
except ResetTimeoutException:
dataset.push_to_hub() # save what we collected
raise
Source code in runtime/src/armnet_runtime/context.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
CompletionStatus
¶
Bases: NamedTuple
Result of :meth:Cell.is_complete: whether the episode is over and how.
complete is True once the current rollout/episode should end (the task
was scored complete by the automated monitor, or a human operator reported
an outcome). success is the verdict — for automated completion it equals
complete (a task scored complete is a success); for a human-reported
outcome it is the operator's success/fail choice, so an operator can end a
rollout as a failure (e.g. the robot behaved dangerously).
Backwards-compatible truthiness: bool(status) is status.complete, so
existing if ctx.cell.is_complete(): ... callers keep working, while new
code can unpack complete, success = ctx.cell.is_complete().
Source code in runtime/src/armnet_runtime/context.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Volume
dataclass
¶
User volume mounted into the runtime container.
Source code in runtime/src/armnet_runtime/context.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
path
¶
path(relative_path: str | Path) -> Path
Source code in runtime/src/armnet_runtime/context.py
87 88 89 90 91 92 93 | |
read_bytes
¶
read_bytes(relative_path: str | Path) -> bytes
Source code in runtime/src/armnet_runtime/context.py
95 96 | |
read_text
¶
read_text(relative_path: str | Path) -> str
Source code in runtime/src/armnet_runtime/context.py
98 99 | |
write_bytes
¶
write_bytes(relative_path: str | Path, data: bytes) -> Path
Source code in runtime/src/armnet_runtime/context.py
101 102 103 104 105 | |
write_text
¶
write_text(relative_path: str | Path, data: str) -> Path
Source code in runtime/src/armnet_runtime/context.py
107 108 109 110 111 | |
RuntimeArm
dataclass
¶
Runtime-facing handle for one named robot arm in a multi-arm cell.
Source code in runtime/src/armnet_runtime/context.py
114 115 116 117 118 119 120 121 122 123 | |
calibration_file_path
class-attribute
instance-attribute
¶
calibration_file_path: Optional[Path] = None
BimanualCalibrationLayout
dataclass
¶
Temporary calibration layout matching LeRobot's bimanual id convention.
Source code in runtime/src/armnet_runtime/context.py
126 127 128 129 130 131 | |
Cell
dataclass
¶
Handle to the physical cell the user code is running on.
M0.5 stub: there is no real cell yet, so robot_port is always None
and :meth:reset is a no-op. The shape is fixed now so the spec
example compiles end-to-end and so M2/M3 can fill in the
implementation without touching customer-facing imports.
Source code in runtime/src/armnet_runtime/context.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
robot_port
class-attribute
instance-attribute
¶
robot_port: Optional[str] = None
Robot port value to pass into LeRobot robot configs.
In container-backed remote execution this is the connector endpoint, not the host's physical serial path. The SDK's import-system swap routes that endpoint through the cell-side connector, which then opens the real robot port configured on the cell host.
robot_id
class-attribute
instance-attribute
¶
robot_id: Optional[str] = None
Stable robot id used by LeRobot to find calibration data.
calibration_dir
class-attribute
instance-attribute
¶
calibration_dir: Optional[Path] = None
Calibration store path visible inside the customer container.
calibration_file_path
class-attribute
instance-attribute
¶
calibration_file_path: Optional[Path] = None
Exact LeRobot calibration file path visible inside the customer container.
language_instruction
class-attribute
instance-attribute
¶
language_instruction: Optional[str] = None
Task instruction provided by the cell.
local_control_endpoint
class-attribute
instance-attribute
¶
local_control_endpoint: Optional[str] = None
Developer local-container control endpoint for keyboard-driven state.
operator_call_endpoint
class-attribute
instance-attribute
¶
operator_call_endpoint: Optional[str] = None
Operator-call endpoint served by the cell program for human-in-the-loop
calls (manual reset confirmation). Distinct from robot_port, which is the
robot/bus connector (potentially a headless edge device).
is_local_container
class-attribute
instance-attribute
¶
is_local_container: bool = False
True when running a Docker image locally for development.
safety_limit
class-attribute
instance-attribute
¶
safety_limit: Optional[float] = None
Relative action safety limit exposed by the cell, if applicable.
arms
class-attribute
instance-attribute
¶
arms: dict[str, RuntimeArm] = field(default_factory=dict)
Named arms for bimanual/multi-arm cells.
arm
¶
arm(name: str) -> RuntimeArm
Source code in runtime/src/armnet_runtime/context.py
194 195 196 197 198 | |
prepare_bimanual_calibration_dir
¶
prepare_bimanual_calibration_dir() -> BimanualCalibrationLayout
Create a temp calibration dir using LeRobot's <base>_<arm>.json names.
Each arm's source calibration is resolved (in order) from its own
calibration_file_path, its own calibration_dir keyed by the arm's
robot_id, or—when the arm declares neither—the cell-level
calibration_dir keyed by the arm's robot_id (<robot_id>.json).
This mirrors how the cell's per-arm health check resolves calibration
(arm.calibration_dir or cell.calibration_dir), so a config that only
sets a top-level calibration_dir (per-arm robot_id only) works.
Source code in runtime/src/armnet_runtime/context.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
reset
¶
reset() -> None
Return the robot to rest, then block until the operator confirms.
Two concerns, two endpoints:
- Returning the arm to its rest position is a low-level bus operation,
so it is sent to the robot connector (
robot_port), which may be a headless edge device. - Operator confirmation is a human-in-the-loop concern, so it is sent
to the
operator_call_endpointserved by thearmnet-cellprocess, whose stdin is the operator's terminal.
The operator-facing prompt is owned by the cell, not by job code: job code only signals that a reset point has been reached.
Source code in runtime/src/armnet_runtime/context.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
is_complete
¶
is_complete(*, block: bool = False) -> CompletionStatus
Return whether the current episode is complete, and its success.
Returns a :class:CompletionStatus (complete, success):
- A human-reported outcome (an operator hitting success/fail in the
FMS during a live rollout) takes precedence and ends the episode
immediately, with
successset to the operator's choice. This is how an operator stops a dangerous rollout without stopping the job. - Otherwise the cell's automated completion monitor is consulted; a
task scored complete is reported as a success (
success == complete). Passblock=Truefor a final episode check that waits for the cell to score the latest cached frames before returning.
bool(status) is status.complete for backwards compatibility.
Source code in runtime/src/armnet_runtime/context.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
rollout_begin
¶
rollout_begin(*, index: Optional[int] = None, total: Optional[int] = None, outcome_controls: bool = True) -> None
Tell the platform a rollout/episode in this job's loop has started.
The cell publishes this to the FMS, which shows the loop progress
("rollout N / M") for the live job. Pass index (1-based) and, when
known, total so operators see how far along the loop is.
outcome_controls controls whether the FMS also shows operator
success/fail buttons: keep the default True for policy evals; pass
False for progress-only loops such as teleop data collection, where
a human verdict doesn't apply. Best-effort: a failed notification never
breaks the rollout. Pair with :meth:rollout_end.
Source code in runtime/src/armnet_runtime/context.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
rollout_end
¶
rollout_end() -> None
Tell the platform the current rollout has ended (hides FMS buttons).
Source code in runtime/src/armnet_runtime/context.py
375 376 377 | |
is_shutting_down
¶
is_shutting_down() -> bool
Return True once the cell has entered the job's post-timeout grace window.
When a job exceeds its timeout_seconds the cell does not kill the
container straight away: it trips the robot interlock (so any further
robot-bus calls fail) and opens a short grace window during which this
returns True, before force-killing the container. Poll it in your loop
and break out to finalize gracefully — e.g. save/push a dataset — instead
of being killed mid-write::
for episode in range(n):
if ctx.cell.is_shutting_down():
break # finalize below
...
Resilient by design: returns False when no cell/operator endpoint is attached or the status can't be read, so it never stalls or crashes the control loop.
Source code in runtime/src/armnet_runtime/context.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
should_stop
¶
should_stop() -> bool
Return True when local/remote control asks user code to stop safely.
Source code in runtime/src/armnet_runtime/context.py
419 420 421 422 423 424 425 426 427 428 | |
get_teleop_action
¶
get_teleop_action() -> Optional[dict[str, float]]
Return the freshest remote-teleoperation action for this job, or None.
The client samples a local leader arm and pushes actions to the cell, which keeps only the most recent one (older messages are dropped). This reads that most-recent-value register over the operator-call endpoint.
Returns None when no teleop has been received yet (or no operator
endpoint is attached), so a control loop can hold position until the
operator starts driving. The returned dict is keyed for LeRobot's
send_action (e.g. {"shoulder_pan.pos": 12.3, ...}).
Source code in runtime/src/armnet_runtime/context.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
get_teleop_event
¶
get_teleop_event() -> Optional[str]
Return the next pending recording-control event, or None.
While teleoperating, the client can send discrete recording-control
events alongside the action stream — LeRobot's standard dataset
recording shortcuts: "next_episode" (Right Arrow: save the episode
and move on), "rerecord_episode" (Left Arrow: discard and redo) and
"stop_recording" (Esc: end the session). The cell queues them in
arrival order; each call pops at most one.
Like :meth:get_teleop_action, a wedged channel never stalls the
control loop: errors log (throttled), drop the connection so the next
call reconnects, and return None.
Source code in runtime/src/armnet_runtime/context.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
Context
dataclass
¶
Everything a @main-decorated function needs from the platform.
Source code in runtime/src/armnet_runtime/context.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
camera_configs
class-attribute
instance-attribute
¶
camera_configs: dict[str, Any] = field(default_factory=dict)
report_progress
¶
report_progress(message: str) -> None
Surface a progress message back to the platform.
M0.5: prints to stdout with a discoverable marker so the cell's captured stdout shows progress in order with other prints. M1+ will also publish a NATS message so the orchestrator can stream progress back to the client without waiting for the job to terminate.
Source code in runtime/src/armnet_runtime/context.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
is_shutting_down
¶
is_shutting_down() -> bool
Whether the cell has entered the job's post-timeout grace window.
Convenience delegate for :meth:Cell.is_shutting_down. Poll it in long
loops and break out to finalize gracefully before the cell kills the
container.
Source code in runtime/src/armnet_runtime/context.py
685 686 687 688 689 690 691 692 | |
log_rerun_data
¶
log_rerun_data(observation: dict[str, Any] | None = None, action: dict[str, Any] | None = None, *, compress_images: bool = True, jpeg_quality: int = 75) -> None
Stream observation/action data to a Rerun viewer on the client.
Mirrors LeRobot's log_rerun_data: scalars are logged as Rerun
scalars, image-like arrays as images, and other arrays as per-element
scalars. Keys are namespaced with observation. / action. when
not already.
Unlike the LeRobot helper, this does not call rr.log in-process
(the cell container has no viewer). Instead it serializes a protobuf
packet and emits it on stdout behind a marker; the cell republishes it
on logs.<job_id>.rerun and the client's orchestrate script replays
it into the viewer it started with rr.init(...).
Images are JPEG-compressed by default to keep the NATS stream light;
set compress_images=False to send raw RGB. opencv is required for
compression and numpy for any array handling; both are imported lazily.
Non-blocking: the snapshot is handed to a background worker thread that
does the encoding and stdout write, so the calling control loop never
stalls on visualization. The worker's queue is bounded and drops the
oldest pending frame under backpressure (tune with
ARMNET_RERUN_QUEUE_MAXSIZE), so a slow consumer sheds frames
rather than slowing the robot loop.
Source code in runtime/src/armnet_runtime/context.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
require_so101_embodiment
¶
require_so101_embodiment(ctx: 'Context', runtime_name: str) -> bool
Validate the job's embodiment is a (single or bimanual) SO-101.
The embodiment is the source of truth for how many arms the robot has —
lerobot/so-101 is a single arm, lerobot/bimanual_so101 is two — and
the orchestrator only routes a job to a cell of the matching embodiment.
Returns True for the bimanual embodiment (so the caller builds a two-arm
robot), False for single-arm.
Raises :class:NotImplementedError for any other embodiment, and
:class:RuntimeError if the embodiment's arm count disagrees with the cell's
actual wiring (ctx.cell.is_bimanual) — a misrouted or misconfigured cell.
Source code in runtime/src/armnet_runtime/context.py
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
build_context
¶
build_context() -> Context
Read the cell-injected env vars and construct a :class:Context.
Called by the armnet-runtime entrypoint before invoking the
user's @main function. Raises :class:RuntimeError with a clear
message if any required env var is missing — that indicates the
program is being run outside a armnet cell.
Source code in runtime/src/armnet_runtime/context.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
armnet_runtime.decorator
¶
The @main decorator and its module-level registry.
Customer code looks like::
from armnet_runtime import main, Context
@main
def run(ctx: Context):
...
return {"success_rate": 1.0}
The decorator records run as the script's entry point. The
armnet-runtime console script loads the script (which executes the
decorator as a side effect) and then calls :func:registered_main to get
the function to invoke.
Single entry point per script — multiple @main-decorated functions in
the same file is almost certainly a bug, so the decorator raises rather
than silently overwriting the previous registration.
MainRegistrationError
¶
Bases: RuntimeError
Raised when @main is used incorrectly (multiple times, etc.).
Source code in runtime/src/armnet_runtime/decorator.py
31 32 | |
main
¶
main(fn: EntryPoint) -> EntryPoint
Decorator: mark fn as the script's entry point.
The function is invoked with a :class:~armnet_runtime.Context by
the armnet-runtime entrypoint. It may return any
JSON-serialisable value; the value becomes
:attr:~armnet_core.JobResult.return_value.
Source code in runtime/src/armnet_runtime/decorator.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
registered_main
¶
registered_main() -> Optional[EntryPoint]
Return the function previously registered with @main, if any.
Source code in runtime/src/armnet_runtime/decorator.py
56 57 58 59 | |
armnet_runtime.cli
¶
armnet-runtime console script.
This is the container entrypoint for any image built on top of the
armnet runtime SDK. The container's CMD looks like::
CMD ["armnet-runtime", "/app/hello.py"]
and this script:
- (M3+) Performs the LeRobot import-system swap so customer code transparently routes hardware operations through the safety-aware robot connector. Currently a marker; nothing is swapped yet.
- Adds the user script's directory to
sys.pathso it can import sibling modules. - Imports the user script — which executes the
@maindecorator as a side effect, registering the entry-point function. - Builds a :class:
~armnet_runtime.Contextfrom cell-injected env vars. - Calls the registered function with the context.
- Prints the function's return value with the
:data:
~armnet_runtime.markers.RESULT_MARKER_JSONprefix; the cell extracts that and surfaces it as :attr:~armnet_core.JobResult.return_value. - Maps exceptions to a non-zero exit so the cell records the job as
FAILED; the traceback ends up in the captured stderr.
run
¶
run(argv: Sequence[str] | None = None) -> int
Source code in runtime/src/armnet_runtime/cli.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
armnet_runtime.env
¶
Env var keys the cell injects into customer containers.
Single source of truth shared by the cell (which sets them) and the runtime SDK (which reads them).
armnet_runtime.lerobot
¶
LeRobot integration helpers for armnet-runtime.
RemoteARX5Arm
¶
Proxy for arx5_common.ARX5Arm.
The user container constructs this class through import replacement, while
the cell-side connector owns the real arx5_interface backed arm.
Source code in runtime/src/armnet_runtime/lerobot/remote_arx5.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
RemoteOpenCVCamera
¶
Drop-in-ish proxy for LeRobot's OpenCVCamera.
The real camera stays on the cell host. The customer container holds this proxy and forwards camera lifecycle/read calls through the connector.
Source code in runtime/src/armnet_runtime/lerobot/remote_camera.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
RemoteFeetechMotorsBus
¶
Drop-in-ish proxy for LeRobot's FeetechMotorsBus.
The connector creates the real bus object on the cell host; this class forwards method calls and simple attribute gets/sets over JSON-lines. It is intentionally generic for M2 so we don't need to perfectly mirror LeRobot's evolving bus API upfront.
Source code in runtime/src/armnet_runtime/lerobot/remote_feetech.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
install_lerobot_remote_mode
¶
install_lerobot_remote_mode() -> None
Replace known LeRobot Feetech bus classes with remote proxies.
This is best-effort and guarded. If LeRobot is not installed, nothing happens. If LeRobot is installed but the Feetech module moved, we log and continue; the user's script will then fail with its normal ImportError, which is useful signal while we refine supported versions.
Source code in runtime/src/armnet_runtime/lerobot/import_swap.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |