diff --git a/homeassistant/components/google_generative_ai_conversation/ai_task.py b/homeassistant/components/google_generative_ai_conversation/ai_task.py index 8c80af563b7..b0007eac385 100644 --- a/homeassistant/components/google_generative_ai_conversation/ai_task.py +++ b/homeassistant/components/google_generative_ai_conversation/ai_task.py @@ -80,7 +80,10 @@ class GoogleGenerativeAITaskEntity( ) -> ai_task.GenDataTaskResult: """Handle a generate data task.""" await self._async_handle_chat_log( - chat_log, task.structure, default_max_tokens=RECOMMENDED_AI_TASK_MAX_TOKENS + chat_log, + task.structure, + default_max_tokens=RECOMMENDED_AI_TASK_MAX_TOKENS, + max_iterations=1000, ) if not isinstance(chat_log.content[-1], conversation.AssistantContent): diff --git a/homeassistant/components/google_generative_ai_conversation/entity.py b/homeassistant/components/google_generative_ai_conversation/entity.py index e223d34d28b..fba51dcd7ef 100644 --- a/homeassistant/components/google_generative_ai_conversation/entity.py +++ b/homeassistant/components/google_generative_ai_conversation/entity.py @@ -486,6 +486,7 @@ class GoogleGenerativeAILLMBaseEntity(Entity): chat_log: conversation.ChatLog, structure: vol.Schema | None = None, default_max_tokens: int | None = None, + max_iterations: int = MAX_TOOL_ITERATIONS, ) -> None: """Generate an answer for the chat log.""" options = self.subentry.data @@ -602,7 +603,7 @@ class GoogleGenerativeAILLMBaseEntity(Entity): ) # To prevent infinite loops, we limit the number of iterations - for _iteration in range(MAX_TOOL_ITERATIONS): + for _iteration in range(max_iterations): try: chat_response_generator = await chat.send_message_stream( message=chat_request