Please read this first
- Have you read the docs?Agents SDK docs :
Yes
- Have you searched for related issues? Others may have had similar requests:
Yes
Question
Description of the Issue:
In the agents/handoffs.py, there's ae assert statement in handoff() function related to the on_handoff and input_type parameters that appears to be logically flawed and potentially misleading:
assert (on_handoff and input_type) or not (on_handoff and input_type), (
"You must provide either both on_input and input_type, or neither"
)
There are two main concerns with this assertion as presented:
-
Logical Tautology: The condition (on_handoff and input_type) or not (on_handoff and input_type) can be simplified to P or not P (where P = on_handoff and input_type). This is a tautology, meaning it always evaluates to True, regardless of the truthiness of on_handoff or input_type. Consequently, this assert statement will never fail and does not enforce any conditions.
-
Contradictory Message: The assertion message states, "You must provide either both on_input and input_type, or neither" (assuming "on_input" is a typo for "on_handoff"). This message suggests a strict requirement that on_handoff and input_type must either both be present or both be absent. This is in direct contradiction to the assertion's condition, which, being always true, places no restrictions.
Framing the Concern:
If the use of a tautological (always true) condition in the assertion is intentional – perhaps to signify that, for the purpose of that example, the SDK imposes no specific co-occurrence requirements on on_handoff and input_type (i.e., allowing flexible combinations such as one parameter being provided without the other) – then the accompanying message "You must provide either both on_handoff and input_type, or neither" becomes highly contradictory and misleading.
This interpretation suggests that the SDK might indeed intend to be flexible regarding these parameters. My own testing confirms this flexibility: for instance, if input_type is not passed to the handoff() function, and the on_handoff callback's signature is adjusted to not expect the corresponding parsed input_data, there is no operational issue. This practical behavior aligns with the idea that the SDK allows providing on_handoff without a corresponding input_type in certain valid scenarios.
The current state of this example assertion can therefore cause significant confusion for users trying to understand the correct and valid usage patterns for on_handoff and input_type.
Expected Behavior:
The code should clearly and accurately reflect the SDK's behavior and requirements. An assert statement should either:
- Correctly enforce a relevant condition being demonstrated.
- Be accompanied by explanatory text that clarifies its purpose or limitations if it's illustrative of a partial concept.
- The message of an assertion should accurately reflect the logic of its condition.
Actual Behavior:
The assert statement:
- Does not enforce any condition due to its tautological logic.
- Presents a message that implies a strict rule ("both or neither").
- This rule from the message is not universally true for the SDK's
handoff() function, which offers more flexibility.
Location:
This assertion statement is found at line 170 in handoff() function and in the agents/handoffs.py within the openai-agents-python repository.
Suggested Actions:
To mitigate confusion, I suggest the following:
- If the intent is to demonstrate a specific rule: The assertion logic should be corrected to accurately implement that rule (e.g.,
assert bool(on_handoff_callback) == bool(input_model) if the "both or neither" rule is indeed what the code aims for a specific scenario).
- If the intent is to show that the parameters are optional or have nuanced dependencies: The assertion might be misleading. It would be better to replace it with clear explanatory text detailing the valid combinations of
on_handoff and input_type, including when input_type is essential for an on_handoff callback that expects structured data.
- At a minimum: The current tautological assertion and its contradictory message should be revised to prevent user confusion.
Clarifying the relationship and valid usage patterns of on_handoff and input_type in the core documentation would also be beneficial.
Thank you for considering this issue.
Please read this first
YesYesQuestion
Description of the Issue:
In the
agents/handoffs.py, there's aeassertstatement inhandoff()function related to theon_handoffandinput_typeparameters that appears to be logically flawed and potentially misleading:There are two main concerns with this assertion as presented:
Logical Tautology: The condition
(on_handoff and input_type) or not (on_handoff and input_type)can be simplified toP or not P(whereP = on_handoff and input_type). This is a tautology, meaning it always evaluates toTrue, regardless of the truthiness ofon_handofforinput_type. Consequently, thisassertstatement will never fail and does not enforce any conditions.Contradictory Message: The assertion message states, "You must provide either both on_input and input_type, or neither" (assuming "on_input" is a typo for "on_handoff"). This message suggests a strict requirement that
on_handoffandinput_typemust either both be present or both be absent. This is in direct contradiction to the assertion's condition, which, being always true, places no restrictions.Framing the Concern:
If the use of a tautological (always true) condition in the assertion is intentional – perhaps to signify that, for the purpose of that example, the SDK imposes no specific co-occurrence requirements on
on_handoffandinput_type(i.e., allowing flexible combinations such as one parameter being provided without the other) – then the accompanying message "You must provide either both on_handoff and input_type, or neither" becomes highly contradictory and misleading.This interpretation suggests that the SDK might indeed intend to be flexible regarding these parameters. My own testing confirms this flexibility: for instance, if
input_typeis not passed to thehandoff()function, and theon_handoffcallback's signature is adjusted to not expect the corresponding parsedinput_data, there is no operational issue. This practical behavior aligns with the idea that the SDK allows providingon_handoffwithout a correspondinginput_typein certain valid scenarios.The current state of this example assertion can therefore cause significant confusion for users trying to understand the correct and valid usage patterns for
on_handoffandinput_type.Expected Behavior:
The code should clearly and accurately reflect the SDK's behavior and requirements. An
assertstatement should either:Actual Behavior:
The
assertstatement:handoff()function, which offers more flexibility.Location:
This assertion statement is found at line 170 in
handoff()function and in theagents/handoffs.pywithin theopenai-agents-pythonrepository.Suggested Actions:
To mitigate confusion, I suggest the following:
assert bool(on_handoff_callback) == bool(input_model)if the "both or neither" rule is indeed what the code aims for a specific scenario).on_handoffandinput_type, including wheninput_typeis essential for anon_handoffcallback that expects structured data.Clarifying the relationship and valid usage patterns of
on_handoffandinput_typein the core documentation would also be beneficial.Thank you for considering this issue.