From 2eec4cea6f06f2c6b09477059d1ee88cc40d9eca Mon Sep 17 00:00:00 2001 From: Calvin Smith Date: Fri, 28 Feb 2025 13:08:24 -0700 Subject: [PATCH] Fix: Update context window exceeded detection (#7024) Co-authored-by: Calvin Smith Co-authored-by: Engel Nyst --- openhands/controller/agent_controller.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py index dbe9151e77..406c4fa4fa 100644 --- a/openhands/controller/agent_controller.py +++ b/openhands/controller/agent_controller.py @@ -697,10 +697,13 @@ class AgentController: except (ContextWindowExceededError, BadRequestError, OpenAIError) as e: # FIXME: this is a hack until a litellm fix is confirmed # Check if this is a nested context window error + # We have to rely on string-matching because LiteLLM doesn't consistently + # wrap the failure in a ContextWindowExceededError error_str = str(e).lower() if ( 'contextwindowexceedederror' in error_str or 'prompt is too long' in error_str + or 'input length and `max_tokens` exceed context limit' in error_str or isinstance(e, ContextWindowExceededError) ): if self.agent.config.enable_history_truncation: