Necessary model configuration to make them runnable. #1315
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request introduces a new set of runnable examples to the
examples/exceptions/
directory within the OpenAI Agents SDK repository. These examples are designed to clearly demonstrate how different types ofAgentsException
are triggered and how they can be handled by users of the SDK.Each example focuses on a specific exception, providing a minimal, self-contained, and executable code snippet along with detailed docstrings explaining the scenario and expected behavior. This aims to improve the developer experience by offering practical illustrations of error handling.
The following exceptions are covered with dedicated examples:
UserError
:File:
examples/exceptions/user_error_example.py
Description: Demonstrates
UserError
being raised due to incorrect SDK usage or configuration, such as providing an invalidtool_use_behavior
or a tool returning a type that mismatches its declared return type.MaxTurnsExceeded
:File:
examples/exceptions/max_turns_exceeded_example.py
Description: Illustrates how
MaxTurnsExceeded
is triggered when an agent's execution requires more turns (e.g., for tool calls and responses) than themax_turns
limit set inRunner.run
.ModelBehaviorError
:File:
examples/exceptions/model_behavior_error_example.py
Description: Shows
ModelBehaviorError
in action, specifically when the underlying language model (LLM) attempts to call a tool that does not exist in the agent's defined tools. This highlights issues arising from unexpected model output or behavior.InputGuardrailTripwireTriggered
:File:
examples/guardrails/input_guardrail_example.py
(As this is a guardrail-specific exception, it fits well withinexamples/guardrails
as it was already placed there.)Description: Demonstrates how
InputGuardrailTripwireTriggered
is raised when an input guardrail's conditions are met (e.g., detecting a math homework question), preventing the main agent from processing the input.OutputGuardrailTripwireTriggered
:File:
examples/guardrails/output_guardrail_example.py
(Similar to InputGuardrail, placed withinexamples/guardrails
.)Description: Illustrates
OutputGuardrailTripwireTriggered
being raised when an output guardrail's conditions are met (e.g., detecting sensitive data or forbidden content in the agent's final response).Each example includes:
Clear docstrings explaining the purpose and how the exception is triggered.
Comprehensive
try-except
blocks to catch and explain the specific exception.This addition will be highly beneficial for developers learning to use and debug the OpenAI Agents SDK.