Skip to content

Commit ee9b194

Browse files
committed
fix(apps): preserve compaction language anchor
1 parent dec2182 commit ee9b194

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/google/adk/apps/llm_event_summarizer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class LlmEventSummarizer(BaseEventsSummarizer):
5151
' reiterate the user request, summarize the context so far, focusing on'
5252
' key decisions made and information obtained, as well as any unresolved'
5353
' questions or tasks. The summary should be concise and capture the'
54-
' essence of the interaction.\n\n{conversation_history}'
54+
' essence of the interaction. When evident, preserve the conversation'
55+
' language and any response-language convention from the original'
56+
' interaction so future turns keep the same language even if retrieved'
57+
' tool content uses another language.\n\n{conversation_history}'
5558
)
5659

5760
# Tool call args and responses can be large (e.g. search results). Cap how

tests/unittests/apps/test_llm_event_summarizer.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,45 @@ async def async_gen():
9595
self.assertEqual(llm_request.contents[0].parts[0].text, expected_prompt)
9696
self.assertFalse(kwargs['stream'])
9797

98+
async def test_default_prompt_preserves_conversation_language_anchor(self):
99+
events = [
100+
self._create_event(
101+
1.0,
102+
'Please answer in English while checking this retrieved material.',
103+
'user',
104+
),
105+
Event(
106+
timestamp=2.0,
107+
author='model',
108+
content=Content(
109+
parts=[
110+
Part(
111+
function_response=FunctionResponse(
112+
id='call_1',
113+
name='retrieve',
114+
response={'document': 'Я подготовил данные.'},
115+
)
116+
)
117+
]
118+
),
119+
),
120+
]
121+
llm_response = LlmResponse(
122+
content=Content(parts=[Part(text='Summary')]),
123+
usage_metadata=None,
124+
)
125+
126+
async def async_gen():
127+
yield llm_response
128+
129+
self.mock_llm.generate_content_async.return_value = async_gen()
130+
131+
await self.compactor.maybe_summarize_events(events=events)
132+
133+
args, _ = self.mock_llm.generate_content_async.call_args
134+
prompt = args[0].contents[0].parts[0].text
135+
self.assertIn('preserve the conversation language', prompt)
136+
98137
async def test_maybe_compact_events_empty_llm_response(self):
99138
events = [
100139
self._create_event(1.0, 'Hello', 'user'),

0 commit comments

Comments
 (0)