fix(llm): register official 200k context window for o1, o1-pro, and o3 (#7303) - #7323
fix(llm): register official 200k context window for o1, o1-pro, and o3 (#7303)#73231747687484-collab wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughChangesThe change registers 200,000-token context windows for Reasoning model context windows
Priority: ➖ Normal — Impact reflects medium issue severity. Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
Full details: Out of Scope Changes checkExplanation The main changes are within scope, but the Azure provider also removes the existing o4-mini mapping. Issue
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Related issue
Fixes #7303
Summary
The official context window for OpenAI's flagship reasoning models (
o1,o1-pro, ando3) is 200,000 tokens (per official OpenAI specifications). Previously,o1,o1-pro, ando3were missing fromLLM_CONTEXT_WINDOW_SIZESand native provider completion tables (openai/completion.pyandazure/completion.py).Because prefix matching fails (
"o1".startswith("o1-preview")is false), queries usingmodel="o1",model="o1-pro", ormodel="o3"fell back toDEFAULT_CONTEXT_WINDOW_SIZE(8,192 tokens, resolving to 6,963 usable tokens withCONTEXT_WINDOW_USAGE_RATIO = 0.85) instead of their real 200,000 tokens (170,000 usable). This could lead to premature prompt truncation or falseLLMContextLengthExceededErrorduring long reasoning loops.This change:
"o1": 200000,"o1-pro": 200000, and"o3": 200000toLLM_CONTEXT_WINDOW_SIZESinlib/crewai/src/crewai/llm.py, while preserving the 128,000-token windows for"o1-preview"and"o1-mini"."o1-pro": 200000,"o1": 200000, and"o3": 200000tocontext_windowsinlib/crewai/src/crewai/llms/providers/openai/completion.pywith longest-prefix ordering so"o1-preview"and"o1-mini"continue matching their specific entries first.lib/crewai/src/crewai/llms/providers/azure/completion.pyin longest-prefix ordering.o1,o1-pro,o3, and preserving overrides foro1-preview/o1-mini.Verification
Local test results:
pytest lib/crewai/tests/test_llm.py -k "context_window"-> 16 passed.o1,o1-pro, ando3under 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)ruff format.Additional context