exceptions.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 SandboxInvalidBackgroundCommandError(Exception):
  22. def __init__(self, id=None):
  23. if id is not None:
  24. message = f'Invalid background command id {id}'
  25. else:
  26. message = 'Invalid background command id'
  27. super().__init__(message)
  28. class TaskInvalidStateError(Exception):
  29. def __init__(self, state=None):
  30. if state is not None:
  31. message = f'Invalid state {state}'
  32. else:
  33. message = 'Invalid state'
  34. super().__init__(message)
  35. class BrowserInitException(Exception):
  36. def __init__(self, message='Failed to initialize browser environment'):
  37. super().__init__(message)
  38. class BrowserUnavailableException(Exception):
  39. def __init__(
  40. self,
  41. message='Browser environment is not available, please check if has been initialized',
  42. ):
  43. super().__init__(message)
  44. # This exception gets sent back to the LLM
  45. # It might be malformed JSON
  46. class LLMMalformedActionError(Exception):
  47. def __init__(self, message='Malformed response'):
  48. super().__init__(message)
  49. # This exception gets sent back to the LLM
  50. # For some reason, the agent did not return an action
  51. class LLMNoActionError(Exception):
  52. def __init__(self, message='Agent must return an action'):
  53. super().__init__(message)
  54. # This exception gets sent back to the LLM
  55. # The LLM output did not include an action, or the action was not the expected type
  56. class LLMResponseError(Exception):
  57. def __init__(self, message='Failed to retrieve action from LLM response'):
  58. super().__init__(message)