Skip to content

Commit 826d0f5

Browse files
committed
fix: preserve original name for warning comparison in transform_string_function_style
The function was replacing spaces with underscores before comparing whether the name had been modified, so space-only transformations never triggered the warning. This preserves the original name and compares the final lowercased result to properly warn on all transformations. Closes #2951 Signed-off-by: Cocoon-Break <54054995+kuishou68@users.noreply.github.com>
1 parent 82eaf15 commit 826d0f5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/agents/util/_transforms.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44

55

66
def transform_string_function_style(name: str) -> str:
7+
# Preserve the original name for comparison and warning message
8+
original_name = name
9+
710
# Replace spaces with underscores
811
name = name.replace(" ", "_")
912

1013
# Replace non-alphanumeric characters with underscores
1114
transformed_name = re.sub(r"[^a-zA-Z0-9_]", "_", name)
15+
final_name = transformed_name.lower()
1216

13-
if transformed_name != name:
14-
final_name = transformed_name.lower()
17+
if final_name != original_name:
1518
logger.warning(
16-
f"Tool name {name!r} contains invalid characters for function calling and has been "
19+
f"Tool name {original_name!r} contains invalid characters for function calling and has been "
1720
f"transformed to {final_name!r}. Please use only letters, digits, and underscores "
1821
"to avoid potential naming conflicts."
1922
)
2023

21-
return transformed_name.lower()
24+
return final_name

0 commit comments

Comments
 (0)