@@ -137,6 +137,7 @@ def function_tool(
137
137
docstring_style : DocstringStyle | None = None ,
138
138
use_docstring_info : bool = True ,
139
139
failure_error_function : ToolErrorFunction | None = None ,
140
+ strict_mode : bool = True ,
140
141
) -> FunctionTool :
141
142
"""Overload for usage as @function_tool (no parentheses)."""
142
143
...
@@ -150,6 +151,7 @@ def function_tool(
150
151
docstring_style : DocstringStyle | None = None ,
151
152
use_docstring_info : bool = True ,
152
153
failure_error_function : ToolErrorFunction | None = None ,
154
+ strict_mode : bool = True ,
153
155
) -> Callable [[ToolFunction [...]], FunctionTool ]:
154
156
"""Overload for usage as @function_tool(...)."""
155
157
...
@@ -163,6 +165,7 @@ def function_tool(
163
165
docstring_style : DocstringStyle | None = None ,
164
166
use_docstring_info : bool = True ,
165
167
failure_error_function : ToolErrorFunction | None = default_tool_error_function ,
168
+ strict_mode : bool = True ,
166
169
) -> FunctionTool | Callable [[ToolFunction [...]], FunctionTool ]:
167
170
"""
168
171
Decorator to create a FunctionTool from a function. By default, we will:
@@ -186,6 +189,7 @@ def function_tool(
186
189
failure_error_function: If provided, use this function to generate an error message when
187
190
the tool call fails. The error message is sent to the LLM. If you pass None, then no
188
191
error message will be sent and instead an Exception will be raised.
192
+ strict_mode: If False, allows optional parameters in the function schema.
189
193
"""
190
194
191
195
def _create_function_tool (the_func : ToolFunction [...]) -> FunctionTool :
@@ -195,6 +199,7 @@ def _create_function_tool(the_func: ToolFunction[...]) -> FunctionTool:
195
199
description_override = description_override ,
196
200
docstring_style = docstring_style ,
197
201
use_docstring_info = use_docstring_info ,
202
+ strict_json_schema = strict_mode ,
198
203
)
199
204
200
205
async def _on_invoke_tool_impl (ctx : RunContextWrapper [Any ], input : str ) -> str :
@@ -273,6 +278,7 @@ async def _on_invoke_tool(ctx: RunContextWrapper[Any], input: str) -> str:
273
278
description = schema .description or "" ,
274
279
params_json_schema = schema .params_json_schema ,
275
280
on_invoke_tool = _on_invoke_tool ,
281
+ strict_json_schema = strict_mode ,
276
282
)
277
283
278
284
# If func is actually a callable, we were used as @function_tool with no parentheses
0 commit comments