mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 23:58:34 +00:00
implement proper try / except
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}",
|
||||
|
||||
Reference in New Issue
Block a user