Fix: Update context window exceeded detection (#7024)

Co-authored-by: Calvin Smith <calvin@all-hands.dev>
Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
Calvin Smith 2025-02-28 13:08:24 -07:00 committed by GitHub
parent 32ee6a5a64
commit 2eec4cea6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: