Skip to content

Exceptions

AgentsException

Bases: Exception

Base class for all exceptions in the CAI Agents.

Source code in src/cai/sdk/agents/exceptions.py
7
8
class AgentsException(Exception):
    """Base class for all exceptions in the CAI Agents."""

MaxTurnsExceeded

Bases: AgentsException

Exception raised when the maximum number of turns is exceeded.

Source code in src/cai/sdk/agents/exceptions.py
11
12
13
14
15
16
17
class MaxTurnsExceeded(AgentsException):
    """Exception raised when the maximum number of turns is exceeded."""

    message: str

    def __init__(self, message: str):
        self.message = message

ModelBehaviorError

Bases: AgentsException

Exception raised when the model does something unexpected, e.g. calling a tool that doesn't exist, or providing malformed JSON.

Source code in src/cai/sdk/agents/exceptions.py
20
21
22
23
24
25
26
27
28
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

UserError

Bases: AgentsException

Exception raised when the user makes an error using CAI.

Source code in src/cai/sdk/agents/exceptions.py
31
32
33
34
35
36
37
class UserError(AgentsException):
    """Exception raised when the user makes an error using CAI."""

    message: str

    def __init__(self, message: str):
        self.message = message

InputGuardrailTripwireTriggered

Bases: AgentsException

Exception raised when a guardrail tripwire is triggered.

Source code in src/cai/sdk/agents/exceptions.py
40
41
42
43
44
45
46
47
48
49
50
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"
        )

guardrail_result instance-attribute

guardrail_result: InputGuardrailResult = guardrail_result

The result data of the guardrail that was triggered.

OutputGuardrailTripwireTriggered

Bases: AgentsException

Exception raised when a guardrail tripwire is triggered.

Source code in src/cai/sdk/agents/exceptions.py
53
54
55
56
57
58
59
60
61
62
63
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"
        )

guardrail_result instance-attribute

guardrail_result: OutputGuardrailResult = guardrail_result

The result data of the guardrail that was triggered.

PriceLimitExceeded

Bases: AgentsException

Raised when the maximum price limit is exceeded.

Source code in src/cai/sdk/agents/exceptions.py
66
67
68
69
class PriceLimitExceeded(AgentsException):
    """Raised when the maximum price limit is exceeded."""
    def __init__(self, current_cost: float, price_limit: float):
        super().__init__(f"Maximum price limit (${price_limit:.4f}) exceeded. Current cost: ${current_cost:.4f}")