This commit is contained in:
Brandon Hancock
2025-01-24 11:54:05 -05:00
parent e27a15023c
commit 0cba344976
2 changed files with 37 additions and 2 deletions

View File

@@ -262,8 +262,8 @@ class Agent(BaseAgent):
}
)["output"]
except Exception as e:
if isinstance(e, LiteLLMAuthenticationError):
# Do not retry on authentication errors
if e.__class__.__module__.startswith("litellm.exceptions"):
# Do not retry on litellm errors
raise e
self._times_executed += 1
if self._times_executed > self.max_retry_limit:

View File

@@ -1700,3 +1700,38 @@ def test_crew_agent_executor_litellm_auth_error():
)
# Verify the call was only made once (no retries)
mock_llm_call.assert_called_once()
def test_litellm_anthropic_error_handling():
"""Test that AnthropicError from LiteLLM is handled correctly and not retried."""
from litellm.llms.anthropic.common_utils import AnthropicError
# Create an agent with a mocked LLM that uses an Anthropic model
agent = Agent(
role="test role",
goal="test goal",
backstory="test backstory",
llm=LLM(model="claude-3.5-sonnet-20240620"),
max_retry_limit=0,
)
# Create a task
task = Task(
description="Test task",
expected_output="Test output",
agent=agent,
)
# Mock the LLM call to raise AnthropicError
with (
patch.object(LLM, "call") as mock_llm_call,
pytest.raises(AnthropicError, match="Test Anthropic error"),
):
mock_llm_call.side_effect = AnthropicError(
status_code=500,
message="Test Anthropic error",
)
agent.execute_task(task)
# Verify the LLM call was only made once (no retries)
mock_llm_call.assert_called_once()