llm_context_adapter

Type adapter for LLMContext serialization.

class pipecat.bus.adapters.llm_context_adapter.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.