Python: feat: Add create_handoff_tools() for Azure AI Agent Service compatibility#3719
Python: feat: Add create_handoff_tools() for Azure AI Agent Service compatibility#3719frdeange wants to merge 3 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
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) |
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.... |
|
Hi @frdeange, thanks for working on this. Could you help check for conflicts between main and this branch? |
5e7c856 to
e1a9346
Compare
…ompatibility (microsoft#3713) Add create_handoff_tools() public function to allow pre-registration of handoff tools at agent creation time, needed for Azure AI Agent Service which does not support adding tools at request time. Also modify _apply_auto_tools() to skip duplicate tools instead of raising ValueError, enabling the pre-registration pattern.
e1a9346 to
1457e40
Compare
Thanks for your incredible effort @moonbox3 and team!!! I have updated the PR to the latest version of the repo with the renaming functions and libraries structure. Now it pass all the test. Thanks again! |
…ered tools Add sample demonstrating create_handoff_tools() usage with AzureAIProjectAgentProvider, showing how to pre-register handoff tools at agent creation time for services that don't support runtime tool registration.
ab84e94 to
67eb5df
Compare
|
Hi @frdeange, thanks for working on this. We actually have an easier solution to use the Foundry agents with orchestration patterns. I will get a PR out soon that shows this - and requires no extra helper functions. |
|
Closing in favor of #3873. |


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