[FEATURE] Agent-as-tools Handoff (TS)
SDK Language
TypeScript
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
Add a delegate boolean option to Agent.asTool(). 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.
The mechanism has two layers:
-
Description suffix at read time. When building
toolSpecsfor the model call, the agent loop appends a suffix to any handoff tool's description. This nudges the model to treat the call as terminal. The suffix is not stored on the tool itself. It's applied at the model-calling boundary. -
Loop short-circuit after tool execution. After
executeTools()completes and messages are appended to history, the loop iteratesToolUseBlocks in source order. If any corresponds to a handoff tool with a successfulToolResultBlock, the tool-result message is returned asAgentResult.lastMessage. On error, the loop continues normally so the model can recover.
// TypeScript
const customerService = new Agent({ name: 'CustomerService', description: '...' })
const technicalSupport = new Agent({ name: 'TechnicalSupport', description: '...' })
const orchestrator = new Agent({
tools: [
customerService.asTool({ delegate: true }),
technicalSupport.asTool({ delegate: true }),
],
})
const result = await orchestrator.invoke('My wifi does not work')
// result.lastMessage is the sub-agent's tool result 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