More clean up

This commit is contained in:
Brandon Hancock
2025-01-24 12:06:50 -05:00
parent 63fcc74faf
commit e125b136b9
3 changed files with 12 additions and 13 deletions

View File

@@ -1,15 +1,13 @@
import os
import shutil
import subprocess
from typing import Any, Dict, List, Literal, Optional, Union
from litellm import AuthenticationError as LiteLLMAuthenticationError
from litellm.llms.base_llm.chat.transformation import BaseLLMException
from pydantic import Field, InstanceOf, PrivateAttr, model_validator
from crewai.agents import CacheHandler
from crewai.agents.agent_builder.base_agent import BaseAgent
from crewai.agents.crew_agent_executor import CrewAgentExecutor
from crewai.cli.constants import ENV_VARS, LITELLM_PARAMS
from crewai.knowledge.knowledge import Knowledge
from crewai.knowledge.source.base_knowledge_source import BaseKnowledgeSource
from crewai.knowledge.utils.knowledge_utils import extract_knowledge_context
@@ -262,7 +260,7 @@ class Agent(BaseAgent):
}
)["output"]
except Exception as e:
if e.__class__.__module__.startswith("litellm.exceptions"):
if isinstance(e, BaseLLMException):
# Do not retry on litellm errors
raise e
self._times_executed += 1

View File

@@ -4,6 +4,7 @@ from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Union
from litellm.exceptions import AuthenticationError as LiteLLMAuthenticationError
from litellm.llms.base_llm.chat.transformation import BaseLLMException
from crewai.agents.agent_builder.base_agent import BaseAgent
from crewai.agents.agent_builder.base_agent_executor_mixin import CrewAgentExecutorMixin
@@ -142,10 +143,10 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
self._invoke_step_callback(formatted_answer)
self._append_message(formatted_answer.text, role="assistant")
except OutputParserException as e:
formatted_answer = self._handle_output_parser_exception(e)
except Exception as e:
if isinstance(e, BaseLLMException):
# Stop execution on litellm errors
raise e
if self._is_context_length_exceeded(e):
self._handle_context_length()
continue