@shinyaz

Swarm agents that hand off produce no text output

1 min read

Trying to extract per-node output from a Swarm result, the researcher that handed off had no text output and caused an IndexError.

Output
--- researcher ---
  Status: Status.COMPLETED
 
--- writer ---
  Status: Status.COMPLETED
  Output: Amazon Bedrock is a fully managed AWS service...

The researcher calls handoff_to_agent to hand off, so it finishes without generating a text block. The content in result.message only contains tool-use blocks, with no block having a text key.

The final text output comes from the last agent that didn't hand off (writer in this case). When extracting output from result.results, always check for text block existence:

Python
for block in msg.get('content', []):
    if 'text' in block:  # This check is required
        print(block['text'])

Share this post

Shinya Tahara

Shinya Tahara

Solutions Architect @ AWS

I'm a Solutions Architect at AWS, providing technical guidance primarily to financial industry customers. I share learnings about cloud architecture and AI/ML on this site.The views and opinions expressed on this site are my own and do not represent the official positions of my employer.