[docs]classResponseParsingError(Exception):"""The exception class for response parsing error with uncertain reasons."""raw_response:str"""Record the raw response."""def__init__(self,message:str,raw_response:str=None)->None:"""Initialize the exception with the message."""self.message=messageself.raw_response=raw_responsedef__str__(self)->str:returnf"{self.__class__.__name__}: {self.message}"
[docs]classJsonParsingError(ResponseParsingError):"""The exception class for JSON parsing error."""
[docs]classJsonDictValidationError(ResponseParsingError):"""The exception class for JSON dict validation error."""
[docs]classJsonTypeError(ResponseParsingError):"""The exception class for JSON type error."""
[docs]classRequiredFieldNotFoundError(ResponseParsingError):"""The exception class for missing required field in model response, when the response is required to be a JSON dict object with required fields."""
[docs]classTagNotFoundError(ResponseParsingError):"""The exception class for missing tagged content in model response."""missing_begin_tag:bool"""If the response misses the begin tag."""missing_end_tag:bool"""If the response misses the end tag."""def__init__(self,message:str,raw_response:str=None,missing_begin_tag:bool=True,missing_end_tag:bool=True,):"""Initialize the exception with the message. Args: raw_response (`str`): Record the raw response from the model. missing_begin_tag (`bool`, defaults to `True`): If the response misses the beginning tag, default to `True`. missing_end_tag (`bool`, defaults to `True`): If the response misses the end tag, default to `True`. """super().__init__(message,raw_response)self.missing_begin_tag=missing_begin_tagself.missing_end_tag=missing_end_tag
# - Function Calling Exceptions
[docs]classFunctionCallError(Exception):"""The base class for exception raising during calling functions."""def__init__(self,message:str)->None:self.message=messagedef__str__(self)->str:returnf"{self.__class__.__name__}: {self.message}"
[docs]classFunctionCallFormatError(FunctionCallError):"""The exception class for function calling format error."""
[docs]classFunctionNotFoundError(FunctionCallError):"""The exception class for function not found error."""
[docs]classArgumentNotFoundError(FunctionCallError):"""The exception class for missing argument error."""
[docs]classArgumentTypeError(FunctionCallError):"""The exception class for argument type error."""
# - AgentScope Studio Exceptions
[docs]classStudioError(Exception):"""The base class for exception raising during interaction with agentscope studio."""def__init__(self,message:str)->None:self.message=messagedef__str__(self)->str:returnf"{self.__class__.__name__}: {self.message}"
[docs]classStudioRegisterError(StudioError):"""The exception class for error when registering to agentscope studio."""
# - Agent Server Exceptions
[docs]classAgentServerError(Exception):"""The exception class for agent server related errors."""host:str"""Hostname of the server."""port:int"""Port of the server."""message:str"""Error message"""def__init__(self,host:str,port:int,message:str=None,)->None:"""Initialize the exception with the message."""self.host=hostself.port=portself.message=messagedef__str__(self)->str:err_msg=f"{self.__class__.__name__}[{self.host}:{self.port}]"ifself.messageisnotNone:err_msg+=f": {self.message}"returnerr_msg
[docs]classAgentServerNotAliveError(AgentServerError):"""The exception class for agent server not alive error."""
[docs]classAgentCreationError(AgentServerError):"""The exception class for failing to create agent."""
[docs]classAgentCallError(AgentServerError):"""The exception class for failing to call agent."""
[docs]classAgentServerUnsupportedMethodError(AgentServerError):"""The exception class for agent server not supporting certain method."""def__init__(self,host:str,port:int,oid:str,func_name:str)->None:super().__init__(host,port,f"Object[{oid}] does not support method[{func_name}]",)
# - Monitor related Exceptions
[docs]classQuotaExceededError(Exception):"""An Exception used to indicate that a certain metric exceeds quota"""def__init__(self,name:str,)->None:"""Init a QuotaExceedError instance. Args: name (`str`): name of the metric which exceeds quota. """self.message=f"Metric [{name}] exceeds quota."self.name=namesuper().__init__(self.message)
# - Environment Exceptions
[docs]classEnvError(Exception):"""The exception class for env related errors."""def__init__(self,message:str)->None:self.message=messagedef__str__(self)->str:returnf"{self.__class__.__name__}: {self.message}"
[docs]classEnvNotFoundError(EnvError):"""The exception class for env not found error."""def__init__(self,name:str)->None:super().__init__(f"Env {name} not found.")
[docs]classEnvAlreadyExistError(EnvError):"""The exception class for env already exist error."""def__init__(self,name:str)->None:super().__init__(f"Env {name} already exist.")
[docs]classEnvUnsupportedFunctionError(EnvError):"""The exception class for use unsupported function of env error."""def__init__(self,env_name:str,func_name:str)->None:super().__init__(f"Env {env_name} doesn't have {func_name}.")
[docs]classEnvTypeError(EnvError):"""The exception class for use wrong type of env error."""def__init__(self,env_name:str,type_name:str)->None:super().__init__(f"Env {env_name} is not an instance of [{type_name}]",)
[docs]classEnvListenerError(Exception):"""The exception class for listener related errors."""def__init__(self,message:str)->None:self.message=messagedef__str__(self)->str:returnf"{self.__class__.__name__}: {self.message}"