Fix SupervisorAgent crash when agent response is a dict#452
Open
gavksingh wants to merge 2 commits intoawslabs:mainfrom
Open
Fix SupervisorAgent crash when agent response is a dict#452gavksingh wants to merge 2 commits intoawslabs:mainfrom
gavksingh wants to merge 2 commits intoawslabs:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
'dict' object has no attribute 'content'error inSupervisorAgent.send_message()that occurs when a team agent'sprocess_request()returns a dict instead of aConversationMessagesend_message()andprocess_agent_streaming_response()to handle bothConversationMessageand dict response formatsDetails
The
send_message()method directly accessedresponse.content[0].get('text', '')assumingresponseis always aConversationMessage. 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.contentattribute as beforedict— access via.get('content', [])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 correctlytest_send_message_dict_string_content— dict with string content items handledtest_send_message_conversation_message_regression— normal ConversationMessage still works (isinstance path)test_process_agent_streaming_response_dict_final_message— streaming with dict final_message handledtest_process_agent_streaming_response_conversation_message— streaming with ConversationMessage (regression)test_send_messages_with_dict_response_agent— end-to-end throughsend_messagesTest plan
pytest -v)Fixes #268