sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[FEATURE] Agent-as-tools handoff (Python)

Open liramon2 opened this issue 4 months ago • 2 comments

SDK Language

Python

Problem Statement

When using agent-as-tools for delegation, the orchestrator always makes an additional model call to process the sub-agent's response before returning it to the user. This adds latency and token cost for routing scenarios where the sub-agent's output is the final answer. It can also corrupt structured output (JSON, code) by paraphrasing it.

There is currently no way to tell the agent loop to skip the post-processing step during agent-as-tools delegation.

Proposed Solution

Port https://github.com/strands-agents/harness-sdk/issues/3257 to the Python SDK. The developer experience is the same: a delegate boolean option is added to Agent.as_tool(). When true, the agent loop short-circuits after the sub-agent's tool result is received, returning it directly as the AgentResult with stopReason: 'endTurn' instead of feeding it back to the orchestrator model.

# Sub-agents as tools
customer_service = Agent(
    name="CustomerService",
    system_prompt="...",
)

technical_support = Agent(
    name="TechnicalSupport",
    system_prompt="...",
)

# Orchestrator with sub-agents as tools
orchestrator = Agent(
    tools=[
        customer_service.as_tool(handoff=True),
        technical_support.as_tool(handoff=True),
    ],
)

result = orchestrator("My wifi does not work")
# result.message is the sub-agent's response directly

Use Case

  • Domain routing: Help-desk orchestrator routes billing to CustomerService, technical issues to TechnicalSupport. Specialist's response is the final answer — no orchestrator post-processing.
  • Structured output preservation: Sub-agent generates JSON for a report. JSON reaches the user verbatim without orchestrator paraphrasing.
  • Hierarchical delegation: Manager → Senior → Junior. Each level hands off deeper without latency accumulating on the way back up.

Alternatives Solutions

No response

Additional Context

Parent issue: https://github.com/strands-agents/harness-sdk/issues/911 Sibling issue: https://github.com/strands-agents/harness-sdk/issues/3257

liramon2 avatar Jul 24 '26 21:07 liramon2

Update 7/28:

  • Added implementation and got initial strandly reviews
  • Need the following merged before continuing: https://github.com/strands-agents/harness-sdk/pull/3508 https://github.com/strands-agents/harness-sdk/pull/3466

liramon2 avatar Jul 28 '26 15:07 liramon2

Update 8/11: passes Strandly reviews, needs human review

liramon2 avatar Aug 11 '26 17:08 liramon2