Skip to content

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

Open
Rohitkanithi wants to merge 1 commit into
crewAIInc:mainfrom
Rohitkanithi:fix/o-series-context-window
Open

fix(llm): register official 200k context window for o1 and o3 (#7303)#7354
Rohitkanithi wants to merge 1 commit into
crewAIInc:mainfrom
Rohitkanithi:fix/o-series-context-window

Conversation

@Rohitkanithi

@Rohitkanithi Rohitkanithi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #7303

Summary

As noted in the issue description, I already had this patch and test suite completed and submitted. Opening this PR with complete coverage across test_llm, test_openai, and test_azure.

Problem

The official context window for OpenAI's flagship reasoning models (o1, o1-pro, and o3) and Azure OpenAI deployments of o1, o1-mini, and o3-mini is 200,000 tokens. Previously, they were missing from LLM_CONTEXT_WINDOW_SIZES and native provider context_windows tables.

Because prefix matching fails ("o1".startswith("o1-preview") is false), queries using model="o1" or model="o3" fell back to DEFAULT_CONTEXT_WINDOW_SIZE (8,192 tokens, resolving to 6,963 usable tokens with ratio 0.85). This triggered false LLMContextLengthExceededError or premature prompt truncation on reasoning models.

Changes

  1. Added "o1": 200000, "o1-pro": 200000, and "o3": 200000 to LLM_CONTEXT_WINDOW_SIZES in lib/crewai/src/crewai/llm.py, preserving 128000 for o1-preview and o1-mini.
  2. Added "o1-pro": 200000, "o1": 200000, and "o3": 200000 to context_windows in lib/crewai/src/crewai/llms/providers/openai/completion.py with longest-prefix-first ordering.
  3. Added o1-preview, o1-mini, o1-pro, o1, o3-mini, o3, and o4-mini to lib/crewai/src/crewai/llms/providers/azure/completion.py.
  4. Added comprehensive parameterized unit tests across:
    • lib/crewai/tests/test_llm.py
    • lib/crewai/tests/llms/openai/test_openai.py
    • lib/crewai/tests/llms/azure/test_azure.py

Verification

  • All 6 files pass syntax and local test checks.
  • Tested resolution for o1, o1-pro, o3, o1-mini, and o1-preview across LiteLLM, OpenAI, and Azure paths.

@coderabbitai

coderabbitai Bot commented Sep 9, 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: a0114049-425f-4ac2-a0b9-5adb7511aae6

📥 Commits

Reviewing files that changed from the base of the PR and between a53ecc1 and b2c20df.

📒 Files selected for processing (6)
  • lib/crewai/src/crewai/llm.py
  • lib/crewai/src/crewai/llms/providers/azure/completion.py
  • lib/crewai/src/crewai/llms/providers/openai/completion.py
  • lib/crewai/tests/llms/azure/test_azure.py
  • lib/crewai/tests/llms/openai/test_openai.py
  • lib/crewai/tests/test_llm.py

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


📝 Walkthrough

Walkthrough

Changes

The change adds 128,000- and 200,000-token context window mappings for OpenAI and Azure o-series reasoning models. Shared and provider-specific tests verify the resolved values after applying CONTEXT_WINDOW_USAGE_RATIO.

Reasoning model context windows

Layer / File(s) Summary
Add o-series context mappings
lib/crewai/src/crewai/llm.py, lib/crewai/src/crewai/llms/providers/*/completion.py
Shared, OpenAI, and Azure lookups now recognize the added o-series model prefixes and assign their supported context windows.
Validate context window resolution
lib/crewai/tests/llms/*, lib/crewai/tests/test_llm.py
Parameterized tests verify 200,000-token windows for current models and 128,000-token windows for preview and mini models, scaled by CONTEXT_WINDOW_USAGE_RATIO.

Suggested reviewers: lorenzejay, lucasgomide

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to b2c20

OpenAI and Azure o-series models now use their registered context windows rather than the default fallback, preventing premature truncation and false context-length failures. The covered mappings are ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The pull request satisfies issue #7303. It registers 200,000-token windows for o1, o1-pro, and o3 in the global and OpenAI mappings, adds Azure o-series mappings, preserves 128,000-token windows for o…
Out of Scope Changes check ✅ Passed The changes are limited to context-window mappings and tests for OpenAI and Azure o-series reasoning models. The additional Azure o4-mini mapping remains within the stated o-series provider scope.
Title check ✅ Passed The title clearly identifies the main change: registering the official 200,000-token context window for the o1 and o3 model families.
Description check ✅ Passed The description identifies issue #7303, explains the problem, lists the implementation changes, and documents verification. The optional Additional context section is missing, but the required informa…
  • 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