Skip to content

Commit 67dc2eb

Browse files
wuliang229copybara-github
authored andcommitted
refactor(live): Use send_client_content to send conversation history
The `send` method was deprecated. Co-authored-by: Liang Wu <wuliang@google.com> PiperOrigin-RevId: 899826160
1 parent a4c9387 commit 67dc2eb

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

src/google/adk/evaluation/agent_evaluator.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class _EvalMetricResultWithInvocation(BaseModel):
9090
"""
9191

9292
actual_invocation: Invocation
93-
expected_invocation: Optional[Invocation] = None
93+
expected_invocation: Invocation
9494
eval_metric_result: EvalMetricResult
9595

9696

@@ -438,21 +438,15 @@ def _print_details(
438438
"threshold": threshold,
439439
"prompt": AgentEvaluator._convert_content_to_text(
440440
per_invocation_result.expected_invocation.user_content
441-
if per_invocation_result.expected_invocation
442-
else per_invocation_result.actual_invocation.user_content
443441
),
444442
"expected_response": AgentEvaluator._convert_content_to_text(
445443
per_invocation_result.expected_invocation.final_response
446-
if per_invocation_result.expected_invocation
447-
else None
448444
),
449445
"actual_response": AgentEvaluator._convert_content_to_text(
450446
per_invocation_result.actual_invocation.final_response
451447
),
452448
"expected_tool_calls": AgentEvaluator._convert_tool_calls_to_text(
453449
per_invocation_result.expected_invocation.intermediate_data
454-
if per_invocation_result.expected_invocation
455-
else None
456450
),
457451
"actual_tool_calls": AgentEvaluator._convert_tool_calls_to_text(
458452
per_invocation_result.actual_invocation.intermediate_data

src/google/adk/models/gemini_llm_connection.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ async def send_history(self, history: list[types.Content]):
8181

8282
if contents:
8383
logger.debug('Sending history to live connection: %s', contents)
84-
await self._gemini_session.send(
85-
input=types.LiveClientContent(
86-
turns=contents,
87-
turn_complete=contents[-1].role == 'user',
88-
),
84+
await self._gemini_session.send_client_content(
85+
turns=contents,
86+
turn_complete=contents[-1].role == 'user',
8987
)
9088
else:
9189
logger.info('no content is sent')

tests/unittests/models/test_gemini_llm_connection.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ async def test_send_history(gemini_connection, mock_gemini_session):
8181

8282
await gemini_connection.send_history(history)
8383

84-
mock_gemini_session.send.assert_called_once()
85-
call_args = mock_gemini_session.send.call_args[1]
86-
assert 'input' in call_args
87-
assert call_args['input'].turns == history
88-
assert call_args['input'].turn_complete is False # Last message is from model
84+
mock_gemini_session.send_client_content.assert_called_once()
85+
call_args = mock_gemini_session.send_client_content.call_args[1]
86+
assert 'turns' in call_args
87+
assert call_args['turns'] == history
88+
assert call_args['turn_complete'] is False # Last message is from model
8989

9090

9191
@pytest.mark.asyncio
@@ -668,9 +668,9 @@ async def test_send_history_filters_audio(mock_gemini_session, audio_part):
668668

669669
await connection.send_history(history)
670670

671-
mock_gemini_session.send.assert_called_once()
672-
call_args = mock_gemini_session.send.call_args[1]
673-
sent_contents = call_args['input'].turns
671+
mock_gemini_session.send_client_content.assert_called_once()
672+
call_args = mock_gemini_session.send_client_content.call_args[1]
673+
sent_contents = call_args['turns']
674674
# Only the model response should be sent (user audio filtered out)
675675
assert len(sent_contents) == 1
676676
assert sent_contents[0].role == 'model'
@@ -696,9 +696,9 @@ async def test_send_history_keeps_image_data(mock_gemini_session):
696696

697697
await connection.send_history(history)
698698

699-
mock_gemini_session.send.assert_called_once()
700-
call_args = mock_gemini_session.send.call_args[1]
701-
sent_contents = call_args['input'].turns
699+
mock_gemini_session.send_client_content.assert_called_once()
700+
call_args = mock_gemini_session.send_client_content.call_args[1]
701+
sent_contents = call_args['turns']
702702
# Both contents should be sent (image is not filtered)
703703
assert len(sent_contents) == 2
704704
assert sent_contents[0].parts[0].inline_data == image_blob
@@ -728,9 +728,9 @@ async def test_send_history_mixed_content_filters_only_audio(
728728

729729
await connection.send_history(history)
730730

731-
mock_gemini_session.send.assert_called_once()
732-
call_args = mock_gemini_session.send.call_args[1]
733-
sent_contents = call_args['input'].turns
731+
mock_gemini_session.send_client_content.assert_called_once()
732+
call_args = mock_gemini_session.send_client_content.call_args[1]
733+
sent_contents = call_args['turns']
734734
# Content should be sent but only with the text part
735735
assert len(sent_contents) == 1
736736
assert len(sent_contents[0].parts) == 1

0 commit comments

Comments
 (0)