- 
                Notifications
    You must be signed in to change notification settings 
- Fork 486
feat: Enable list[dict] type for message['content'] for two-agent chat and group chat APIs #2145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…tool_executor.py:149-157)
  - Issue: tool_message variable was not initialized before the loop, causing UnboundLocalError when no tool calls were present
  - Fix: Added tool_message = None initialization and improved condition checking with message.get('tool_calls') instead of 'tool_calls' in message
    - Marker-based filtering system in test/conftest.py is working correctly - No Google dependency import errors in OpenAI tests - Proper test isolation achieved between different LLM providers
| Pull Request Review: Enable list[dict] type for message contentSummaryThis PR adds support for multimodal content (list of dictionaries) in the message content field across AG2 chat APIs, enabling compatibility with OpenAI Response API and new Gemini client formats. The implementation is comprehensive and well-tested. StrengthsCode Quality
 Test Coverage
 Backward Compatibility
 Issues FoundCritical Bug (test_multimodal_integration.py:86)Line 86 has duplicate image_url in list - should be image_url and input_image to match autogen/code_utils.py:82 Potential Enhancement (code_utils.py:79)The content_str() function uses assertions for validation. Assertions can be disabled with Pythons -O flag. Consider using explicit if checks with ValueError instead for production safety. Code Quality ObservationsGood Practices
 Minor Improvements
 PerformanceNo performance concerns. The content_str() function is efficient with simple list iteration and string joining. SecurityNo security vulnerabilities identified. Input validation is appropriate with type checking and explicit allowed types. No injection risks. Safeguard enforcement properly handles multimodal content with masking. Test CoverageExcellent - 18 total tests covering two-agent chat, group chat, sequential chat, nested chat, tool execution, and guardrails. Both Chat Completion API and Responses API formats tested. Suggestion: Add unit tests for content_str() function edge cases (empty list, unknown type, mixed content, non-dict items). RecommendationsMust Fix: 
 Should Consider: Nice to Have: Overall AssessmentVerdict: Approve with minor fixes (4.5/5) Well-engineered PR with thorough implementation, proper edge case handling, and excellent test coverage. Code follows good practices with type annotations and defensive programming. The critical bug is minor and easy to fix. Great work on comprehensive testing and maintaining backward compatibility! | 
| Code Review for PR #2145: Enable list[dict] type for message['content']SummaryThis PR extends AG2's message handling to support multimodal content in the form of list[dict] for the message['content'] field, aligning with OpenAI's Response API and Gemini client formats. The implementation is comprehensive and well-tested. Strengths1. Excellent Test Coverage
 2. Consistent Pattern Application & Backward Compatibility
 Issues and Concerns1. Code Duplication - High PriorityThe normalization logic is repeated 10+ times across multiple files in chat.py, conversable_agent.py, groupchat.py, group_tool_executor.py, and safeguards/enforcer.py. Recommendation: Extract this into a reusable helper function to reduce duplication. 2. Potential Type InconsistencyIn groupchat.py:1776-1786, the code modifies reply['content'] after normalizing, converting list[dict] to strings. Recommendation: Verify this is intentional and document why mutation is necessary. 3. Inconsistent Error HandlingMost locations don't have try-except blocks around content_str() calls, but SafeguardEnforcer._stringify_content does. 4. Missing Type HintsThe _post_process_carryover_item function lacks type hints. 5. Workflow File ChangesThe workflow file changes appear unrelated to the main feature - consider splitting into separate PR. Security & Performance
 Recommendations SummaryHigh Priority: 
 Medium Priority: Overall AssessmentWell-implemented feature with excellent test coverage. Main issue is code duplication, easily addressed. Recommendation: Approve with requested changes. Great work on comprehensive testing! | 
| PR Review: Enable list[dict] type for message['content']Thank you for this comprehensive PR! This is a well-structured enhancement that enables multimodal content support for AG2's chat APIs. ✅ Strengths
 
 | 
| Codecov Report❌ Patch coverage is  
 ... and 38 files with indirect coverage changes 🚀 New features to boost your workflow:
 | 
Why are these changes needed?
OAI Response API and new Gemini client support list[dict] in their output content field. See below for details.
OAI Response API output is a list of ResponseOutputItem. E.g. output of an image generation could be a list of two items, one text output and one encoded image string.
To support use cases like this, I would like to make AG2 message to messages.
Similarly, the content of OAI response API input (https://github.com/openai/openai-python/blob/main/src/openai/types/responses/response_input_item.py#L42 and https://github.com/openai/openai-python/blob/main/src/openai/types/responses/easy_input_message.py#L13) is a ResponseInputMessageContentList
Gemini Chat also support sending a list of messages https://github.com/googleapis/python-genai/blob/main/google/genai/chats.py#L227
Enable list[dict] type for message['content']
Add multimodal testing with list[dict] type for message['content'] for two-agent chat and groupchat with responses API.
Related issue number
Replace PR #2134
Checks
LLM test with
https://github.com/ag2ai/ag2/actions/runs/18505526861/job/52733291499
Skip LLM test with
https://github.com/ag2ai/ag2/actions/runs/18439791453