Commit 16169e1
committed
fix: validate tool types in Agent.tools list to prevent runtime AttributeError (fixes openai#1443)
This fix addresses issue openai#1443 where passing invalid tool types (e.g., raw
functions instead of FunctionTool objects) in the tools list would pass
initialization but fail at runtime with:
AttributeError: 'function' object has no attribute 'name'
(in src/agents/run.py line 584)
Changes:
- Added validation in Agent.__post_init__ to check each tool in the list
- Invalid tools now raise UserError at initialization with helpful message
- Suggests using @function_tool decorator when raw functions are detected
This provides better developer experience by:
1. Catching errors early (at init vs runtime)
2. Providing clear error messages
3. Suggesting the correct fix
Test Coverage:
- Added test_tools_content_validation_issue_1443 with 3 test cases
- Tests raw functions, strings, and mixed valid/invalid tools
- Verifies correct error index is reported1 parent 03dca68 commit 16169e1
2 files changed
+60
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
249 | 265 | | |
250 | 266 | | |
251 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
217 | 260 | | |
218 | 261 | | |
219 | 262 | | |
| |||
0 commit comments