From 5bf7e83e76364700251e71eeb9c1a962cdf22eee Mon Sep 17 00:00:00 2001 From: Denis Shulyaka Date: Sat, 14 Feb 2026 14:33:12 +0300 Subject: [PATCH] Anthropic: Increase max iterations for AI Task (#162954) --- homeassistant/components/anthropic/ai_task.py | 4 +++- homeassistant/components/anthropic/entity.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/anthropic/ai_task.py b/homeassistant/components/anthropic/ai_task.py index 33748928b74..d3536ec9bf4 100644 --- a/homeassistant/components/anthropic/ai_task.py +++ b/homeassistant/components/anthropic/ai_task.py @@ -50,7 +50,9 @@ class AnthropicTaskEntity( chat_log: conversation.ChatLog, ) -> ai_task.GenDataTaskResult: """Handle a generate data task.""" - await self._async_handle_chat_log(chat_log, task.name, task.structure) + await self._async_handle_chat_log( + chat_log, task.name, task.structure, max_iterations=1000 + ) if not isinstance(chat_log.content[-1], conversation.AssistantContent): raise HomeAssistantError( diff --git a/homeassistant/components/anthropic/entity.py b/homeassistant/components/anthropic/entity.py index b8a194eb368..f82cf5859cf 100644 --- a/homeassistant/components/anthropic/entity.py +++ b/homeassistant/components/anthropic/entity.py @@ -599,6 +599,7 @@ class AnthropicBaseLLMEntity(Entity): chat_log: conversation.ChatLog, structure_name: str | None = None, structure: vol.Schema | None = None, + max_iterations: int = MAX_TOOL_ITERATIONS, ) -> None: """Generate an answer for the chat log.""" options = self.subentry.data @@ -770,7 +771,7 @@ class AnthropicBaseLLMEntity(Entity): client = self.entry.runtime_data # To prevent infinite loops, we limit the number of iterations - for _iteration in range(MAX_TOOL_ITERATIONS): + for _iteration in range(max_iterations): try: stream = await client.messages.create(**model_args)