fix: ContextComponent.to_messages() returns smolagents-compatible list content#3330
Merged
Dallas98 merged 3 commits intoJun 29, 2026
Merged
Conversation
…t content
Root cause: ContextComponent subclasses returned {"content": "string"} but
smolagents v1.23 requires {"content": [{"type": "text", "text": "..."}]}
when merging consecutive same-role messages in get_clean_message_list().
This caused 'Error: wrong content: <system prompt text>' assertion failures
for all non-modelengine model providers when enable_context_manager was active.
Changes:
- agent_model.py: All 8 to_messages() methods now return list-format content
via new _text_message() helper; estimate_tokens() handles list content
- agent_context.py: prepare_run_context uses _extract_message_text() for
stable_text assembly; _purpose_messages returns list-format content
- Tests updated to match new content format
…ent-smolagents-content-format
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…essage_text branches - estimate_tokens: test string content fallback path (else branch) - _extract_message_text: test ChatMessage object input, string content, None content, missing key, and mixed list content
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.
Root Cause
Agent conversations fail with
Error: wrong content: <system prompt text>when using non-modelengine model providers withenable_context_managerenabled.Error chain:
ContextComponent.to_messages()returned{"content": "string"}but smolagents v1.23 requires{"content": [{"type": "text", "text": "..."}]}when merging consecutive same-role messages.The
prepare_messages_for_smolagents_text_flatteningmitigation inopenai_llm.pyonly activated formodel_factory == "modelengine", leaving all other providers (OpenAI, Silicon, etc.) with string content that triggered the assertion.Changes
Production code
sdk/nexent/core/agents/agent_model.py: All 8to_messages()methods now return list-format content via new_text_message()static helper.estimate_tokens()rewritten to handle list content.sdk/nexent/core/agents/agent_context.py:prepare_run_contextuses new_extract_message_text()for stable_text assembly._purpose_messagesreturns list-format content.Tests
test/sdk/core/agents/test_context_component.py: 1 assertion updatedtest/backend/utils/test_context_component_types.py: 6 assertions updatedtest/sdk/core/agents/test_context_manager_assembly.py:_message_texthelper +_Stepstub + 2 assertions updatedVerification
All 521 directly related and adjacent tests pass:
test_context_component.py: 68/68test_context_component_types.py: 38/38test_context_manager_assembly.py: 4/4test_agent_context/: 126/126test_agent_model.py: 224/224test_openai_llm.py: 53/53test_message_utils.py: 8/8