forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.py
63 lines (40 loc) · 1.81 KB
/
exceptions.py
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
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .guardrail import InputGuardrailResult, OutputGuardrailResult
class AgentsException(Exception):
"""Base class for all exceptions in the Agents SDK."""
class MaxTurnsExceeded(AgentsException):
"""Exception raised when the maximum number of turns is exceeded."""
message: str
def __init__(self, message: str):
self.message = message
class ModelBehaviorError(AgentsException):
"""Exception raised when the model does something unexpected, e.g. calling a tool that doesn't
exist, or providing malformed JSON.
"""
message: str
def __init__(self, message: str):
self.message = message
class UserError(AgentsException):
"""Exception raised when the user makes an error using the SDK."""
message: str
def __init__(self, message: str):
self.message = message
class InputGuardrailTripwireTriggered(AgentsException):
"""Exception raised when a guardrail tripwire is triggered."""
guardrail_result: "InputGuardrailResult"
"""The result data of the guardrail that was triggered."""
def __init__(self, guardrail_result: "InputGuardrailResult"):
self.guardrail_result = guardrail_result
super().__init__(
f"Guardrail {guardrail_result.guardrail.__class__.__name__} triggered tripwire"
)
class OutputGuardrailTripwireTriggered(AgentsException):
"""Exception raised when a guardrail tripwire is triggered."""
guardrail_result: "OutputGuardrailResult"
"""The result data of the guardrail that was triggered."""
def __init__(self, guardrail_result: "OutputGuardrailResult"):
self.guardrail_result = guardrail_result
super().__init__(
f"Guardrail {guardrail_result.guardrail.__class__.__name__} triggered tripwire"
)