Skip to content

Python: feat: Add create_handoff_tools() for Azure AI Agent Service compatibility#3719

Open
frdeange wants to merge 2 commits intomicrosoft:mainfrom
frdeange:issue-3713-azure-handoff-fix
Open

Python: feat: Add create_handoff_tools() for Azure AI Agent Service compatibility#3719
frdeange wants to merge 2 commits intomicrosoft:mainfrom
frdeange:issue-3713-azure-handoff-fix

Conversation

@frdeange
Copy link

@frdeange frdeange commented Feb 6, 2026

Summary

This PR addresses issue #3713 where HandoffBuilder raised ValueError when 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 current HandoffBuilder implementation creates handoff tools at workflow build time and raises ValueError if tools with the same names already exist:

raise ValueError(
    f"Agent '{resolve_agent_id(agent)}' already has a tool named '{tool.name}'. "
    f"Handoff tool name '{tool.name}' conflicts with existing tool."
)

This prevents users from pre-creating handoff tools for Azure compatibility.

Solution

  1. 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 in default_options.tools.

  2. Modify _apply_auto_tools() to skip duplicates: Instead of raising ValueError, the method now logs a debug message and skips creating duplicate tools using continue.

  3. Export new functions: Both create_handoff_tools and get_handoff_tool_name are now part of the public API.

Usage Example

from agent_framework import ChatAgent, HandoffBuilder, create_handoff_tools

# Pre-create handoff tools for Azure AI Agent Service compatibility
handoff_tools = create_handoff_tools(
    ["specialist", "escalation"],
    descriptions={
        "specialist": "Route to specialist for technical issues",
        "escalation": "Escalate to supervisor for complex cases",
    },
)

# Create agent with Azure AI Agent Service
agent_definition = azure_project.agents.create_agent(
    name="triage",
    model="gpt-4o",
    instructions="...",
    tools=[t.metadata for t in handoff_tools],  # Pre-register tools
)

# Create ChatAgent with pre-registered tools
triage = ChatAgent(
    chat_client=azure_client,
    name="triage",
    default_options={"tools": handoff_tools},
)

# HandoffBuilder will skip duplicate tools automatically
workflow = (
    HandoffBuilder(participants=[triage, specialist, escalation])
    .with_start_agent(triage)
    .build()
)

Changes

  • _handoff.py:

    • Added create_handoff_tools() function (lines 120-186)
    • Modified _apply_auto_tools() to use continue instead of raise ValueError (lines 405-416)
  • _workflows/__init__.py:

    • Added exports for create_handoff_tools and get_handoff_tool_name
  • tests/workflow/test_handoff.py:

    • Added 4 new tests covering the Azure AI compatibility scenario

Testing

All 30 tests in test_handoff.py pass:

packages/core/tests/workflow/test_handoff.py ........................... [100%]
============================= 30 passed in 44.49s ==============================

Checklist

  • Tests added
  • Documentation in docstrings
  • Lint checks pass (poe lint)
  • Type checks pass (poe pyright)

Fixes #3713

Copilot AI review requested due to automatic review settings February 6, 2026 08:34
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Feb 6, 2026
@github-actions github-actions bot changed the title feat: Add create_handoff_tools() for Azure AI Agent Service compatibility Python: feat: Add create_handoff_tools() for Azure AI Agent Service compatibility Feb 6, 2026
Copy link
Contributor

Copilot AI left a 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 raising ValueError
  • Exported create_handoff_tools and get_handoff_tool_name in 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
@frdeange frdeange force-pushed the issue-3713-azure-handoff-fix branch from 61d0400 to ab0c153 Compare February 6, 2026 09:13
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 6, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/orchestrations/agent_framework_orchestrations
   _handoff.py3945785%104–105, 107, 181, 205–206, 228–238, 240, 242, 244, 249, 349, 432, 460, 468–469, 483, 534–535, 567, 614–616, 803, 810, 815, 902, 905, 914–917, 927, 932, 939, 945–948, 983, 988, 1185, 1188, 1196, 1214, 1221, 1296
TOTAL16595202487% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3916 225 💤 0 ❌ 0 🔥 1m 10s ⏱️

@TaoChenOSU
Copy link
Contributor

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 specialist and escalation to handoff to triage. The system internal will still attempt to create handoff tools for specialist and escalation to handoff to triage, which will fail.

I think we need a way to let the builder know not to create the handoff tools at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: HandoffBuilder incompatible with Azure AI Agent Service (tools cannot be added at request time)

3 participants