orxtra v0.13.0 /worker.src.orxtra.worker._brain
On this page

BrainWorkerBridge manages one worker's WebSocket connection on the brain side: sends ExecuteToolCall, matches results by call_id via per-call Futures, and runs heartbeat ping/pong for liveness.

#worker.src.orxtra.worker._brain

#worker.src.orxtra.worker._brain

Brain-worker bridge: manages a single worker WebSocket connection.

The brain side of the protocol. Sends ExecuteToolCall messages to the worker, awaits ToolCallResult responses. Handles heartbeat ping/pong and tracks worker connection state.

#WorkerDisconnectedError

Raised when a tool call is attempted on a disconnected worker.

#ToolCallTimeoutError

Raised when a worker does not respond to a tool call within the timeout.

#BrainWorkerBridge

Manages the WebSocket connection to a single worker.

Thread-safe for concurrent tool calls: each call gets a unique call_id and its own Future. The receive loop dispatches responses to the correct Future.

#connected

python
def connected(self) -> bool

#worker_id

python
def worker_id(self) -> UUID

#start

python
def start(self) -> None

Start the receive and heartbeat loops.

#stop

python
async def stop(self) -> None

Stop the receive and heartbeat loops.

#send_tool_call

python
async def send_tool_call(self, call: ExecuteToolCall, timeout: float | None=None) -> ToolCallResult

Send a tool call to the worker and await the result.

Idempotent: if a result for this call_id is already cached, returns the cached result without re-sending.

#_receive_loop

python
async def _receive_loop(self) -> None

Continuously receive messages from the worker WebSocket.

#_dispatch_message

python
def _dispatch_message(self, raw: str) -> None

Parse and dispatch a single message from the worker.

#_heartbeat_loop

python
async def _heartbeat_loop(self) -> None

Send heartbeats and detect timeouts.

#_mark_disconnected

python
def _mark_disconnected(self) -> None

Mark the worker as disconnected and fail pending calls.

#_serialize_message

python
def _serialize_message(msg_type: str, model: Any) -> str

Serialize a protocol message as a JSON envelope.

Search