Skip to content

Fix SupervisorAgent crash when agent response is a dict#452

Open
gavksingh wants to merge 2 commits intoawslabs:mainfrom
gavksingh:fix/supervisor-agent-streaming
Open

Fix SupervisorAgent crash when agent response is a dict#452
gavksingh wants to merge 2 commits intoawslabs:mainfrom
gavksingh:fix/supervisor-agent-streaming

Conversation

@gavksingh
Copy link
Copy Markdown

@gavksingh gavksingh commented Mar 17, 2026

Summary

  • Fixed 'dict' object has no attribute 'content' error in SupervisorAgent.send_message() that occurs when a team agent's process_request() returns a dict instead of a ConversationMessage
  • Added type guards in both send_message() and process_agent_streaming_response() to handle both ConversationMessage and dict response formats
  • Added 6 new tests covering dict response handling, streaming with dict final_message, and regression tests

Details

The send_message() method directly accessed response.content[0].get('text', '') assuming response is always a ConversationMessage. However, in certain scenarios (e.g., tool use with some providers, or follow-up messages in multi-turn conversations), the response can be a plain dict with {'role': ..., 'content': [...]} structure.

The fix adds isinstance checks to handle both formats gracefully:

  • ConversationMessage — access .content attribute as before
  • dict — access via .get('content', [])
  • Other types — fall back to str(response)

Tests added

Added to: python/src/tests/agents/test_supervisor_agent.py (6 new tests)

  • test_send_message_dict_response — the bug fix test: agent returns dict, no AttributeError, extracts text correctly
  • test_send_message_dict_string_content — dict with string content items handled
  • test_send_message_conversation_message_regression — normal ConversationMessage still works (isinstance path)
  • test_process_agent_streaming_response_dict_final_message — streaming with dict final_message handled
  • test_process_agent_streaming_response_conversation_message — streaming with ConversationMessage (regression)
  • test_send_messages_with_dict_response_agent — end-to-end through send_messages

Test plan

  • All 18 tests pass (12 existing + 6 new) (pytest -v)
  • Dict response handling works for both dict-with-dict-content and dict-with-string-content
  • Streaming dict final_message handled correctly
  • ConversationMessage responses still work (regression tests)

Fixes #268

In send_message(), the code assumed process_request() always returns a
ConversationMessage with a .content attribute. However, in some cases
(e.g., tool use with certain providers), the response can be a plain
dict, causing "'dict' object has no attribute 'content'" errors.

Add type checking before accessing .content on the response and handle
both ConversationMessage and dict response formats gracefully. Also add
the same guard in process_agent_streaming_response for consistency.

Fixes awslabs#268
Tests verify that send_message correctly handles agents returning dicts
instead of ConversationMessage objects (the bug fix), including dict
with string content items, streaming with dict final_message, and
regression tests ensuring ConversationMessage still works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Error in send_message: 'dict' object has no attribute 'content'" From Supervisor Agent

1 participant