diff --git a/src/agents/function_schema.py b/src/agents/function_schema.py index 18856697..dd1db1fe 100644 --- a/src/agents/function_schema.py +++ b/src/agents/function_schema.py @@ -223,7 +223,8 @@ def function_schema( doc_info = None param_descs = {} - func_name = name_override or doc_info.name if doc_info else func.__name__ + # Ensure name_override takes precedence even if docstring info is disabled. + func_name = name_override or (doc_info.name if doc_info else func.__name__) # 2. Inspect function signature and get type hints sig = inspect.signature(func) diff --git a/tests/test_function_schema.py b/tests/test_function_schema.py index 5618d8ae..54e7e2f9 100644 --- a/tests/test_function_schema.py +++ b/tests/test_function_schema.py @@ -439,3 +439,15 @@ def func_with_mapping(test_one: Mapping[str, int]) -> str: with pytest.raises(UserError): function_schema(func_with_mapping) + + +def test_name_override_without_docstring() -> None: + """name_override should be used even when not parsing docstrings.""" + + def foo(x: int) -> int: + return x + + fs = function_schema(foo, use_docstring_info=False, name_override="custom") + + assert fs.name == "custom" + assert fs.params_json_schema.get("title") == "custom_args"