exceptions.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. super().__init__(message)
  42. # This exception gets sent back to the LLM
  43. # For some reason, the agent did not return an action
  44. class LLMNoActionError(Exception):
  45. def __init__(self, message='Agent must return an action'):
  46. super().__init__(message)
  47. # This exception gets sent back to the LLM
  48. # The LLM output did not include an action, or the action was not the expected type
  49. class LLMResponseError(Exception):
  50. def __init__(self, message='Failed to retrieve action from LLM response'):
  51. super().__init__(message)
  52. class UserCancelledError(Exception):
  53. def __init__(self, message='User cancelled the request'):
  54. super().__init__(message)