MessageSerializer
Abstract base class for bus message serialization. Network bus implementations use aMessageSerializer to convert messages to bytes for transmission and reconstruct them on the receiving end.
Methods
serialize
| Parameter | Type | Description |
|---|---|---|
message | BusMessage | The bus message to serialize |
deserialize
| Parameter | Type | Description |
|---|---|---|
data | bytes | The serialized bytes produced by serialize() |
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 registeredTypeAdapter.
Adapters for common Pipecat types (LLMContext, ToolsSchema) are registered by default.
RedisBus and the proxy agents.
Methods
register_adapter
| Parameter | Type | Description |
|---|---|---|
type_ | type | The type to handle |
adapter | TypeAdapter | The adapter that serializes/deserializes instances |
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
| Parameter | Type | Description |
|---|---|---|
obj | Any | The object to serialize |
serialize_value | Callable[[Any], Any] | Callback to recursively serialize nested values |
deserialize
| Parameter | Type | Default | Description |
|---|---|---|---|
data | dict[str, Any] | The dict representation produced by serialize() | |
deserialize_value | Callable[[Any], Any] | Callback to recursively deserialize nested values | |
target_type | Optional[type] | None | The resolved target class |