From a46444c2150c9956ab13da7961970b586394ef00 Mon Sep 17 00:00:00 2001 From: lbbniu Date: Tue, 9 Dec 2025 11:55:26 +0800 Subject: [PATCH] Python: Use agent description in HandoffBuilder auto-generated tools (#2713) ## 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 --- .../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 0a3608d2e6..a325fcb3ee 100644 --- a/python/packages/core/agent_framework/_workflows/_handoff.py +++ b/python/packages/core/agent_framework/_workflows/_handoff.py @@ -1085,10 +1085,18 @@ def _apply_auto_tools(self, agent: ChatAgent, specialists: Mapping[str, Executor 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