anthropic_adapter
Anthropic LLM adapter for Pipecat.
- pipecat.adapters.services.anthropic_adapter.is_given(value: _T | NotGiven) TypeGuard[_T][source]
Check whether a value was explicitly provided.
Typically used when checking whether a parameter or field typed with Anthropic’s
NotGivenwas set:if is_given(system): ...
Also acts as a type guard: inside a true branch, the value is narrowed to exclude
NotGiven(e.g.str | NotGivenbecomesstr).- Parameters:
value – The value to check.
- Returns:
Trueif value is anything other thanNOT_GIVEN.
- class pipecat.adapters.services.anthropic_adapter.AnthropicLLMInvocationParams[source]
Bases:
TypedDictContext-based parameters for invoking Anthropic’s LLM API.
- system: str | NotGiven
- messages: list[MessageParam]
- tools: list[ToolParam | ToolBash20250124Param | CodeExecutionTool20250522Param | CodeExecutionTool20250825Param | CodeExecutionTool20260120Param | MemoryTool20250818Param | ToolTextEditor20250124Param | ToolTextEditor20250429Param | ToolTextEditor20250728Param | WebSearchTool20250305Param | WebFetchTool20250910Param | WebSearchTool20260209Param | WebFetchTool20260209Param | WebFetchTool20260309Param | ToolSearchToolBm25_20251119Param | ToolSearchToolRegex20251119Param]
- class pipecat.adapters.services.anthropic_adapter.AnthropicLLMAdapter[source]
Bases:
BaseLLMAdapter[AnthropicLLMInvocationParams]Adapter for converting tool schemas to Anthropic’s function-calling format.
This adapter handles the conversion of Pipecat’s standard function schemas to the specific format required by Anthropic’s Claude models for function calling.
- property id_for_llm_specific_messages: str
Get the identifier used in LLMSpecificMessage instances for Anthropic.
- get_llm_invocation_params(context: LLMContext, enable_prompt_caching: bool, system_instruction: str | None = None) AnthropicLLMInvocationParams[source]
Get Anthropic-specific LLM invocation parameters from a universal LLM context.
- Parameters:
context – The LLM context containing messages, tools, etc.
enable_prompt_caching – Whether prompt caching should be enabled.
system_instruction – Optional system instruction from service settings or
run_inference.
- Returns:
Dictionary of parameters for invoking Anthropic’s LLM API.
- 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 Anthropic.
Removes or truncates sensitive data like image content for safe logging.
- Parameters:
context – The LLM context containing messages.
- Returns:
List of messages in a format ready for logging about Anthropic.
- class ConvertedMessages(messages: list[MessageParam], system: str | NotGiven)[source]
Bases:
objectContainer for Anthropic-formatted messages converted from universal context.
- messages: list[MessageParam]
- system: str | NotGiven
- to_provider_tools_format(tools_schema: ToolsSchema) list[dict[str, Any]][source]
Convert function schemas to Anthropic’s function-calling format.
- Parameters:
tools_schema – The tools schema containing functions to convert.
- Returns:
List of function definitions formatted for Anthropic’s API.