跳至内容

Exceptions

AgentsException

基类: Exception

Agents SDK中所有异常的基类。

Source code in src/agents/exceptions.py
class AgentsException(Exception):
    """Base class for all exceptions in the Agents SDK."""

MaxTurnsExceeded

基类: AgentsException

当超过最大轮数时引发的异常。

Source code in src/agents/exceptions.py
class MaxTurnsExceeded(AgentsException):
    """Exception raised when the maximum number of turns is exceeded."""

    message: str

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

ModelBehaviorError

基类:AgentsException

当模型执行意外操作时引发的异常,例如调用不存在的工具,或提供格式错误的JSON。

Source code in src/agents/exceptions.py
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

用户错误

基类:AgentsException

当用户使用SDK时出现错误引发的异常。

Source code in src/agents/exceptions.py
class UserError(AgentsException):
    """Exception raised when the user makes an error using the SDK."""

    message: str

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

输入防护栏触发警告

基类: AgentsException

当防护栏触发线被触发时引发的异常。

Source code in src/agents/exceptions.py
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"
        )

防护栏结果 instance-attribute

guardrail_result: InputGuardrailResult = guardrail_result

被触发的防护栏的结果数据。

输出防护栏触发警报

基类:AgentsException

当防护栏触发线被触发时引发的异常。

Source code in src/agents/exceptions.py
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"
        )

防护栏结果 instance-attribute

guardrail_result: OutputGuardrailResult = guardrail_result

被触发的防护栏的结果数据。