diff --git a/src/google/adk/apps/llm_event_summarizer.py b/src/google/adk/apps/llm_event_summarizer.py index 5e88a0bc02d..6081690da78 100644 --- a/src/google/adk/apps/llm_event_summarizer.py +++ b/src/google/adk/apps/llm_event_summarizer.py @@ -51,7 +51,10 @@ class LlmEventSummarizer(BaseEventsSummarizer): ' reiterate the user request, summarize the context so far, focusing on' ' key decisions made and information obtained, as well as any unresolved' ' questions or tasks. The summary should be concise and capture the' - ' essence of the interaction.\n\n{conversation_history}' + ' essence of the interaction. When evident, preserve the conversation' + ' language and any response-language convention from the original' + ' interaction so future turns keep the same language even if retrieved' + ' tool content uses another language.\n\n{conversation_history}' ) # Tool call args and responses can be large (e.g. search results). Cap how diff --git a/tests/unittests/apps/test_llm_event_summarizer.py b/tests/unittests/apps/test_llm_event_summarizer.py index 3ce7c6ddf2c..864cc4d478f 100644 --- a/tests/unittests/apps/test_llm_event_summarizer.py +++ b/tests/unittests/apps/test_llm_event_summarizer.py @@ -95,6 +95,45 @@ async def async_gen(): self.assertEqual(llm_request.contents[0].parts[0].text, expected_prompt) self.assertFalse(kwargs['stream']) + async def test_default_prompt_preserves_conversation_language_anchor(self): + events = [ + self._create_event( + 1.0, + 'Please answer in English while checking this retrieved material.', + 'user', + ), + Event( + timestamp=2.0, + author='model', + content=Content( + parts=[ + Part( + function_response=FunctionResponse( + id='call_1', + name='retrieve', + response={'document': 'Я подготовил данные.'}, + ) + ) + ] + ), + ), + ] + llm_response = LlmResponse( + content=Content(parts=[Part(text='Summary')]), + usage_metadata=None, + ) + + async def async_gen(): + yield llm_response + + self.mock_llm.generate_content_async.return_value = async_gen() + + await self.compactor.maybe_summarize_events(events=events) + + args, _ = self.mock_llm.generate_content_async.call_args + prompt = args[0].contents[0].parts[0].text + self.assertIn('preserve the conversation language', prompt) + async def test_maybe_compact_events_empty_llm_response(self): events = [ self._create_event(1.0, 'Hello', 'user'),