grok_realtime_adapter

Grok Realtime LLM adapter for Pipecat.

Converts Pipecat’s tool schemas and context into the format required by Grok’s Voice Agent API.

class pipecat.adapters.services.grok_realtime_adapter.GrokRealtimeLLMInvocationParams[source]

Bases: TypedDict

Context-based parameters for invoking Grok Realtime API.

Parameters:
  • system_instruction – System prompt/instructions for the session.

  • messages – List of conversation items formatted for Grok Realtime.

  • tools – List of tool definitions (function, web_search, x_search, file_search).

system_instruction: str | None
messages: list[ConversationItem]
tools: list[dict[str, Any]]
class pipecat.adapters.services.grok_realtime_adapter.GrokRealtimeLLMAdapter[source]

Bases: BaseLLMAdapter

LLM adapter for Grok Voice Agent API.

Converts Pipecat’s universal context and tool schemas into the specific format required by Grok’s Voice Agent Realtime API.

property id_for_llm_specific_messages: str

Get the identifier used in LLMSpecificMessage instances for Grok Realtime.

get_llm_invocation_params(context: LLMContext, *, system_instruction: str | None = None) GrokRealtimeLLMInvocationParams[source]

Get Grok Realtime-specific LLM invocation parameters from a universal LLM context.

Parameters:
  • context – The LLM context containing messages, tools, etc.

  • system_instruction – Optional system instruction from service settings.

Returns:

Dictionary of parameters for invoking Grok’s Voice Agent API.

get_messages_for_logging(context) list[dict[str, Any]][source]

Get messages from context in a format safe for logging.

Binary data (images, audio) is replaced with short placeholders.

Parameters:

context – The LLM context containing messages.

Returns:

List of messages with sensitive data redacted.

class ConvertedMessages(messages: list[ConversationItem], system_instruction: str | None = None)[source]

Bases: object

Container for Grok-formatted messages converted from universal context.

messages: list[ConversationItem]
system_instruction: str | None = None
to_provider_tools_format(tools_schema: ToolsSchema) list[dict[str, Any]][source]

Convert tool schemas to Grok Realtime format.

Supports both standard function tools and Grok-specific tools (web_search, x_search, file_search).

Parameters:

tools_schema – The tools schema containing functions to convert.

Returns:

List of tool definitions in Grok Realtime format.