Skip to content

fix(llm): register official 200k context window for o1, o1-pro, and o3 (#7303) - #7323

Open
1747687484-collab wants to merge 2 commits into
crewAIInc:mainfrom
1747687484-collab:fix/o-series-context-window-7303
Open

fix(llm): register official 200k context window for o1, o1-pro, and o3 (#7303)#7323
1747687484-collab wants to merge 2 commits into
crewAIInc:mainfrom
1747687484-collab:fix/o-series-context-window-7303

Conversation

@1747687484-collab

Copy link
Copy Markdown

Related issue

Fixes #7303

Summary

The official context window for OpenAI's flagship reasoning models (o1, o1-pro, and o3) is 200,000 tokens (per official OpenAI specifications). Previously, o1, o1-pro, and o3 were missing from LLM_CONTEXT_WINDOW_SIZES and native provider completion tables (openai/completion.py and azure/completion.py).

Because prefix matching fails ("o1".startswith("o1-preview") is false), queries using model="o1", model="o1-pro", or model="o3" fell back to DEFAULT_CONTEXT_WINDOW_SIZE (8,192 tokens, resolving to 6,963 usable tokens with CONTEXT_WINDOW_USAGE_RATIO = 0.85) instead of their real 200,000 tokens (170,000 usable). This could lead to premature prompt truncation or false LLMContextLengthExceededError during long reasoning loops.

This change:

  1. Adds "o1": 200000, "o1-pro": 200000, and "o3": 200000 to LLM_CONTEXT_WINDOW_SIZES in lib/crewai/src/crewai/llm.py, while preserving the 128,000-token windows for "o1-preview" and "o1-mini".
  2. Adds "o1-pro": 200000, "o1": 200000, and "o3": 200000 to context_windows in lib/crewai/src/crewai/llms/providers/openai/completion.py with longest-prefix ordering so "o1-preview" and "o1-mini" continue matching their specific entries first.
  3. Adds o-series reasoning models to lib/crewai/src/crewai/llms/providers/azure/completion.py in longest-prefix ordering.
  4. Adds unit tests covering context window resolution for o1, o1-pro, o3, and preserving overrides for o1-preview / o1-mini.

Verification

  • Tests added or updated for the changed behavior
  • Relevant tests and quality checks pass locally

Local test results:

  • pytest lib/crewai/tests/test_llm.py -k "context_window" -> 16 passed.
  • Verified resolution for o1, o1-pro, and o3 under both LiteLLM and native OpenAI paths:
    • LLM(model="o1", is_litellm=True).get_context_window_size() -> 170000 (200000 * 0.85)
    • LLM(model="openai/o1").get_context_window_size() -> 170000 (200000 * 0.85)
    • LLM(model="o1-preview", is_litellm=True).get_context_window_size() -> 108800 (128000 * 0.85)
    • LLM(model="o1-mini", is_litellm=True).get_context_window_size() -> 108800 (128000 * 0.85)
  • Code formatting checked with ruff format.

Additional context

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 964af105-5ec2-454f-b24a-999138d29ad7

📥 Commits

Reviewing files that changed from the base of the PR and between fd831d2 and 2abafaa.

📒 Files selected for processing (1)
  • lib/crewai/src/crewai/llms/providers/azure/completion.py
💤 Files with no reviewable changes (1)
  • lib/crewai/src/crewai/llms/providers/azure/completion.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Changes

The change registers 200,000-token context windows for o1, o1-pro, and o3 in shared, OpenAI, and Azure mappings. Azure mappings also cover o1-preview, o1-mini, and o3-mini. Tests verify preserved 128,000-token windows and provider-prefixed models.

Reasoning model context windows

Layer / File(s) Summary
Context-window mappings
lib/crewai/src/crewai/llm.py, lib/crewai/src/crewai/llms/providers/openai/completion.py, lib/crewai/src/crewai/llms/providers/azure/completion.py
The shared, OpenAI, and Azure mappings recognize the added reasoning-model prefixes and configured context sizes. The Azure mapping no longer includes o4-mini.
Context-window resolution tests
lib/crewai/tests/test_llm.py
Tests verify 200,000-token windows, preserve 128,000-token windows for o1-preview and o1-mini, and cover openai/ model prefixes.

Priority: ➖ Normal — Impact reflects medium issue severity.

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2abaf

The change updates reasoning-model context-window registrations and adds resolution coverage, with no unresolved merge-readiness risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The main changes are within scope, but the Azure provider also removes the existing o4-mini mapping. Issue #7303 does not require removing o4-mini, so this change appears unrelated to the stated objec… Remove the unrelated o4-mini deletion, or document a linked requirement that requires it. Keep the PR limited to registering the requested o-series context windows and preserving existing mappings.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: registering 200,000-token context windows for o1, o1-pro, and o3.
Description check ✅ Passed The description includes the related issue, implementation summary, verification details, test results, and additional context. It covers all required template sections.
Linked Issues check ✅ Passed The changes satisfy issue #7303 by registering 200,000-token windows for o1, o1-pro, and o3 across the general configuration and provider tables. The changes preserve the 128,000-token windows for o1-…
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files.
Full details: Out of Scope Changes check

Explanation

The main changes are within scope, but the Azure provider also removes the existing o4-mini mapping. Issue #7303 does not require removing o4-mini, so this change appears unrelated to the stated objectives.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] o1, o1-pro, and o3 reasoning models fallback to 8k default context window

1 participant