From 3c379718e90a607ae04168b24b582970afe226e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=82=A6=E5=AD=A6AI?= Date: Tue, 16 Dec 2025 09:31:26 +0800 Subject: [PATCH] Python: Use agent description in HandoffBuilder auto-generated tools (#2713) (#2714) ## Summary Enhanced `HandoffBuilder._apply_auto_tools` to use the target agent's description when creating handoff tools, providing more informative tool descriptions for LLMs. ## Changes - Modified `_apply_auto_tools` to extract `description` from `AgentExecutor._agent` when available - Updated iteration to use `.items()` for more efficient dict traversal - Handoff tools now use agent descriptions instead of generic placeholders ## Example Before: "Handoff to the refund_agent agent." After: "You handle refund requests. Ask for order details and process refunds." ## Testing - All handoff tests pass (20/20) - No breaking changes to existing API Fixes #2713 Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com> --- .../core/agent_framework/_workflows/_handoff.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/python/packages/core/agent_framework/_workflows/_handoff.py b/python/packages/core/agent_framework/_workflows/_handoff.py index 8e0a7aec1e..47e558ccbd 100644 --- a/python/packages/core/agent_framework/_workflows/_handoff.py +++ b/python/packages/core/agent_framework/_workflows/_handoff.py @@ -1114,10 +1114,18 @@ class HandoffBuilder: tool_targets: dict[str, str] = {} new_tools: list[Any] = [] - for exec_id in specialists: + for exec_id, executor in specialists.items(): alias = exec_id sanitized = sanitize_identifier(alias) - tool = _create_handoff_tool(alias) + + # Extract agent description from AgentExecutor if available + description = None + if isinstance(executor, AgentExecutor): + target_agent = getattr(executor, "_agent", None) + if target_agent: + description = getattr(target_agent, "description", None) + + tool = _create_handoff_tool(alias, description) if tool.name not in existing_names: new_tools.append(tool) tool_targets[tool.name.lower()] = exec_id