exceptions.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. class MaxCharsExceedError(Exception):
  2. def __init__(self, num_of_chars=None, max_chars_limit=None):
  3. if num_of_chars is not None and max_chars_limit is not None:
  4. message = f'Number of characters {num_of_chars} exceeds MAX_CHARS limit: {max_chars_limit}'
  5. else:
  6. message = 'Number of characters exceeds MAX_CHARS limit'
  7. super().__init__(message)
  8. class AgentNoInstructionError(Exception):
  9. def __init__(self, message='Instruction must be provided'):
  10. super().__init__(message)
  11. class AgentEventTypeError(Exception):
  12. def __init__(self, message='Event must be a dictionary'):
  13. super().__init__(message)
  14. class AgentAlreadyRegisteredError(Exception):
  15. def __init__(self, name=None):
  16. if name is not None:
  17. message = f"Agent class already registered under '{name}'"
  18. else:
  19. message = 'Agent class already registered'
  20. super().__init__(message)
  21. class AgentNotRegisteredError(Exception):
  22. def __init__(self, name=None):
  23. if name is not None:
  24. message = f"No agent class registered under '{name}'"
  25. else:
  26. message = 'No agent class registered'
  27. super().__init__(message)
  28. class SandboxInvalidBackgroundCommandError(Exception):
  29. def __init__(self, id=None):
  30. if id is not None:
  31. message = f'Invalid background command id {id}'
  32. else:
  33. message = 'Invalid background command id'
  34. super().__init__(message)
  35. class TaskInvalidStateError(Exception):
  36. def __init__(self, state=None):
  37. if state is not None:
  38. message = f'Invalid state {state}'
  39. else:
  40. message = 'Invalid state'
  41. super().__init__(message)
  42. class BrowserInitException(Exception):
  43. def __init__(self, message='Failed to initialize browser environment'):
  44. super().__init__(message)
  45. class BrowserUnavailableException(Exception):
  46. def __init__(
  47. self,
  48. message='Browser environment is not available, please check if has been initialized',
  49. ):
  50. super().__init__(message)
  51. # This exception gets sent back to the LLM
  52. # It might be malformed JSON
  53. class LLMMalformedActionError(Exception):
  54. def __init__(self, message='Malformed response'):
  55. super().__init__(message)
  56. # This exception gets sent back to the LLM
  57. # For some reason, the agent did not return an action
  58. class LLMNoActionError(Exception):
  59. def __init__(self, message='Agent must return an action'):
  60. super().__init__(message)
  61. # This exception gets sent back to the LLM
  62. # The LLM output did not include an action, or the action was not the expected type
  63. class LLMResponseError(Exception):
  64. def __init__(self, message='Failed to retrieve action from LLM response'):
  65. super().__init__(message)