-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
139 lines (98 loc) · 3.93 KB
/
Copy pathexceptions.py
File metadata and controls
139 lines (98 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""
exceptions.py — Пользовательские исключения для агента.
"""
class AgentException(Exception):
"""Базовое исключение агента."""
def __init__(self, message: str, details: dict = None):
super().__init__(message)
self.message = message
self.details = details or {}
def __str__(self):
if self.details:
return f"{self.message} | Детали: {self.details}"
return self.message
class ModelError(AgentException):
"""Ошибка загрузки или работы модели."""
pass
class ModelNotLoadedError(ModelError):
"""Модель не загружена."""
pass
class ModelInferenceError(ModelError):
"""Ошибка инференса."""
pass
class SafetyError(AgentException):
"""Ошибка безопасности."""
pass
class DangerousCommandError(SafetyError):
"""Обнаружена опасная команда."""
def __init__(self, command: str, pattern: str):
super().__init__(
f"Обнаружена опасная команда: {command}",
{"command": command, "pattern": pattern}
)
class ConfirmationRequiredError(SafetyError):
"""Требуется подтверждение пользователя."""
def __init__(self, command: str, reason: str):
super().__init__(
f"Требуется подтверждение: {reason}",
{"command": command, "reason": reason}
)
class ToolError(AgentException):
"""Ошибка инструмента."""
pass
class ToolNotFoundError(ToolError):
"""Инструмент не найден."""
pass
class ToolExecutionError(ToolError):
"""Ошибка выполнения инструмента."""
def __init__(self, tool_name: str, error: str, command: str = None):
details = {"tool": tool_name, "error": error}
if command:
details["command"] = command
super().__init__(f"Ошибка инструмента {tool_name}: {error}", details)
class ToolTimeoutError(ToolError):
"""Таймаут инструмента."""
def __init__(self, tool_name: str, timeout: int):
super().__init__(
f"Инструмент {tool_name} превысил таймаут {timeout}с",
{"tool": tool_name, "timeout": timeout}
)
class MemoryError(AgentException):
"""Ошибка памяти."""
pass
class MemoryStorageError(MemoryError):
"""Ошибка сохранения в память."""
pass
class MemoryRetrievalError(MemoryError):
"""Ошибка извлечения из памяти."""
pass
class WebError(AgentException):
"""Ошибка веб-инструментов."""
pass
class WebRequestError(WebError):
"""Ошибка HTTP-запроса."""
def __init__(self, url: str, status_code: int = None, error: str = None):
super().__init__(
f"Ошибка запроса к {url}",
{"url": url, "status_code": status_code, "error": error}
)
class WebParseError(WebError):
"""Ошибка парсинга веб-страницы."""
pass
class ConfigurationError(AgentException):
"""Ошибка конфигурации."""
pass
class StepLimitExceededError(AgentException):
"""Превышен лимит шагов."""
def __init__(self, max_steps: int):
super().__init__(
f"Превышен лимит шагов ({max_steps})",
{"max_steps": max_steps}
)
class RetryLimitExceededError(AgentException):
"""Превышен лимит повторных попыток."""
def __init__(self, max_retries: int):
super().__init__(
f"Превышен лимит повторных попыток ({max_retries})",
{"max_retries": max_retries}
)