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>
This commit is contained in:
刘邦学AI
2025-12-16 09:31:26 +08:00
committed by GitHub
Unverified
parent a7298757f5
commit 3c379718e9
@@ -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