exceptions.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. # These exceptions get sent back to the LLM
  46. class AgentMalformedActionError(Exception):
  47. def __init__(self, message='Malformed response'):
  48. super().__init__(message)
  49. class AgentNoActionError(Exception):
  50. def __init__(self, message='Agent must return an action'):
  51. super().__init__(message)