pygeai-orchestration 0.1.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pygeai_orchestration/__init__.py +99 -0
- pygeai_orchestration/cli/__init__.py +7 -0
- pygeai_orchestration/cli/__main__.py +11 -0
- pygeai_orchestration/cli/commands/__init__.py +13 -0
- pygeai_orchestration/cli/commands/base.py +192 -0
- pygeai_orchestration/cli/error_handler.py +123 -0
- pygeai_orchestration/cli/formatters.py +419 -0
- pygeai_orchestration/cli/geai_orch.py +270 -0
- pygeai_orchestration/cli/interactive.py +265 -0
- pygeai_orchestration/cli/texts/help.py +169 -0
- pygeai_orchestration/core/__init__.py +130 -0
- pygeai_orchestration/core/base/__init__.py +23 -0
- pygeai_orchestration/core/base/agent.py +121 -0
- pygeai_orchestration/core/base/geai_agent.py +144 -0
- pygeai_orchestration/core/base/geai_orchestrator.py +77 -0
- pygeai_orchestration/core/base/orchestrator.py +142 -0
- pygeai_orchestration/core/base/pattern.py +161 -0
- pygeai_orchestration/core/base/tool.py +149 -0
- pygeai_orchestration/core/common/__init__.py +18 -0
- pygeai_orchestration/core/common/context.py +140 -0
- pygeai_orchestration/core/common/memory.py +176 -0
- pygeai_orchestration/core/common/message.py +50 -0
- pygeai_orchestration/core/common/state.py +181 -0
- pygeai_orchestration/core/composition.py +190 -0
- pygeai_orchestration/core/config.py +356 -0
- pygeai_orchestration/core/exceptions.py +400 -0
- pygeai_orchestration/core/handlers.py +380 -0
- pygeai_orchestration/core/utils/__init__.py +37 -0
- pygeai_orchestration/core/utils/cache.py +138 -0
- pygeai_orchestration/core/utils/config.py +94 -0
- pygeai_orchestration/core/utils/logging.py +57 -0
- pygeai_orchestration/core/utils/metrics.py +184 -0
- pygeai_orchestration/core/utils/validators.py +140 -0
- pygeai_orchestration/dev/__init__.py +15 -0
- pygeai_orchestration/dev/debug.py +288 -0
- pygeai_orchestration/dev/templates.py +321 -0
- pygeai_orchestration/dev/testing.py +301 -0
- pygeai_orchestration/patterns/__init__.py +15 -0
- pygeai_orchestration/patterns/multi_agent.py +237 -0
- pygeai_orchestration/patterns/planning.py +219 -0
- pygeai_orchestration/patterns/react.py +221 -0
- pygeai_orchestration/patterns/reflection.py +134 -0
- pygeai_orchestration/patterns/tool_use.py +170 -0
- pygeai_orchestration/tests/__init__.py +1 -0
- pygeai_orchestration/tests/test_base_classes.py +187 -0
- pygeai_orchestration/tests/test_cache.py +184 -0
- pygeai_orchestration/tests/test_cli_formatters.py +232 -0
- pygeai_orchestration/tests/test_common.py +214 -0
- pygeai_orchestration/tests/test_composition.py +265 -0
- pygeai_orchestration/tests/test_config.py +301 -0
- pygeai_orchestration/tests/test_dev_utils.py +337 -0
- pygeai_orchestration/tests/test_exceptions.py +327 -0
- pygeai_orchestration/tests/test_handlers.py +307 -0
- pygeai_orchestration/tests/test_metrics.py +171 -0
- pygeai_orchestration/tests/test_patterns.py +165 -0
- pygeai_orchestration-0.1.0b2.dist-info/METADATA +290 -0
- pygeai_orchestration-0.1.0b2.dist-info/RECORD +61 -0
- pygeai_orchestration-0.1.0b2.dist-info/WHEEL +5 -0
- pygeai_orchestration-0.1.0b2.dist-info/entry_points.txt +2 -0
- pygeai_orchestration-0.1.0b2.dist-info/licenses/LICENSE +8 -0
- pygeai_orchestration-0.1.0b2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom exceptions for pygeai-orchestration.
|
|
3
|
+
|
|
4
|
+
This module defines the exception hierarchy for the orchestration package,
|
|
5
|
+
providing specific error types for different failure scenarios.
|
|
6
|
+
|
|
7
|
+
Exception Hierarchy:
|
|
8
|
+
- OrchestrationError (base)
|
|
9
|
+
- PatternExecutionError
|
|
10
|
+
- PatternConfigurationError
|
|
11
|
+
- AgentError
|
|
12
|
+
- ToolExecutionError
|
|
13
|
+
- StateError
|
|
14
|
+
- ValidationError
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from typing import Any, Dict, Optional
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class OrchestrationError(Exception):
|
|
21
|
+
"""
|
|
22
|
+
Base class for all pygeai-orchestration exceptions.
|
|
23
|
+
|
|
24
|
+
All custom exceptions in this package inherit from this base class,
|
|
25
|
+
allowing for catching all orchestration-related errors with a single
|
|
26
|
+
except clause.
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
>>> try:
|
|
30
|
+
... pattern.execute(task)
|
|
31
|
+
... except OrchestrationError as e:
|
|
32
|
+
... logger.error(f"Orchestration failed: {e}")
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class PatternExecutionError(OrchestrationError):
|
|
39
|
+
"""
|
|
40
|
+
Raised when a pattern fails during execution.
|
|
41
|
+
|
|
42
|
+
This exception is raised when a pattern encounters an error during
|
|
43
|
+
its execution phase, such as agent failures, iteration limits exceeded,
|
|
44
|
+
or unexpected runtime errors.
|
|
45
|
+
|
|
46
|
+
:param message: str - The error message.
|
|
47
|
+
:param pattern_name: Optional[str] - Name of the pattern that failed.
|
|
48
|
+
:param iteration: Optional[int] - Iteration number where failure occurred.
|
|
49
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
>>> raise PatternExecutionError(
|
|
53
|
+
... "Reflection pattern failed to converge",
|
|
54
|
+
... pattern_name="reflection",
|
|
55
|
+
... iteration=5,
|
|
56
|
+
... details={"max_iterations": 3}
|
|
57
|
+
... )
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def __init__(
|
|
61
|
+
self,
|
|
62
|
+
message: str,
|
|
63
|
+
pattern_name: Optional[str] = None,
|
|
64
|
+
iteration: Optional[int] = None,
|
|
65
|
+
details: Optional[Dict[str, Any]] = None,
|
|
66
|
+
):
|
|
67
|
+
"""
|
|
68
|
+
Initialize a PatternExecutionError with detailed context.
|
|
69
|
+
|
|
70
|
+
:param message: str - The main error message.
|
|
71
|
+
:param pattern_name: Optional[str] - Name of the pattern that failed.
|
|
72
|
+
:param iteration: Optional[int] - Iteration number where failure occurred.
|
|
73
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
74
|
+
"""
|
|
75
|
+
super().__init__(message)
|
|
76
|
+
self.pattern_name = pattern_name
|
|
77
|
+
self.iteration = iteration
|
|
78
|
+
self.details = details or {}
|
|
79
|
+
|
|
80
|
+
def __str__(self) -> str:
|
|
81
|
+
"""
|
|
82
|
+
Format the error message with all available context.
|
|
83
|
+
|
|
84
|
+
:return: str - Formatted error message with pattern details.
|
|
85
|
+
"""
|
|
86
|
+
parts = [super().__str__()]
|
|
87
|
+
|
|
88
|
+
if self.pattern_name:
|
|
89
|
+
parts.append(f" Pattern: {self.pattern_name}")
|
|
90
|
+
if self.iteration is not None:
|
|
91
|
+
parts.append(f" Iteration: {self.iteration}")
|
|
92
|
+
if self.details:
|
|
93
|
+
parts.append(f" Details: {self.details}")
|
|
94
|
+
|
|
95
|
+
return "\n".join(parts)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class PatternConfigurationError(OrchestrationError):
|
|
99
|
+
"""
|
|
100
|
+
Raised when a pattern is incorrectly configured.
|
|
101
|
+
|
|
102
|
+
This exception is raised during pattern initialization or setup when
|
|
103
|
+
the provided configuration is invalid, incomplete, or incompatible.
|
|
104
|
+
|
|
105
|
+
:param message: str - The error message.
|
|
106
|
+
:param config_field: Optional[str] - The configuration field that is invalid.
|
|
107
|
+
:param expected: Optional[str] - Description of expected value.
|
|
108
|
+
:param received: Optional[Any] - The actual value received.
|
|
109
|
+
|
|
110
|
+
Example:
|
|
111
|
+
>>> raise PatternConfigurationError(
|
|
112
|
+
... "Invalid max_iterations value",
|
|
113
|
+
... config_field="max_iterations",
|
|
114
|
+
... expected="positive integer",
|
|
115
|
+
... received=-1
|
|
116
|
+
... )
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
def __init__(
|
|
120
|
+
self,
|
|
121
|
+
message: str,
|
|
122
|
+
config_field: Optional[str] = None,
|
|
123
|
+
expected: Optional[str] = None,
|
|
124
|
+
received: Optional[Any] = None,
|
|
125
|
+
):
|
|
126
|
+
"""
|
|
127
|
+
Initialize a PatternConfigurationError with validation details.
|
|
128
|
+
|
|
129
|
+
:param message: str - The main error message.
|
|
130
|
+
:param config_field: Optional[str] - The configuration field that is invalid.
|
|
131
|
+
:param expected: Optional[str] - Description of expected value.
|
|
132
|
+
:param received: Optional[Any] - The actual value received.
|
|
133
|
+
"""
|
|
134
|
+
super().__init__(message)
|
|
135
|
+
self.config_field = config_field
|
|
136
|
+
self.expected = expected
|
|
137
|
+
self.received = received
|
|
138
|
+
|
|
139
|
+
def __str__(self) -> str:
|
|
140
|
+
"""
|
|
141
|
+
Format the error message with configuration context.
|
|
142
|
+
|
|
143
|
+
:return: str - Formatted error message with config details.
|
|
144
|
+
"""
|
|
145
|
+
parts = [super().__str__()]
|
|
146
|
+
|
|
147
|
+
if self.config_field:
|
|
148
|
+
parts.append(f" Field: {self.config_field}")
|
|
149
|
+
if self.expected:
|
|
150
|
+
parts.append(f" Expected: {self.expected}")
|
|
151
|
+
if self.received is not None:
|
|
152
|
+
parts.append(f" Received: {self.received}")
|
|
153
|
+
|
|
154
|
+
return "\n".join(parts)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class AgentError(OrchestrationError):
|
|
158
|
+
"""
|
|
159
|
+
Raised when an agent operation fails.
|
|
160
|
+
|
|
161
|
+
This exception is raised when agent initialization, execution, or
|
|
162
|
+
communication fails. It can wrap underlying errors from the agent
|
|
163
|
+
implementation.
|
|
164
|
+
|
|
165
|
+
:param message: str - The error message.
|
|
166
|
+
:param agent_name: Optional[str] - Name of the agent that failed.
|
|
167
|
+
:param operation: Optional[str] - The operation that failed (e.g., "generate", "execute").
|
|
168
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
169
|
+
|
|
170
|
+
Example:
|
|
171
|
+
>>> raise AgentError(
|
|
172
|
+
... "Agent failed to generate response",
|
|
173
|
+
... agent_name="research-agent",
|
|
174
|
+
... operation="generate",
|
|
175
|
+
... details={"timeout": True}
|
|
176
|
+
... )
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
def __init__(
|
|
180
|
+
self,
|
|
181
|
+
message: str,
|
|
182
|
+
agent_name: Optional[str] = None,
|
|
183
|
+
operation: Optional[str] = None,
|
|
184
|
+
details: Optional[Dict[str, Any]] = None,
|
|
185
|
+
):
|
|
186
|
+
"""
|
|
187
|
+
Initialize an AgentError with operation context.
|
|
188
|
+
|
|
189
|
+
:param message: str - The main error message.
|
|
190
|
+
:param agent_name: Optional[str] - Name of the agent that failed.
|
|
191
|
+
:param operation: Optional[str] - The operation that failed.
|
|
192
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
193
|
+
"""
|
|
194
|
+
super().__init__(message)
|
|
195
|
+
self.agent_name = agent_name
|
|
196
|
+
self.operation = operation
|
|
197
|
+
self.details = details or {}
|
|
198
|
+
|
|
199
|
+
def __str__(self) -> str:
|
|
200
|
+
"""
|
|
201
|
+
Format the error message with agent context.
|
|
202
|
+
|
|
203
|
+
:return: str - Formatted error message with agent details.
|
|
204
|
+
"""
|
|
205
|
+
parts = [super().__str__()]
|
|
206
|
+
|
|
207
|
+
if self.agent_name:
|
|
208
|
+
parts.append(f" Agent: {self.agent_name}")
|
|
209
|
+
if self.operation:
|
|
210
|
+
parts.append(f" Operation: {self.operation}")
|
|
211
|
+
if self.details:
|
|
212
|
+
parts.append(f" Details: {self.details}")
|
|
213
|
+
|
|
214
|
+
return "\n".join(parts)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class ToolExecutionError(OrchestrationError):
|
|
218
|
+
"""
|
|
219
|
+
Raised when a tool fails during execution.
|
|
220
|
+
|
|
221
|
+
This exception is raised when a tool encounters an error while
|
|
222
|
+
executing its operation, such as invalid inputs, external API
|
|
223
|
+
failures, or resource unavailability.
|
|
224
|
+
|
|
225
|
+
:param message: str - The error message.
|
|
226
|
+
:param tool_name: Optional[str] - Name of the tool that failed.
|
|
227
|
+
:param input_data: Optional[Dict[str, Any]] - The input that caused the failure.
|
|
228
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
229
|
+
|
|
230
|
+
Example:
|
|
231
|
+
>>> raise ToolExecutionError(
|
|
232
|
+
... "Calculator tool received invalid expression",
|
|
233
|
+
... tool_name="calculator",
|
|
234
|
+
... input_data={"expression": "2 + + 2"},
|
|
235
|
+
... details={"error": "SyntaxError"}
|
|
236
|
+
... )
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
def __init__(
|
|
240
|
+
self,
|
|
241
|
+
message: str,
|
|
242
|
+
tool_name: Optional[str] = None,
|
|
243
|
+
input_data: Optional[Dict[str, Any]] = None,
|
|
244
|
+
details: Optional[Dict[str, Any]] = None,
|
|
245
|
+
):
|
|
246
|
+
"""
|
|
247
|
+
Initialize a ToolExecutionError with execution context.
|
|
248
|
+
|
|
249
|
+
:param message: str - The main error message.
|
|
250
|
+
:param tool_name: Optional[str] - Name of the tool that failed.
|
|
251
|
+
:param input_data: Optional[Dict[str, Any]] - The input that caused the failure.
|
|
252
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
253
|
+
"""
|
|
254
|
+
super().__init__(message)
|
|
255
|
+
self.tool_name = tool_name
|
|
256
|
+
self.input_data = input_data or {}
|
|
257
|
+
self.details = details or {}
|
|
258
|
+
|
|
259
|
+
def __str__(self) -> str:
|
|
260
|
+
"""
|
|
261
|
+
Format the error message with tool context.
|
|
262
|
+
|
|
263
|
+
:return: str - Formatted error message with tool details.
|
|
264
|
+
"""
|
|
265
|
+
parts = [super().__str__()]
|
|
266
|
+
|
|
267
|
+
if self.tool_name:
|
|
268
|
+
parts.append(f" Tool: {self.tool_name}")
|
|
269
|
+
if self.input_data:
|
|
270
|
+
parts.append(f" Input: {self.input_data}")
|
|
271
|
+
if self.details:
|
|
272
|
+
parts.append(f" Details: {self.details}")
|
|
273
|
+
|
|
274
|
+
return "\n".join(parts)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class StateError(OrchestrationError):
|
|
278
|
+
"""
|
|
279
|
+
Raised when state management operations fail.
|
|
280
|
+
|
|
281
|
+
This exception is raised when there are errors in state initialization,
|
|
282
|
+
updates, transitions, or persistence operations.
|
|
283
|
+
|
|
284
|
+
:param message: str - The error message.
|
|
285
|
+
:param current_state: Optional[str] - The current state when error occurred.
|
|
286
|
+
:param attempted_state: Optional[str] - The state that was being set.
|
|
287
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
288
|
+
|
|
289
|
+
Example:
|
|
290
|
+
>>> raise StateError(
|
|
291
|
+
... "Invalid state transition",
|
|
292
|
+
... current_state="running",
|
|
293
|
+
... attempted_state="completed",
|
|
294
|
+
... details={"reason": "Cannot transition while tasks pending"}
|
|
295
|
+
... )
|
|
296
|
+
"""
|
|
297
|
+
|
|
298
|
+
def __init__(
|
|
299
|
+
self,
|
|
300
|
+
message: str,
|
|
301
|
+
current_state: Optional[str] = None,
|
|
302
|
+
attempted_state: Optional[str] = None,
|
|
303
|
+
details: Optional[Dict[str, Any]] = None,
|
|
304
|
+
):
|
|
305
|
+
"""
|
|
306
|
+
Initialize a StateError with state context.
|
|
307
|
+
|
|
308
|
+
:param message: str - The main error message.
|
|
309
|
+
:param current_state: Optional[str] - The current state when error occurred.
|
|
310
|
+
:param attempted_state: Optional[str] - The state that was being set.
|
|
311
|
+
:param details: Optional[Dict[str, Any]] - Additional error context.
|
|
312
|
+
"""
|
|
313
|
+
super().__init__(message)
|
|
314
|
+
self.current_state = current_state
|
|
315
|
+
self.attempted_state = attempted_state
|
|
316
|
+
self.details = details or {}
|
|
317
|
+
|
|
318
|
+
def __str__(self) -> str:
|
|
319
|
+
"""
|
|
320
|
+
Format the error message with state context.
|
|
321
|
+
|
|
322
|
+
:return: str - Formatted error message with state details.
|
|
323
|
+
"""
|
|
324
|
+
parts = [super().__str__()]
|
|
325
|
+
|
|
326
|
+
if self.current_state:
|
|
327
|
+
parts.append(f" Current State: {self.current_state}")
|
|
328
|
+
if self.attempted_state:
|
|
329
|
+
parts.append(f" Attempted State: {self.attempted_state}")
|
|
330
|
+
if self.details:
|
|
331
|
+
parts.append(f" Details: {self.details}")
|
|
332
|
+
|
|
333
|
+
return "\n".join(parts)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
class ValidationError(OrchestrationError):
|
|
337
|
+
"""
|
|
338
|
+
Raised when input validation fails.
|
|
339
|
+
|
|
340
|
+
This exception is raised when user inputs, configuration values, or
|
|
341
|
+
data structures fail validation checks. Provides detailed information
|
|
342
|
+
about what was expected versus what was received.
|
|
343
|
+
|
|
344
|
+
:param message: str - The error message.
|
|
345
|
+
:param field: Optional[str] - Name of the field that failed validation.
|
|
346
|
+
:param expected: Optional[str] - Description of what was expected.
|
|
347
|
+
:param received: Optional[Any] - Description of what was received.
|
|
348
|
+
:param example: Optional[str] - Example of valid input.
|
|
349
|
+
|
|
350
|
+
Example:
|
|
351
|
+
>>> raise ValidationError(
|
|
352
|
+
... "Invalid task input",
|
|
353
|
+
... field="task",
|
|
354
|
+
... expected="non-empty string",
|
|
355
|
+
... received="",
|
|
356
|
+
... example="task='Summarize this document'"
|
|
357
|
+
... )
|
|
358
|
+
"""
|
|
359
|
+
|
|
360
|
+
def __init__(
|
|
361
|
+
self,
|
|
362
|
+
message: str,
|
|
363
|
+
field: Optional[str] = None,
|
|
364
|
+
expected: Optional[str] = None,
|
|
365
|
+
received: Optional[Any] = None,
|
|
366
|
+
example: Optional[str] = None,
|
|
367
|
+
):
|
|
368
|
+
"""
|
|
369
|
+
Initialize a ValidationError with detailed context.
|
|
370
|
+
|
|
371
|
+
:param message: str - The main error message.
|
|
372
|
+
:param field: Optional[str] - Name of the field that failed validation.
|
|
373
|
+
:param expected: Optional[str] - Description of what was expected.
|
|
374
|
+
:param received: Optional[Any] - Description of what was received.
|
|
375
|
+
:param example: Optional[str] - Example of valid input.
|
|
376
|
+
"""
|
|
377
|
+
super().__init__(message)
|
|
378
|
+
self.field = field
|
|
379
|
+
self.expected = expected
|
|
380
|
+
self.received = received
|
|
381
|
+
self.example = example
|
|
382
|
+
|
|
383
|
+
def __str__(self) -> str:
|
|
384
|
+
"""
|
|
385
|
+
Format the error message with all available context.
|
|
386
|
+
|
|
387
|
+
:return: str - Formatted error message with validation details.
|
|
388
|
+
"""
|
|
389
|
+
parts = [super().__str__()]
|
|
390
|
+
|
|
391
|
+
if self.field:
|
|
392
|
+
parts.append(f" Field: {self.field}")
|
|
393
|
+
if self.expected:
|
|
394
|
+
parts.append(f" Expected: {self.expected}")
|
|
395
|
+
if self.received is not None:
|
|
396
|
+
parts.append(f" Received: {self.received}")
|
|
397
|
+
if self.example:
|
|
398
|
+
parts.append(f" Example: {self.example}")
|
|
399
|
+
|
|
400
|
+
return "\n".join(parts)
|