-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: feat: Add create_handoff_tools() for Azure AI Agent Service compatibility #3719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses issue #3713 by enabling HandoffBuilder to work with Azure AI Agent Service, which requires tools to be registered at agent creation time rather than request time. The solution adds a public create_handoff_tools() helper function that users can call to pre-create handoff tools before agent creation, and modifies the builder to skip (rather than error on) duplicate tools.
Changes:
- Added
create_handoff_tools()function to generate handoff tools compatible with the framework's internal structure - Modified
_apply_auto_tools()to log and skip duplicate tools instead of raisingValueError - Exported
create_handoff_toolsandget_handoff_tool_namein the public API
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_workflows/_handoff.py | Implements create_handoff_tools() function and modifies duplicate tool handling to use continue instead of raising ValueError |
| python/packages/core/agent_framework/_workflows/init.py | Adds exports for create_handoff_tools and get_handoff_tool_name to public API |
| python/packages/core/tests/workflow/test_handoff.py | Adds 4 comprehensive tests covering Azure AI compatibility scenarios including pre-created tools and integration testing |
| python/packages/declarative/README.md | Comprehensive documentation update (appears unrelated to PR's stated purpose) |
…lity This PR adds support for Azure AI Agent Service and other providers that require tools to be registered at agent creation time. Changes: - Add create_handoff_tools() function to pre-create handoff FunctionTools - Modify _apply_auto_tools() to skip duplicates instead of raising ValueError - Add get_handoff_tool_name() to public exports - Add tests for Azure AI compatibility scenario The create_handoff_tools() function allows users to pre-create handoff tools that can be included in the agent's default_options when creating agents with Azure AI Agent Service. The HandoffBuilder now detects pre-existing handoff tools and gracefully skips creating duplicates, logging a debug message instead of raising an error. Fixes microsoft#3713
61d0400 to
ab0c153
Compare
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
|
Hi @frdeange, Thanks for your contribution! I am surprised that your sample would work. The handoff workflow creates a mesh topology by default where all nodes are connected to each other. In your sample, you didn't create tool for the I think we need a way to let the builder know not to create the handoff tools at all. |
|
Hello @TaoChenOSU! Thanks for your time checking this!!! Actually, let me say it works.... I have the example running right now using this method (before the latest updates I have see right now in the breaking_changes :-( Here is tracing for the router agent handoff tool execution
And the abseceAgent giving back to routerAgent after solving situation with user: So yes, it works.... |


Summary
This PR addresses issue #3713 where
HandoffBuilderraisedValueErrorwhen users pre-created handoff tools for Azure AI Agent Service compatibility.Problem
When using Azure AI Agent Service, tools must be registered at agent creation time (via
AzureAIClient.create_agent()), not at request time. The currentHandoffBuilderimplementation creates handoff tools at workflow build time and raisesValueErrorif tools with the same names already exist:This prevents users from pre-creating handoff tools for Azure compatibility.
Solution
Add
create_handoff_tools()function: A public helper that creates handoff tools compatible with the framework's internal structure. Users can call this before creating their agents and include the tools indefault_options.tools.Modify
_apply_auto_tools()to skip duplicates: Instead of raisingValueError, the method now logs a debug message and skips creating duplicate tools usingcontinue.Export new functions: Both
create_handoff_toolsandget_handoff_tool_nameare now part of the public API.Usage Example
Changes
_handoff.py:create_handoff_tools()function (lines 120-186)_apply_auto_tools()to usecontinueinstead ofraise ValueError(lines 405-416)_workflows/__init__.py:create_handoff_toolsandget_handoff_tool_nametests/workflow/test_handoff.py:Testing
All 30 tests in
test_handoff.pypass:Checklist
poe lint)poe pyright)Fixes #3713