fix: V0.2 stability — token-limited orphan, message-filter order, rst… - #8036
Open
Hariom (hariomlohardev) wants to merge 1 commit into
Open
fix: V0.2 stability — token-limited orphan, message-filter order, rst…#8036Hariom (hariomlohardev) wants to merge 1 commit into
Hariom (hariomlohardev) wants to merge 1 commit into
Conversation
…rip empty - core/model_context: remove orphaned FunctionExecutionResultMessage after mid-list truncation (Fixes microsoft#8035). Collect active call_ids and filter orphans, handles first-element orphan. - agentchat: MessageFilterAgent._apply_filter preserves chronological order (Fixes microsoft#8034). Track original indices, emit in input order. - ext/models: _rstrip_last_assistant_message drops whitespace-only trailing assistant message and handles empty input (Fixes microsoft#8029) — anthropic + openai. Umbrella Fixes microsoft#8030 Signed-off-by: hariomlohardev <hariomlohar.new@gmail.com>
Author
|
@microsoft-github-policy-service agree |
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.
Why are these changes needed?
This PR fixes three V0.2 stability bugs triaged under the blank
needs-triagereport #8030 (autogen-agentchat==0.2.*, Python dev/main). Each bug is an open, unmerged fix that causes hard failures in multi-agent / token-limited / LLM edge cases.1)
core/model_context: remove orphaned FunctionExecutionResultMessage after mid-list truncation(Fixes #8035)TokenLimitedChatCompletionContext.get_messages()truncates from the middle (middle_index = len//2) to stay withintoken_limit/remaining_tokens.AssistantMessage(content=[FunctionCall(id=\"call_1\")])is dropped, its pairedFunctionExecutionResultMessage(call_id=\"call_1\")was orphaned. Old guard only checkedmessages[0](if isinstance(messages[0], FERM): pop 0), so any orphan beyond index 0 passed through and causedAPI error: orphaned tool result.python/packages/autogen-core/src/autogen_core/model_context/_token_limited_chat_completion_context.py— importAssistantMessage, FunctionCall, collectactive_call_ids = {item.id for msg in messages if AssistantMessage+list ..}, then filter:[m for m in messages if not FERM or (m.content and all(r.call_id in active_call_ids))]. Handles both mid-list and first-element orphans, preserves non-orphaned results.2)
agentchat: MessageFilterAgent._apply_filter preserves chronological order(Fixes #8034, root #7971)_apply_filteriteratedper_sourcefilters andresult.extend(msgs)in filter-config order. Withper_source=[A-last1, user-first1]and messages[user, A(old), B, A(new)]it returned[A(new), user]— config order, not timeline — breaking the LLM conversation.python/packages/autogen-agentchat/src/autogen_agentchat/agents/_message_filter_agent.py— trackselected: set[int]of original indices per filter (indexed = [(i,m) for i,m in enumerate(messages) if m.source == ...]slice byfirst/last/count), return[m for i,m in enumerate(messages) if i in selected]in original order. Result is now[user, A(new)].3)
ext/models: _rstrip_last_assistant_message drops whitespace-only trailing assistant message and handles empty input(Fixes #8029, #7768)AnthropicChatCompletionClientandOpenAIChatCompletionClienthad identical helper documented as “Remove the last assistant message if it is empty.” It only didcontent.rstrip()and left""in place.content=" "→""→ Anthropic rejects empty text block (text content blocks must be non-empty). Also crashed on[](messages[-1]IndexError) and mutated list content but never dropped.python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.pyandpython/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py— guardif not messages: return messages, afterrstrip()drop ifnot content: return messages[:-1]. Preserves normalrstripbehavior, listFunctionCallcontent unchanged, non-assistant last message untouched.No breaking API changes. All existing semantics preserved; only the buggy edge cases now behave as documented.
Related issue number
Closes #8030
Closes #8035
Closes #8034
Closes #8029
Related #7971, #7768, #7955
Checks
CONTRIBUTING.mdflow, no public API/docs affected.TokenLimited7-msg orphan removed / preserved,MessageFilterchronological order,rstripempty/whitespace/list/empty-list cases — all PASS viauv run python /tmp/verify_fixes5.py). Existing suites still green:test_model_context.py 9 passed,test_group_chat_graph.py -k message_filter 6 passed,test_mock_rstrip... 1 passed,test_rstrip... 1 passed. No new test files committed; ready to addtest_token_limited_mid_list_orphaned.../test_message_filter_agent_preserves_chronological_order/test_rstrip_emptyas follow-up if reviewer wants.uv run ruff checkclean,uv run pytest17 targeted tests pass,pyrightnot run (no type changes beyond expected imports). Push is gated by CI.