Skip to content
This repository was archived by the owner on Sep 14, 2026. It is now read-only.

fix: pass model and llm_provider to ContextWindowExceededError constructor - #275

Closed
paulxg12 wants to merge 1 commit into
huggingface:mainfrom
paulxg12:fix/context-window-exceeded-error-init
Closed

paulxg12 wants to merge 1 commit into
huggingface:mainfrom
paulxg12:fix/context-window-exceeded-error-init

Conversation

@paulxg12

Copy link
Copy Markdown

What

Fix a TypeError in _call_llm_streaming and _call_llm_non_streaming that prevents context compaction from triggering when the LLM responds with a context overflow error.

Why

Fixes #270. When litellm raises a BadRequestError (or similar) indicating the prompt exceeds the model context window, the exception handlers attempt to re-raise it as ContextWindowExceededError but omit the required model and llm_provider positional arguments:

TypeError: ContextWindowExceededError.__init__() missing 2 required positional arguments: 'model' and 'llm_provider'

This prevents the except ContextWindowExceededError: handler in the main agent loop (line ~1692) from ever catching the error, so context compaction never fires. The session is permanently stuck throwing the same TypeError on every iteration.

How

Both _call_llm_streaming (line ~876) and _call_llm_non_streaming (line ~1033) now pass:

  • model — from llm_params.get("model", "")
  • llm_provider — extracted as the prefix before / in the model string (e.g. "openai", "anthropic", "bedrock")

These values are already available in llm_params at the call site.

Testing

  • The fix is a minimal change (2 call sites, +10 lines) that matches the constructor signature used everywhere else in litellm.
  • The except ContextWindowExceededError: handler in run_agent at line ~1692 can now correctly catch the re-raised error and trigger context compaction.

Checklist

  • Follows existing code style
  • No breaking changes
  • Documentation updated if needed

…uctor

When litellm raises a non-ContextWindowExceededError that indicates
context overflow (e.g. BadRequestError with 'prompt is too long'),
_call_llm_streaming and _call_llm_non_streaming try to re-raise it
as ContextWindowExceededError but omit the required model and
llm_provider arguments, causing:

  TypeError: ContextWindowExceededError.__init__() missing 2 required
  positional arguments: 'model' and 'llm_provider'

This prevents context compaction from triggering and the session is
permanently stuck in an error loop.

Fixes huggingface#270
@lewtun

lewtun commented Sep 14, 2026

Copy link
Copy Markdown
Member

Thanks for contributing to ML Intern. The project, including its CLI, has been retired and this repository is being archived. We will therefore not be able to review or merge this work. For continued AI assistance, please use HuggingChat.

@lewtun lewtun closed this Sep 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

latest version fails to compact context and endlessly throws a malformed ContextWindowExceededError exception

2 participants