Skip to content

Commit e486b3a

Browse files
authored
Add warning for agent names that transform into conflicting function names (#1758)
1 parent 76d637d commit e486b3a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/agents/util/_transforms.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import re
22

3+
from ..logger import logger
4+
35

46
def transform_string_function_style(name: str) -> str:
57
# Replace spaces with underscores
68
name = name.replace(" ", "_")
79

810
# Replace non-alphanumeric characters with underscores
9-
name = re.sub(r"[^a-zA-Z0-9]", "_", name)
11+
transformed_name = re.sub(r"[^a-zA-Z0-9_]", "_", name)
12+
13+
if transformed_name != name:
14+
final_name = transformed_name.lower()
15+
logger.warning(
16+
f"Tool name {name!r} contains invalid characters for function calling and has been "
17+
f"transformed to {final_name!r}. Please use only letters, digits, and underscores "
18+
"to avoid potential naming conflicts."
19+
)
1020

11-
return name.lower()
21+
return transformed_name.lower()

0 commit comments

Comments
 (0)