Skip to content

API Reference parrot.integrations.liveavatar.output_transport

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.liveavatar.output_transport

View source

Cross-process transport for structured-output delivery (FEAT-249).

ai-parrot-server is multi-process (gunicorn); UserSocketManager.broadcast_to_channel is in-process only. Structured outputs from any ai-parrot worker process must cross the process boundary to reach the browser's WebSocket connection, which may be held by a different gunicorn worker. This module bridges that gap over Redis pub/sub:

  • :class:RedisBroadcastForwarder is a duck-typed stand-in for UserSocketManager that :class:OutputBridge can use unchanged: its broadcast_to_channel publishes a JSON envelope to a Redis channel.
  • :func:run_output_subscriber runs in the ai-parrot-server process: it subscribes to that Redis channel and replays each envelope through the real UserSocketManager.broadcast_to_channel (re-broadcast to the browser).

Envelope schema published on the Redis channel::

{"channel": "<session_id>", "message": {<StructuredOutputMessage.model_dump()>}}

redis.asyncio is imported lazily so importing this module never requires the redis dependency.

Attribute DEFAULT_OUTPUT_CHANNEL

Class RedisBroadcastForwarder

UserSocketManager-compatible sink that forwards broadcasts over Redis.

Implements the single method :class:OutputBridge depends on — broadcast_to_channel(channel, message, exclude_ws=None) — by publishing a JSON envelope to a Redis pub/sub channel. The ai-parrot-server consumes it via :func:run_output_subscriber and re-broadcasts to the browser.

Parameter Type Default Description
redis_client Any An async Redis client (redis.asyncio.Redis) exposing publish(channel, data) and aclose().
channel str DEFAULT_OUTPUT_CHANNEL Redis pub/sub channel to publish envelopes on.

Method RedisBroadcastForwarder.from_url

Build a forwarder from a Redis URL (lazy redis.asyncio import).

from_url(redis_url: str, *, channel: str = DEFAULT_OUTPUT_CHANNEL) -> RedisBroadcastForwarder

Parameter Type Default Description
redis_url str
channel str DEFAULT_OUTPUT_CHANNEL

Returns: RedisBroadcastForwarder

Method RedisBroadcastForwarder.broadcast_to_channel

Publish a {"channel", "message"} envelope to Redis.

Signature mirrors UserSocketManager.broadcast_to_channel so :class:OutputBridge is agnostic to which sink it holds. exclude_ws is accepted for compatibility and ignored (no local sockets here).

broadcast_to_channel(channel: str, message: Any, exclude_ws: Any = None) -> None

Parameter Type Default Description
channel str
message Any
exclude_ws Any None

Method RedisBroadcastForwarder.aclose

Close the underlying Redis client if it owns one.

aclose() -> None

Function run_output_subscriber

Consume output envelopes from Redis and re-broadcast them (server side).

Runs in the ai-parrot-server process. For each envelope received on channel it calls socket_manager.broadcast_to_channel with the original target channel (the session_id) and message, delivering the worker's structured output to the browser. Runs until cancelled.

run_output_subscriber(redis_client: Any, socket_manager: Any, *, channel: str = DEFAULT_OUTPUT_CHANNEL) -> None

Parameter Type Default Description
redis_client Any Async Redis client (redis.asyncio.Redis).
socket_manager Any The real UserSocketManager (duck-typed).
channel str DEFAULT_OUTPUT_CHANNEL Redis pub/sub channel to subscribe to.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally