base_llm_adapter
Base adapter for LLM provider integration.
This module provides the abstract base class for implementing LLM provider-specific adapters that handle tool format conversion and standardization.
- class pipecat.adapters.base_llm_adapter.BaseLLMAdapter[source]
Bases:
ABC,Generic[TLLMInvocationParams]Abstract base class for LLM provider adapters.
Provides a standard interface for converting to provider-specific formats.
Handles:
Extracting provider-specific parameters for LLM invocation from a universal LLM context
Converting standardized tools schema to provider-specific tool formats.
Extracting messages from the LLM context for the purposes of logging about the specific provider.
Resolving conflicts between
system_instructionand initial system/developer messages in the conversation context.
Subclasses must implement provider-specific conversion logic.
- property builtin_tools: dict[str, FunctionSchema]
Built-in tools automatically merged into every inference request.
Keyed by tool name for O(1) lookup, insertion, and removal. The service injects tools here so they are sent transparently on every inference request without the user having to add them to their
ToolsSchema.- Returns:
Mutable dict mapping tool name to
FunctionSchema.
- abstract property id_for_llm_specific_messages: str
Get the identifier used in LLMSpecificMessage instances for this LLM provider.
- Returns:
The identifier string.
- abstractmethod get_llm_invocation_params(context: LLMContext, **kwargs) TLLMInvocationParams[source]
Get provider-specific LLM invocation parameters from a universal LLM context.
- Parameters:
context – The LLM context containing messages, tools, etc.
**kwargs – Additional provider-specific arguments that subclasses can use.
- Returns:
Provider-specific parameters for invoking the LLM.
- abstractmethod to_provider_tools_format(tools_schema: ToolsSchema) list[Any][source]
Convert tools schema to the provider’s specific format.
- Parameters:
tools_schema – The standardized tools schema to convert.
- Returns:
List of tools in the provider’s expected format.
- abstractmethod get_messages_for_logging(context: LLMContext) list[dict[str, Any]][source]
Get messages from a universal LLM context in a format ready for logging about this provider.
- Parameters:
context – The LLM context containing messages.
- Returns:
List of messages in a format ready for logging about this provider.
- create_llm_specific_message(message: Any) LLMSpecificMessage[source]
Create an LLM-specific message (as opposed to a standard message) for use in an LLMContext.
- Parameters:
message – The message content.
- Returns:
A LLMSpecificMessage instance.
- get_messages(context: LLMContext, *, truncate_large_values: bool = False) list[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam | LLMSpecificMessage][source]
Get messages from the LLM context, including standard and LLM-specific messages.
- Parameters:
context – The LLM context containing messages.
truncate_large_values – If True, return deep copies of messages with large values replaced by short placeholders.
- Returns:
List of messages including standard and LLM-specific messages.
- from_standard_tools(tools: Any) list[Any] | NotGiven[source]
Convert tools from standard format to provider format.
Built-in tools are automatically merged into the schema before conversion so that every inference request receives them without the user having to declare them explicitly.
- Parameters:
tools – Tools in standard format or provider-specific format.
- Returns:
List of tools converted to provider format, or original tools if not in standard format.