Repository navigation
fix: restore chronological order in MessageFilterAgent._apply_filter - #8275
Open
Varshith (Varshith-Kali) wants to merge 2 commits into
Open
Varshith (Varshith-Kali) wants to merge 2 commits into
Varshith (Varshith-Kali) wants to merge 2 commits into
Conversation
Author
|
Checking in on this MessageFilterAgent ordering fix. The change is small and covered by tests. The branch has fallen behind main since it was opened; happy to rebase if that helps the review. |
_apply_filter collected filtered messages grouped by per_source config order, so the wrapped agent received messages in config order rather than the order they appear in the message history. Re-sort the result on each message's original position before returning. The index map is keyed by object identity (id(m)) deliberately: list indexing would be O(n^2) and incorrect for value-identical duplicates (BaseChatMessage.__eq__ is pydantic value equality), e.g. a message and its model_copy() would both resolve to the first duplicate's position. Fixes microsoft#7971
- Add test for position=None (select-all) filters: config order [B, ghost, A] still yields chronological output, unmatched sources are ignored, and the input sequence is not mutated by the re-sort. - Add empty-history and on_messages_stream ordering tests; the stream entry point shares _apply_filter but previously had no coverage. - Document the chronological-order guarantee in the MessageFilterAgent class docstring. - Fix import order in the new test module per repo ruff (isort) config. All 10 ordering tests pass; 76 graph tests and 202 package tests pass. The 5 remaining collection errors are missing optional third-party dependencies (openai, tiktoken) in unrelated modules, pre-existing. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
Varshith (Varshith-Kali)
force-pushed
the
fix/message-filter-chronological-order
branch
from
October 24, 2026 05:43
2567996 to
ac92d35
Compare
Author
|
Rebased onto latest main; message-filter tests green. |
Author
|
Hi, the rebased head has its main CI workflows parked waiting for a first-time-contributor approval (action_required). Could a maintainer approve the runs so CI can proceed? Thanks. |
This branch has not been deployed
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
MessageFilterAgent._apply_filtercollected filtered messages grouped by per-source config order, so the wrapped agent received messages in config order rather than the order they appear in the message history. This re-sorts the result on each message's original position before returning.The index map is keyed by object identity (
id(m)) deliberately: list indexing would be O(n²) and incorrect for value-identical duplicates (BaseChatMessage.__eq__is pydantic value equality) — e.g. a message and itsmodel_copy()would both resolve to the first duplicate's position.Fixes #7971.
Changes
python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_graph/_agents/_message_filter_agent.py: 3-line fix + explanatory comment, plus a chronological-order guarantee in the class docstring.python/packages/autogen-agentchat/tests/test_message_filter_agent_order.py: 10 tests covering multi-source reordering,position=Noneselect-all filters, empty history, the streaming entry point, input non-mutation, and duplicate/value-equal messages.Test results
test_group_chat_graph.py, incl. existingMessageFilterAgenttests)autogen_agentchatpackage runruff checkandruff format --checkclean