diff --git a/lib/crewai/src/crewai/llm.py b/lib/crewai/src/crewai/llm.py index f42e2c483c..336b3e7f98 100644 --- a/lib/crewai/src/crewai/llm.py +++ b/lib/crewai/src/crewai/llm.py @@ -125,7 +125,6 @@ LiteLLMStreamingChoices = None get_supported_openai_params = None ChatCompletionDeltaToolCall = None - ChatCompletionDeltaCustomToolCall = None Function = None ModelResponse = None supports_response_schema = None @@ -136,7 +135,7 @@ def _ensure_litellm() -> bool: global _litellm_loaded, LITELLM_AVAILABLE global litellm, Choices, LiteLLMDelta, Message, ModelResponseBase global ModelResponseStream, LiteLLMStreamingChoices, get_supported_openai_params - global ChatCompletionDeltaCustomToolCall, ChatCompletionDeltaToolCall, Function + global ChatCompletionDeltaToolCall, Function global ModelResponse, supports_response_schema if _litellm_loaded: diff --git a/lib/crewai/tests/test_llm.py b/lib/crewai/tests/test_llm.py index 0e7c1b501a..9f32de310d 100644 --- a/lib/crewai/tests/test_llm.py +++ b/lib/crewai/tests/test_llm.py @@ -1141,6 +1141,25 @@ def test_litellm_path_preserves_provider_from_model_prefix(model, expected_provi assert llm.model == model +@requires_litellm_python_311 +def test_litellm_fallback_loads_without_custom_tool_call_delta_type( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """LiteLLM releases before 1.97.0 lack ChatCompletionDeltaCustomToolCall. + + The fallback only needs that type for type checking, so it must still load. + """ + import litellm.types.utils + + monkeypatch.delattr(litellm.types.utils, "ChatCompletionDeltaCustomToolCall") + monkeypatch.setattr("crewai.llm._litellm_loaded", False) + monkeypatch.setattr("crewai.llm.LITELLM_AVAILABLE", False) + + llm = LLM(model="openai/custom-finetune-model", is_litellm=False) + + assert llm.is_litellm is True + + def test_litellm_keeps_provider_but_formats_multimodal_as_openai_schema(): llm = LLM(model="anthropic/claude-3-5-haiku-20241022", is_litellm=True) assert llm.provider == "anthropic"