Bug: transform_string_function_style silently transforms tool names with spaces without warning
Description
In src/agents/util/_transforms.py, the function transform_string_function_style has a logic bug: it replaces spaces with underscores before comparing to decide whether to emit a warning. This means tool names containing spaces are silently lowercased and space-replaced without triggering the warning.
Current behavior
def transform_string_function_style(name: str) -> str:
name = name.replace(" ", "_") # ← modifies `name` in-place
transformed_name = re.sub(r"[^a-zA-Z0-9_]", "_", name)
if transformed_name != name: # ← compared against already-modified name
logger.warning(...) # ← never fires for space-only transformations
return transformed_name.lower()
For a tool named "My Tool":
name becomes "My_Tool"
transformed_name becomes "My_Tool" (no further changes)
transformed_name == name → no warning
- Returns
"my_tool" — silently different from the original input "My Tool"
Expected behavior
The warning should fire whenever the final returned value differs from the original input. Names with spaces should trigger the same warning as names with other invalid characters.
Fix
Preserve the original name before any modifications:
def transform_string_function_style(name: str) -> str:
original_name = name
name = name.replace(" ", "_")
transformed_name = re.sub(r"[^a-zA-Z0-9_]", "_", name)
final_name = transformed_name.lower()
if final_name != original_name:
logger.warning(
f"Tool name {original_name!r} contains invalid characters for function calling and has been "
f"transformed to {final_name!r}. Please use only letters, digits, and underscores "
"to avoid potential naming conflicts."
)
return final_name
Impact
Users defining tools with names containing spaces will silently get renamed without any log warning, making it harder to debug mismatched tool names.
Signed-off-by: Cocoon-Break 54054995+kuishou68@users.noreply.github.com
Bug:
transform_string_function_stylesilently transforms tool names with spaces without warningDescription
In
src/agents/util/_transforms.py, the functiontransform_string_function_stylehas a logic bug: it replaces spaces with underscores before comparing to decide whether to emit a warning. This means tool names containing spaces are silently lowercased and space-replaced without triggering the warning.Current behavior
For a tool named
"My Tool":namebecomes"My_Tool"transformed_namebecomes"My_Tool"(no further changes)transformed_name == name→ no warning"my_tool"— silently different from the original input"My Tool"Expected behavior
The warning should fire whenever the final returned value differs from the original input. Names with spaces should trigger the same warning as names with other invalid characters.
Fix
Preserve the original name before any modifications:
Impact
Users defining tools with names containing spaces will silently get renamed without any log warning, making it harder to debug mismatched tool names.
Signed-off-by: Cocoon-Break 54054995+kuishou68@users.noreply.github.com