implement proper try / except

This commit is contained in:
Brandon Hancock
2025-01-21 14:56:17 -05:00
parent 002568f2b2
commit e32d1007ba
2 changed files with 10 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import shutil
import subprocess
from typing import Any, Dict, List, Literal, Optional, Union
from litellm import AuthenticationError as LiteLLMAuthenticationError
from pydantic import Field, InstanceOf, PrivateAttr, model_validator
from crewai.agents import CacheHandler
@@ -261,6 +262,9 @@ class Agent(BaseAgent):
}
)["output"]
except Exception as e:
if isinstance(e, LiteLLMAuthenticationError):
# Do not retry on authentication errors
raise e
self._times_executed += 1
if self._times_executed > self.max_retry_limit:
raise e

View File

@@ -100,7 +100,11 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
self._show_start_logs()
self.ask_for_human_input = bool(inputs.get("ask_for_human_input", False))
formatted_answer = self._invoke_loop()
try:
formatted_answer = self._invoke_loop()
except Exception as e:
raise e
if self.ask_for_human_input:
formatted_answer = self._handle_human_feedback(formatted_answer)
@@ -153,7 +157,7 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
continue
elif self._is_litellm_authentication_error(e):
self._handle_litellm_auth_error(e)
break
raise e
else:
self._printer.print(
content=f"Unhandled exception: {e}",