llm_context_adapter
Type adapter for LLMContext serialization.
- class pipecat.bus.adapters.llm_context_adapter.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.