Merge pull request #4314 from pipecat-ai/mb/prudent-system-instruction-logging

Log system instruction once at composition time, not on every LLM call
This commit is contained in:
Mark Backman
2026-04-16 13:18:33 -04:00
committed by GitHub
5 changed files with 5 additions and 7 deletions

View File

@@ -0,0 +1 @@
- Reduced debug log noise for LLM services. The system instruction is now logged once when composed (e.g. when turn completion is enabled) instead of on every LLM call. Per-call logs now show only the conversation messages, consistent across Google, Anthropic, AWS, and OpenAI services.

View File

@@ -345,9 +345,7 @@ class AnthropicLLMService(LLMService):
adapter = self.get_llm_adapter()
messages_for_logging = adapter.get_messages_for_logging(context)
logger.debug(
f"{self}: Generating chat from context [{params_from_context['system']}] | {messages_for_logging}"
)
logger.debug(f"{self}: Generating chat from context {messages_for_logging}")
await self.start_ttfb_metrics()

View File

@@ -475,9 +475,7 @@ class AWSBedrockLLMService(LLMService):
# Log request params with messages redacted for logging
adapter = self.get_llm_adapter()
messages_for_logging = adapter.get_messages_for_logging(context)
logger.debug(
f"{self}: Generating chat from context [{system}] | {messages_for_logging}"
)
logger.debug(f"{self}: Generating chat from context {messages_for_logging}")
async with self._aws_session.client(
service_name="bedrock-runtime", **self._aws_params

View File

@@ -392,7 +392,7 @@ class GoogleLLMService(LLMService):
)
logger.debug(
f"{self}: Generating chat from context [{params['system_instruction']}] | {adapter.get_messages_for_logging(context)}"
f"{self}: Generating chat from context {adapter.get_messages_for_logging(context)}"
)
messages = params["messages"]

View File

@@ -347,6 +347,7 @@ class LLMService(UserTurnCompletionLLMServiceMixin, AIService):
parts.append(ASYNC_TOOL_CANCELLATION_INSTRUCTIONS)
composed = "\n\n".join(p for p in parts if p)
self._settings.system_instruction = composed or None
logger.debug(f"{self}: System instruction composed: {self._settings.system_instruction}")
async def _update_settings(self, delta: LLMSettings) -> dict[str, Any]:
"""Apply a settings delta, handling turn-completion fields.