Stream¶
Typed event model and NDJSON stream wrapper for Arena streaming endpoints. Used internally by the client for real-time progress during validation, profiling, and training submission.
Events¶
- class agilerl.arena.stream.StatusEvent(stage: str, status: str, message: str, detail: dict[str, Any], raw: dict[str, Any], kind: str = 'status', level: str | None = None)¶
A stage-progression or warning event (
kind: "status"orkind: "warning").- Parameters:
stage (str) – The stage of the event.
status (str) – The status of the event.
message (str) – Human-readable message.
detail (dict[str, Any]) – Structured payload from the
detailenvelope field.kind (str) – The envelope
kindfield ("status"or"warning").level (str | None) – The envelope
levelfield. .
- class agilerl.arena.stream.CheckEvent(name: str, success: bool | None, warnings: list[str], error: str, raw: dict[str, Any])¶
An individual validation-check result.
- class agilerl.arena.stream.ErrorEvent(message: str, extras: dict[str, ~typing.Any] = <factory>, raw: dict[str, ~typing.Any] = <factory>)¶
An error returned by the server inside the stream.
- Parameters:
message – Primary error message.
extras – Supplementary context (e.g. available entrypoints).
raw – The full raw JSON payload.
Parsing¶
- agilerl.arena.stream.parse_ndjson_line(line: str) StatusEvent | CheckEvent | ErrorEvent | LogEvent¶
Parse a single NDJSON line into a typed
StreamEvent.Every line from the backend is a uniform envelope with a
kindfield. Dispatch order:kind:"status"+status:"failed"->ErrorEventkind:"status"(other statuses) ->StatusEventkind:"check"->CheckEventAnything else ->
LogEvent
- Parameters:
line (str) – The NDJSON line to parse.
- Returns:
The parsed
StreamEvent.- Return type:
StreamEvent
Stream Iterator¶
- class agilerl.arena.stream.NDJsonStream(response: httpx.Response, *, handler: Callable[[StreamEvent], None] | None = None, renderer: SupportsClose | None = None, error_cls: type[ArenaAPIError] | None = None)¶
Iterator + context-manager over an NDJSON HTTP response.
Yields
StreamEventobjects and tracks the final result for convenient access after iteration.- Parameters:
response (httpx.Response) – The HTTP response to iterate over.
handler (Callable[[StreamEvent], None] | None) – Callback invoked for each event.
Nonemeans silent.renderer (object | None) – Optional renderer to close when the stream is fully consumed.
Usage:
# Iterate events with client.validate_environment(name="MyEnv") as stream: for event in stream: ... print(stream.result) # Or just collect the final result result = client.validate_environment(name="MyEnv").collect()
- collect() dict[str, Any]¶
Consume all events and return the final result dict.
- Returns:
The final result dict.
- Return type:
- Raises:
ArenaAPIError – If the server reported a failure inside the stream (the endpoint-specific subclass when one is registered).
- property error: ErrorEvent | None¶
First server-side error event seen in the stream, if any.
- Returns:
The first
ErrorEvent, orNone.- Return type:
ErrorEvent | None