diff --git a/src/google/adk/models/gemini_llm_connection.py b/src/google/adk/models/gemini_llm_connection.py index da508891d4..39676c32de 100644 --- a/src/google/adk/models/gemini_llm_connection.py +++ b/src/google/adk/models/gemini_llm_connection.py @@ -105,12 +105,21 @@ async def send_content(self, content: types.Content): # All parts have to be function responses. function_responses = [part.function_response for part in content.parts] logger.debug('Sending LLM function response: %s', function_responses) - await self._gemini_session.send( - input=types.LiveClientToolResponse( - function_responses=function_responses - ), + await self._gemini_session.send_tool_response( + function_responses=function_responses ) else: + # 3.1 models reject LiveClientContent for mid-conversation text + if self._model_version and '3.1' in self._model_version: + text_parts = [p.text for p in content.parts if p.text] + if text_parts: + combined = ' '.join(text_parts) + logger.debug( + 'Sending text via realtime input for 3.1 model: %s', + combined[:100], + ) + await self._gemini_session.send_realtime_input(text=combined) + return logger.debug('Sending LLM new content %s', content) await self._gemini_session.send( input=types.LiveClientContent( @@ -128,7 +137,7 @@ async def send_realtime(self, input: RealtimeInput): if isinstance(input, types.Blob): # The blob is binary and is very large. So let's not log it. logger.debug('Sending LLM Blob.') - await self._gemini_session.send_realtime_input(media=input) + await self._gemini_session.send_realtime_input(audio=input) elif isinstance(input, types.ActivityStart): logger.debug('Sending LLM activity start signal.') diff --git a/src/google/adk/models/google_llm.py b/src/google/adk/models/google_llm.py index 609de3d3d3..fa8980a8cb 100644 --- a/src/google/adk/models/google_llm.py +++ b/src/google/adk/models/google_llm.py @@ -401,6 +401,16 @@ async def connect(self, llm_request: LlmRequest) -> BaseLlmConnection: ' backend. Please use Vertex AI backend.' ) llm_request.live_connect_config.tools = llm_request.config.tools + + # 3.1 models require history_config for session history to work + model_name = llm_request.model or '' + if '3.1' in model_name and not getattr( + llm_request.live_connect_config, 'history_config', None + ): + llm_request.live_connect_config.history_config = types.HistoryConfig( + initial_history_in_client_content=True + ) + logger.debug('Connecting to live with llm_request:%s', llm_request) logger.debug('Live connect config: %s', llm_request.live_connect_config) async with self._live_api_client.aio.live.connect(