Repository navigation
Recommend way of returning the last tool result as the agent's result/ preventing a last reasoning step in the Agent #1115
Replies: 3 comments 2 replies
|
Hi, we have a feature request for a similar feature to allow one agent to handoff control to another agent. You can track that here: #911 |
|
@MannyDiera , do you have a workaround for this until its officially supported? |
|
Hey @MannyDiera, hope you're doing well! Thanks for the really clear question, the education agent example made it easy to follow. And thanks @Unshure for linking #911 early on, since that feature request ended up shipping and it covers this pretty well now. The workaround you mentioned to @sahlawat11 (keep the last tool result and answer straight from the sub agent) is close to what the SDK does for you today. If the thing answering is a sub agent, you can mark it as a delegate (Python 1.53.0 and up): from strands import Agent
education = Agent(name="education", description="Answers education questions")
orchestrator = Agent(tools=[education.as_tool(delegate=True)])
result = orchestrator("explain photosynthesis")For a plain tool, a hook on from strands.hooks import AfterToolsEvent
def answer_with_tool_result(event: AfterToolsEvent):
for block in event.message["content"]:
if "toolResult" in block and block["toolResult"]["status"] == "success":
event.end_turn = block["toolResult"]["content"]
agent.add_hook(answer_with_tool_result, AfterToolsEvent)TypeScript has the same pair: This runs on current main: with a scripted model, both paths call the orchestrator's model only once and finish with Docs: agents as tools, Delegation and hook events. Would delegate fit your flow, or do you need the hook path for something the sub agent setup doesn't cover? And @Unshure, if there's a better recommended pattern here, I'd love to hear it. Any feedback or tips are very welcome. Drafted with help from Claude. |
Uh oh!
There was an error while loading. Please reload this page.
As an example, I have a personal assistant agent that uses a sub agents as tools.
In one scenario, my main / orchestrator agent calls an education agent which answers the users question. The main agent then receives this result as a tool output, calls an LLM and then responds to the user.
My goal is for the response from the education agent to be sent as-is back to the user. This way I can avoid an extra call to an LLM, reducing latency and cost.
Have looked into setting the callback handler to None, then capturing the tool result event with a Hook but in this case the hook event doesn't have enough information I need in order to respond to the user.
Does anyone have any suggestions?
All reactions