adapters
Type adapters for bus message serialization.
Provides ready-made TypeAdapter implementations for common Pipecat types
(LLMContext, ToolsSchema) used in bus messages.
- class pipecat.bus.adapters.LLMContextAdapter[source]
Bases:
TypeAdapterSerialize and deserialize
LLMContextinstances.The
NOT_GIVENsentinel is preserved across serialization: missing keys are restored asNOT_GIVENon deserialization.- serialize(obj: Any, serialize_value: Callable[[Any], Any]) dict[str, Any][source]
Serialize an
LLMContextto a JSON-compatible dict.- Parameters:
obj – An
LLMContextinstance.serialize_value – Callback to recursively serialize nested values.
- Returns:
A dict with
messagesand, optionally,toolsandtool_choicekeys.
- deserialize(data: dict[str, Any], deserialize_value: Callable[[Any], Any], target_type: type | None = None) Any[source]
Reconstruct an
LLMContextfrom a serialized dict.Missing
toolsandtool_choicekeys are restored as OpenAI’sNOT_GIVENsentinel.- Parameters:
data – A dict produced by
serialize().deserialize_value – Callback to recursively deserialize nested values.
target_type – Unused.
LLMContextis always the target.
- Returns:
A new
LLMContextinstance.
- class pipecat.bus.adapters.ToolsSchemaAdapter[source]
Bases:
TypeAdapterSerialize and deserialize
ToolsSchemainstances for network transport.- serialize(obj: Any, serialize_value: Callable[[Any], Any]) dict[str, Any][source]
Serialize a
ToolsSchemato a JSON-compatible dict.- Parameters:
obj – A
ToolsSchemainstance.serialize_value – Callback to recursively serialize nested values.
- Returns:
A dict with a
standard_toolslist.
- deserialize(data: dict[str, Any], deserialize_value: Callable[[Any], Any], target_type: type | None = None) Any[source]
Reconstruct a
ToolsSchemafrom a serialized dict.- Parameters:
data – A dict produced by
serialize().deserialize_value – Callback to recursively deserialize nested values.
target_type – Unused.
ToolsSchemais always the target.
- Returns:
A new
ToolsSchemainstance.
- class pipecat.bus.adapters.TypeAdapter[source]
Bases:
ABCSerialize and deserialize instances of a specific type for network transport.
Each adapter handles one or more types, converting them to/from a JSON-compatible dict. Register adapters on a
JSONMessageSerializerto handle non-JSON-native field values (e.g.LLMContext,ToolsSchema).Adapters receive
serialize_valueanddeserialize_valuecallbacks from the serializer so they can recursively serialize nested fields without importing the serializer itself.- abstractmethod serialize(obj: Any, serialize_value: Callable[[Any], Any]) dict[str, Any][source]
Convert an object to a JSON-compatible dict.
- Parameters:
obj – The object to serialize.
serialize_value – Callback to recursively serialize nested values.
- Returns:
A dict representation of the object.
- abstractmethod deserialize(data: dict[str, Any], deserialize_value: Callable[[Any], Any], target_type: type | None = None) Any[source]
Reconstruct an object from a dict.
- Parameters:
data – The dict representation produced by
serialize().deserialize_value – Callback to recursively deserialize nested values.
target_type – The resolved target class. Defaults to None.
- Returns:
The reconstructed object.