Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

Fix litellm issues to be more broad (#1960)

Brandon Hancock (bhancock_ai)8c76bad50f5b
diff --git a/docs/installation.mdx b/docs/installation.mdx
index d629c4c80..8abba152a 100644
--- a/docs/installation.mdx
+++ b/docs/installation.mdx
@@ -139,7 +139,6 @@ Now let's get you set up! πŸš€
β”‚ └── __init__.py
└── config/
β”œβ”€β”€ agents.yaml
- β”œβ”€β”€ config.yaml
└── tasks.yaml
```
</Frame>
diff --git a/src/crewai/agents/crew_agent_executor.py b/src/crewai/agents/crew_agent_executor.py
index ee5b9c582..d7bf97795 100644
--- a/src/crewai/agents/crew_agent_executor.py
+++ b/src/crewai/agents/crew_agent_executor.py
@@ -149,33 +149,19 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
if self._is_context_length_exceeded(e):
self._handle_context_length()
continue
- elif self._is_litellm_authentication_error(e):
- self._handle_litellm_auth_error(e)
- raise e
else:
- self._printer.print(
- content=f"Unhandled exception: {e}",
- color="red",
- )
+ self._handle_unknown_error(e)
+ raise e
finally:
self.iterations += 1
self._show_logs(formatted_answer)
return formatted_answer
- def _is_litellm_authentication_error(self, exception: Exception) -> bool:
- """Check if the exception is a litellm authentication error."""
- if LiteLLMAuthenticationError and isinstance(
- exception, LiteLLMAuthenticationError
- ):
- return True
-
- return False
-
- def _handle_litellm_auth_error(self, exception: Exception) -> None:
- """Handle litellm authentication error by informing the user and exiting."""
+ def _handle_unknown_error(self, exception: Exception) -> None:
+ """Handle unknown errors by informing the user."""
self._printer.print(
- content="Authentication error with litellm occurred. Please check your API key and configuration.",
+ content="An unknown error occurred. Please check the details below.",
color="red",
)
self._printer.print(
diff --git a/tests/agent_test.py b/tests/agent_test.py
index 46b20004e..3ed51ebde 100644
--- a/tests/agent_test.py
+++ b/tests/agent_test.py
@@ -1638,13 +1638,13 @@ def test_litellm_auth_error_handling():
def test_crew_agent_executor_litellm_auth_error():
- """Test that CrewAgentExecutor properly identifies and handles LiteLLM authentication errors."""
+ """Test that CrewAgentExecutor handles LiteLLM authentication errors by raising them."""
from litellm import AuthenticationError as LiteLLMAuthenticationError
from crewai.agents.tools_handler import ToolsHandler
from crewai.utilities import Printer
- # Create an agent and executor with max_retry_limit=0
+ # Create an agent and executor
agent = Agent(
role="test role",
goal="test goal",
@@ -1691,7 +1691,7 @@ def test_crew_agent_executor_litellm_auth_error():
# Verify error handling
mock_printer.assert_any_call(
- content="Authentication error with litellm occurred. Please check your API key and configuration.",
+ content="An unknown error occurred. Please check the details below.",
color="red",
)
mock_printer.assert_any_call(