-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Description:
According to the SDK documentation, a UserError
should be raised when the user passes an invalid value to the tools
parameter (e.g., wrong type).
However, when I pass a string instead of a list of tools, an AttributeError
is thrown instead of the documented UserError
.
This seems to be due to missing type validation before the SDK iterates over the tools
parameter.
Steps to Reproduce:
from openai import OpenAI
from openai.agents import Agent
def predict_weather():
return "Sunny"
client = OpenAI()
# Passing a string instead of a list of tools
agent = Agent(
name="TestAgent",
instructions="Test agent",
tools="predict_weather" # should be a list
)
Expected Behavior:
Raise:
UserError: 'tools' must be a list of Tool objects, not a string.
Actual Behavior:
AttributeError: 'str' object has no attribute 'name'
Possible Fix:
Add an explicit type check in the constructor before iterating over the tools:
if not isinstance(tools, list):
raise UserError("'tools' must be a list of Tool objects, not a string.")
Note:
The UserError
class already exists in the SDK (class UserError(AgentsException)
) and is designed to handle such invalid usage scenarios. However, in this case, it’s not triggered because there’s no type check before the code tries to access tool.name
.
Environment:
- SDK version:
openai-agents[viz]>=0.2.4
- Python version:
Python 3.13.2
- OS:
Windows-11-10.0.26100-SP0