Repository navigation
Python: fix(core): prevent Python keywords from producing invalid tool names in _sanitize_agent_name - #8694
Conversation
…in _sanitize_agent_name Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
|
Thank you for proposing this change. I am closing this PR for now because it has no linked issue, and I could not find an issue covering this specific problem. Our contribution guidelines ask contributors to create or reuse an issue and discuss the approach before nontrivial changes (with an exception for trivial changes). The repository PR template asks for Motivation & Context, Description & Review Guide, a Related Issue linked with a closing keyword such as |
When converting an Agent to a tool via as_tool(), _sanitize_agent_name prepares the tool name so it behaves as a valid Python identifier for function invocation.
However, if an agent is named after a reserved Python keyword like def, class, for, or return, the sanitizer returned the keyword verbatim. Reserved keywords are not legal function identifiers in Python and cause syntax issues or tool schema problems.
This PR checks keyword.iskeyword(sanitized) in _sanitize_agent_name and appends a trailing underscore, following standard PEP 8 conventions for keyword disambiguation. I also added unit tests covering keyword sanitization in test_agents.py.