Skip to content

Commit ab7590a

Browse files
lbbniumoonbox3
andauthored
Python: Use agent description in HandoffBuilder auto-generated tools (microsoft#2713) (microsoft#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 microsoft#2713 Co-authored-by: Evan Mattson <[email protected]>
1 parent 7d25102 commit ab7590a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • python/packages/core/agent_framework/_workflows

‎python/packages/core/agent_framework/_workflows/_handoff.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,18 @@ def _apply_auto_tools(self, agent: ChatAgent, specialists: Mapping[str, Executor
11141114

11151115
tool_targets: dict[str, str] = {}
11161116
new_tools: list[Any] = []
1117-
for exec_id in specialists:
1117+
for exec_id, executor in specialists.items():
11181118
alias = exec_id
11191119
sanitized = sanitize_identifier(alias)
1120-
tool = _create_handoff_tool(alias)
1120+
1121+
# Extract agent description from AgentExecutor if available
1122+
description = None
1123+
if isinstance(executor, AgentExecutor):
1124+
target_agent = getattr(executor, "_agent", None)
1125+
if target_agent:
1126+
description = getattr(target_agent, "description", None)
1127+
1128+
tool = _create_handoff_tool(alias, description)
11211129
if tool.name not in existing_names:
11221130
new_tools.append(tool)
11231131
tool_targets[tool.name.lower()] = exec_id

0 commit comments

Comments
 (0)