Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/google/adk/apps/llm_event_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions tests/unittests/apps/test_llm_event_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down