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: TypeAdapter

Serialize and deserialize LLMContext instances.

The NOT_GIVEN sentinel is preserved across serialization: missing keys are restored as NOT_GIVEN on deserialization.

serialize(obj: Any, serialize_value: Callable[[Any], Any]) dict[str, Any][source]

Serialize an LLMContext to a JSON-compatible dict.

Parameters:
  • obj – An LLMContext instance.

  • serialize_value – Callback to recursively serialize nested values.

Returns:

A dict with messages and, optionally, tools and tool_choice keys.

deserialize(data: dict[str, Any], deserialize_value: Callable[[Any], Any], target_type: type | None = None) Any[source]

Reconstruct an LLMContext from a serialized dict.

Missing tools and tool_choice keys are restored as OpenAI’s NOT_GIVEN sentinel.

Parameters:
  • data – A dict produced by serialize().

  • deserialize_value – Callback to recursively deserialize nested values.

  • target_type – Unused. LLMContext is always the target.

Returns:

A new LLMContext instance.

class pipecat.bus.adapters.ToolsSchemaAdapter[source]

Bases: TypeAdapter

Serialize and deserialize ToolsSchema instances for network transport.

serialize(obj: Any, serialize_value: Callable[[Any], Any]) dict[str, Any][source]

Serialize a ToolsSchema to a JSON-compatible dict.

Parameters:
  • obj – A ToolsSchema instance.

  • serialize_value – Callback to recursively serialize nested values.

Returns:

A dict with a standard_tools list.

deserialize(data: dict[str, Any], deserialize_value: Callable[[Any], Any], target_type: type | None = None) Any[source]

Reconstruct a ToolsSchema from a serialized dict.

Parameters:
  • data – A dict produced by serialize().

  • deserialize_value – Callback to recursively deserialize nested values.

  • target_type – Unused. ToolsSchema is always the target.

Returns:

A new ToolsSchema instance.

class pipecat.bus.adapters.TypeAdapter[source]

Bases: ABC

Serialize 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 JSONMessageSerializer to handle non-JSON-native field values (e.g. LLMContext, ToolsSchema).

Adapters receive serialize_value and deserialize_value callbacks 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.

Submodules