exc.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from typing import Optional
  2. class AgentNodeError(Exception):
  3. """Base exception for all agent node errors."""
  4. def __init__(self, message: str):
  5. self.message = message
  6. super().__init__(self.message)
  7. class AgentStrategyError(AgentNodeError):
  8. """Exception raised when there's an error with the agent strategy."""
  9. def __init__(self, message: str, strategy_name: Optional[str] = None, provider_name: Optional[str] = None):
  10. self.strategy_name = strategy_name
  11. self.provider_name = provider_name
  12. super().__init__(message)
  13. class AgentStrategyNotFoundError(AgentStrategyError):
  14. """Exception raised when the specified agent strategy is not found."""
  15. def __init__(self, strategy_name: str, provider_name: Optional[str] = None):
  16. super().__init__(
  17. f"Agent strategy '{strategy_name}' not found"
  18. + (f" for provider '{provider_name}'" if provider_name else ""),
  19. strategy_name,
  20. provider_name,
  21. )
  22. class AgentInvocationError(AgentNodeError):
  23. """Exception raised when there's an error invoking the agent."""
  24. def __init__(self, message: str, original_error: Optional[Exception] = None):
  25. self.original_error = original_error
  26. super().__init__(message)
  27. class AgentParameterError(AgentNodeError):
  28. """Exception raised when there's an error with agent parameters."""
  29. def __init__(self, message: str, parameter_name: Optional[str] = None):
  30. self.parameter_name = parameter_name
  31. super().__init__(message)
  32. class AgentVariableError(AgentNodeError):
  33. """Exception raised when there's an error with variables in the agent node."""
  34. def __init__(self, message: str, variable_name: Optional[str] = None):
  35. self.variable_name = variable_name
  36. super().__init__(message)
  37. class AgentVariableNotFoundError(AgentVariableError):
  38. """Exception raised when a variable is not found in the variable pool."""
  39. def __init__(self, variable_name: str):
  40. super().__init__(f"Variable '{variable_name}' does not exist", variable_name)
  41. class AgentInputTypeError(AgentNodeError):
  42. """Exception raised when an unknown agent input type is encountered."""
  43. def __init__(self, input_type: str):
  44. super().__init__(f"Unknown agent input type '{input_type}'")
  45. class ToolFileError(AgentNodeError):
  46. """Exception raised when there's an error with a tool file."""
  47. def __init__(self, message: str, file_id: Optional[str] = None):
  48. self.file_id = file_id
  49. super().__init__(message)
  50. class ToolFileNotFoundError(ToolFileError):
  51. """Exception raised when a tool file is not found."""
  52. def __init__(self, file_id: str):
  53. super().__init__(f"Tool file '{file_id}' does not exist", file_id)
  54. class AgentMessageTransformError(AgentNodeError):
  55. """Exception raised when there's an error transforming agent messages."""
  56. def __init__(self, message: str, original_error: Optional[Exception] = None):
  57. self.original_error = original_error
  58. super().__init__(message)
  59. class AgentModelError(AgentNodeError):
  60. """Exception raised when there's an error with the model used by the agent."""
  61. def __init__(self, message: str, model_name: Optional[str] = None, provider: Optional[str] = None):
  62. self.model_name = model_name
  63. self.provider = provider
  64. super().__init__(message)
  65. class AgentMemoryError(AgentNodeError):
  66. """Exception raised when there's an error with the agent's memory."""
  67. def __init__(self, message: str, conversation_id: Optional[str] = None):
  68. self.conversation_id = conversation_id
  69. super().__init__(message)
  70. class AgentVariableTypeError(AgentNodeError):
  71. """Exception raised when a variable has an unexpected type."""
  72. def __init__(
  73. self,
  74. message: str,
  75. variable_name: Optional[str] = None,
  76. expected_type: Optional[str] = None,
  77. actual_type: Optional[str] = None,
  78. ):
  79. self.variable_name = variable_name
  80. self.expected_type = expected_type
  81. self.actual_type = actual_type
  82. super().__init__(message)