Update agent.py

pull/1084/head
CI-DEV 3 weeks ago committed by GitHub
parent 0e14f51930
commit 7b7d3e3cb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -28,6 +28,7 @@ from litellm.utils import (
supports_parallel_function_calling, supports_parallel_function_calling,
supports_vision, supports_vision,
) )
from litellm.exceptions import BadRequestError, InternalServerError, AuthenticationError
from loguru import logger from loguru import logger
from pydantic import BaseModel from pydantic import BaseModel
@ -747,8 +748,11 @@ class Agent:
if self.model_name is None: if self.model_name is None:
self.model_name = "gpt-4o-mini" self.model_name = "gpt-4o-mini"
# Use current model (which may be a fallback) # Use current model (which may be a fallback) only if fallbacks are configured
if self.fallback_models:
current_model = self.get_current_model() current_model = self.get_current_model()
else:
current_model = self.model_name
# Determine if parallel tool calls should be enabled # Determine if parallel tool calls should be enabled
if exists(self.tools) and len(self.tools) >= 2: if exists(self.tools) and len(self.tools) >= 2:
@ -763,7 +767,7 @@ class Agent:
try: try:
# Base configuration that's always included # Base configuration that's always included
common_args = { common_args = {
"model_name": self.model_name, "model_name": current_model,
"temperature": self.temperature, "temperature": self.temperature,
"max_tokens": self.max_tokens, "max_tokens": self.max_tokens,
"system_prompt": self.system_prompt, "system_prompt": self.system_prompt,
@ -1299,7 +1303,7 @@ class Agent:
success = True # Mark as successful to exit the retry loop success = True # Mark as successful to exit the retry loop
except Exception as e: except (BadRequestError, InternalServerError, AuthenticationError, Exception) as e:
if self.autosave is True: if self.autosave is True:
log_agent_data(self.to_dict()) log_agent_data(self.to_dict())
@ -2572,7 +2576,7 @@ class Agent:
return out return out
except (AgentLLMError, Exception) as e: except (AgentLLMError, BadRequestError, InternalServerError, AuthenticationError, Exception) as e:
logger.error( logger.error(
f"Error calling LLM with model '{self.get_current_model()}': {e}. " f"Error calling LLM with model '{self.get_current_model()}': {e}. "
f"Task: {task}, Args: {args}, Kwargs: {kwargs} Traceback: {traceback.format_exc()}" f"Task: {task}, Args: {args}, Kwargs: {kwargs} Traceback: {traceback.format_exc()}"
@ -2654,7 +2658,7 @@ class Agent:
return output return output
except (AgentRunError, AgentLLMError, Exception) as e: except (AgentRunError, AgentLLMError, BadRequestError, InternalServerError, AuthenticationError, Exception) as e:
# Try fallback models if available # Try fallback models if available
if self.is_fallback_available() and self.switch_to_next_model(): if self.is_fallback_available() and self.switch_to_next_model():
logger.info( logger.info(

Loading…
Cancel
Save