exceptions.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 LLMOutputError(Exception):
  29. def __init__(self, message):
  30. super().__init__(message)
  31. class SandboxInvalidBackgroundCommandError(Exception):
  32. def __init__(self, id=None):
  33. if id is not None:
  34. message = f'Invalid background command id {id}'
  35. else:
  36. message = 'Invalid background command id'
  37. super().__init__(message)
  38. class TaskInvalidStateError(Exception):
  39. def __init__(self, state=None):
  40. if state is not None:
  41. message = f'Invalid state {state}'
  42. else:
  43. message = 'Invalid state'
  44. super().__init__(message)
  45. class BrowserInitException(Exception):
  46. def __init__(self, message='Failed to initialize browser environment'):
  47. super().__init__(message)
  48. class BrowserUnavailableException(Exception):
  49. def __init__(
  50. self,
  51. message='Browser environment is not available, please check if has been initialized',
  52. ):
  53. super().__init__(message)
  54. # These exceptions get sent back to the LLM
  55. class AgentMalformedActionError(Exception):
  56. def __init__(self, message='Malformed response'):
  57. super().__init__(message)
  58. class AgentNoActionError(Exception):
  59. def __init__(self, message='Agent must return an action'):
  60. super().__init__(message)