exceptions.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. class AgentNoInstructionError(Exception):
  2. def __init__(self, message='Instruction must be provided'):
  3. super().__init__(message)
  4. class AgentEventTypeError(Exception):
  5. def __init__(self, message='Event must be a dictionary'):
  6. super().__init__(message)
  7. class AgentAlreadyRegisteredError(Exception):
  8. def __init__(self, name=None):
  9. if name is not None:
  10. message = f"Agent class already registered under '{name}'"
  11. else:
  12. message = 'Agent class already registered'
  13. super().__init__(message)
  14. class AgentNotRegisteredError(Exception):
  15. def __init__(self, name=None):
  16. if name is not None:
  17. message = f"No agent class registered under '{name}'"
  18. else:
  19. message = 'No agent class registered'
  20. super().__init__(message)
  21. class TaskInvalidStateError(Exception):
  22. def __init__(self, state=None):
  23. if state is not None:
  24. message = f'Invalid state {state}'
  25. else:
  26. message = 'Invalid state'
  27. super().__init__(message)
  28. class BrowserInitException(Exception):
  29. def __init__(self, message='Failed to initialize browser environment'):
  30. super().__init__(message)
  31. class BrowserUnavailableException(Exception):
  32. def __init__(
  33. self,
  34. message='Browser environment is not available, please check if has been initialized',
  35. ):
  36. super().__init__(message)
  37. # This exception gets sent back to the LLM
  38. # It might be malformed JSON
  39. class LLMMalformedActionError(Exception):
  40. def __init__(self, message='Malformed response'):
  41. self.message = message
  42. super().__init__(message)
  43. def __str__(self):
  44. return self.message
  45. # This exception gets sent back to the LLM
  46. # For some reason, the agent did not return an action
  47. class LLMNoActionError(Exception):
  48. def __init__(self, message='Agent must return an action'):
  49. super().__init__(message)
  50. # This exception gets sent back to the LLM
  51. # The LLM output did not include an action, or the action was not the expected type
  52. class LLMResponseError(Exception):
  53. def __init__(self, message='Failed to retrieve action from LLM response'):
  54. super().__init__(message)
  55. class UserCancelledError(Exception):
  56. def __init__(self, message='User cancelled the request'):
  57. super().__init__(message)
  58. class MicroAgentValidationError(Exception):
  59. def __init__(self, message='Micro agent validation failed'):
  60. super().__init__(message)
  61. class OperationCancelled(Exception):
  62. """Exception raised when an operation is cancelled (e.g. by a keyboard interrupt)."""
  63. def __init__(self, message='Operation was cancelled'):
  64. super().__init__(message)
  65. class CloudFlareBlockageError(Exception):
  66. """Exception raised when a request is blocked by CloudFlare."""
  67. pass
  68. class FunctionCallConversionError(Exception):
  69. """Exception raised when FunctionCallingConverter failed to convert a non-function call message to a function call message.
  70. This typically happens when there's a malformed message (e.g., missing <function=...> tags). But not due to LLM output.
  71. """
  72. def __init__(self, message):
  73. super().__init__(message)
  74. class FunctionCallValidationError(Exception):
  75. """Exception raised when FunctionCallingConverter failed to validate a function call message.
  76. This typically happens when the LLM outputs unrecognized function call / parameter names / values.
  77. """
  78. def __init__(self, message):
  79. super().__init__(message)
  80. class FunctionCallNotExistsError(Exception):
  81. """Exception raised when an LLM call a tool that is not registered."""
  82. def __init__(self, message):
  83. super().__init__(message)