From 153705f05ba4ea6474e282f5d73e8374e413e957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 10 Mar 2026 09:25:42 -0700 Subject: [PATCH] Fix Google LLM system instruction priority Constructor/settings system_instruction now takes priority over the context system message. Previously the context value would overwrite the constructor value on every call. Warn when both are set. --- src/pipecat/services/google/llm.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pipecat/services/google/llm.py b/src/pipecat/services/google/llm.py index 7f4f8caae..d14795d29 100644 --- a/src/pipecat/services/google/llm.py +++ b/src/pipecat/services/google/llm.py @@ -997,12 +997,16 @@ class GoogleLLMService(LLMService): self, params_from_context: GeminiLLMInvocationParams ) -> AsyncIterator[GenerateContentResponse]: messages = params_from_context["messages"] - if ( - params_from_context["system_instruction"] - and self._settings.system_instruction != params_from_context["system_instruction"] - ): - logger.debug(f"System instruction changed: {params_from_context['system_instruction']}") - self._settings.system_instruction = params_from_context["system_instruction"] + + # Constructor/settings system instruction takes priority over context. + if self._settings.system_instruction and params_from_context["system_instruction"]: + logger.warning( + f"{self}: Both system_instruction and a system message in context are" + " set. Using system_instruction." + ) + system_instruction = ( + self._settings.system_instruction or params_from_context["system_instruction"] + ) tools = [] if params_from_context["tools"]: @@ -1015,7 +1019,7 @@ class GoogleLLMService(LLMService): # Build generation parameters generation_params = self._build_generation_params( - system_instruction=self._settings.system_instruction, + system_instruction=system_instruction, tools=tools, tool_config=tool_config, )