gateway

A pipeline service for the OpenClaw Gateway.

class pipecat.services.openclaw.gateway.OpenClawGatewayService(*, url: str = 'ws://127.0.0.1:18789', token: str | None = None, password: str | None = None, session_key: str = 'agent:main:main', connect_timeout: float = 15.0, request_timeout: float = 30.0, run_timeout: float = 300.0, scopes: list[str] | None = None, role: str = 'operator', max_message_size: int = 26214400, reconnect_on_error: bool = True, **kwargs)[source]

Bases: AIService

Turns OpenClaw Gateway traffic into frames, and frames into Gateway calls.

Downstream, OpenClawSendFrame starts a run, OpenClawSteerFrame redirects the one in flight, and OpenClawAbortFrame stops it. What the Gateway streams back is pushed as OpenClawTextFrame between an OpenClawStartedFrame and one OpenClawEndFrame.

An agent run is not a spoken turn: it can take minutes and it answers in prose. What that should sound like belongs to whatever wraps this, which is why nothing here reads or writes conversational frames.

A session runs one turn at a time, so a send arriving while a run is live stops that run first. Every started frame is followed by exactly one end frame.

Example:

service = OpenClawGatewayService(token=os.getenv("OPENCLAW_TOKEN"))
__init__(*, url: str = 'ws://127.0.0.1:18789', token: str | None = None, password: str | None = None, session_key: str = 'agent:main:main', connect_timeout: float = 15.0, request_timeout: float = 30.0, run_timeout: float = 300.0, scopes: list[str] | None = None, role: str = 'operator', max_message_size: int = 26214400, reconnect_on_error: bool = True, **kwargs)[source]

Initialize the service and the client it drives.

Parameters:
  • url – The Gateway websocket, or the port a NemoClaw sandbox republishes it on.

  • token – The Gateway’s shared token. Required even on loopback.

  • password – Gateway password, if the deployment uses one instead.

  • session_key – Which OpenClaw session to run in.

  • connect_timeout – Seconds to wait for the handshake.

  • request_timeout – Seconds to wait for a Gateway method to answer.

  • run_timeout – Seconds the agent is given to finish a run.

  • scopes – Handshake scopes.

  • role – Handshake role.

  • max_message_size – Largest websocket frame to accept.

  • reconnect_on_error – Whether to reconnect after the socket fails.

  • **kwargs – Additional arguments passed to AIService.

See OpenClawGatewayClient for what each of these means to the Gateway.

property client: OpenClawGatewayClient

The Gateway client this service drives.

async setup(setup: FrameProcessorSetup)[source]

Wire the client up with the pipeline’s task manager, and connect.

Connecting here rather than on the StartFrame overlaps the Gateway handshake with the rest of the pipeline setting up.

Parameters:

setup – Configuration parameters for the frame processor.

async stop(frame: EndFrame)[source]

Stop the run in flight and close the connection.

Parameters:

frame – The end frame.

async cancel(frame: CancelFrame)[source]

Stop the run in flight and close the connection, at once.

Parameters:

frame – The cancel frame.

async cleanup()[source]

Release the run in flight and the connection.

async process_frame(frame: Frame, direction: FrameDirection)[source]

Process a frame, driving the Gateway from the ones addressed to it.

Parameters:
  • frame – The frame to process.

  • direction – The direction the frame is travelling.