Skip to content

Python: fix(core): prevent Python keywords from producing invalid tool names in _sanitize_agent_name - #8694

Closed
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/sanitize-agent-name-keywords
Closed

Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/sanitize-agent-name-keywords

Conversation

@ManoharPaturi

Copy link
Copy Markdown
Contributor

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.

…in _sanitize_agent_name

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 23, 2026
@github-actions github-actions Bot changed the title fix(core): prevent Python keywords from producing invalid tool names in _sanitize_agent_name Python: fix(core): prevent Python keywords from producing invalid tool names in _sanitize_agent_name Sep 23, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

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 Fixes #123, and the contribution checklist; it notes that PRs without an issue link may be closed. This description does not follow that template. Please open or identify an issue, agree on the approach with the maintainers, then submit an updated PR using the template and linking the issue. Thanks.

This branch was previously deployed

1 inactive deployment
github-app-auth — 1f5bc86b Deployed Sep 23, 2026 by ManoharPaturi via team_check #5165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants