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 2 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) |
…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. |
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