Skip to main content

MessageSerializer

Abstract base class for bus message serialization. Network bus implementations use a MessageSerializer to convert messages to bytes for transmission and reconstruct them on the receiving end.

Methods

serialize

Convert a bus message to bytes. Returns: The serialized bytes.

deserialize

Reconstruct a bus message from bytes. Returns: The reconstructed BusMessage, or None if deserialization fails.

JSONMessageSerializer

Serialize bus messages as JSON with pluggable type adapters. Handles JSON-native types, enums, bytes, dataclasses, and any type with a registered TypeAdapter. Adapters for common Pipecat types (LLMContext, ToolsSchema) are registered by default.
This is the default serializer used by RedisBus and the proxy agents.

Methods

register_adapter

Register a custom type adapter for types not supported by default.

TypeAdapter

Abstract base class for type-specific serialization adapters. Each adapter handles one or more types, converting them to/from a JSON-compatible dict.

Methods

serialize

Convert an object to a JSON-compatible dict.

deserialize

Reconstruct an object from a dict.