Skip to content

fix: preserve chronological message order in MessageFilterAgent._apply_filter - #7981

Open
Varshith-Kali wants to merge 1 commit into
microsoft:mainfrom
Varshith-Kali:fix/message-filter-agent-ordering
Open

fix: preserve chronological message order in MessageFilterAgent._apply_filter#7981
Varshith-Kali wants to merge 1 commit into
microsoft:mainfrom
Varshith-Kali:fix/message-filter-agent-ordering

Conversation

@Varshith-Kali

Copy link
Copy Markdown

Fixes #7971

MessageFilterAgent._apply_filter iterates per_source in config order and
appends each source's matches, emitting messages in config order rather
than their original chronological order. This breaks the class's own
documented example (A->B->A->B->C graph where B sees A's newer message
before its own prior reply).

What changed

Added a sort by original input position after building the result list.
The fix is a one-liner: result.sort(key=lambda m: messages.index(m))
preceded by an explanatory comment referencing the issue.

Test

Added 5 tests covering:

  • Chronological order preservation with the documented A->B->A->B example
  • Filter results are always a subset of input messages
  • Single-source filter with no reordering
  • Unfiltered sources are correctly excluded
  • Empty per_source returns an empty list

Files

  • python/packages/autogen-agentchat/src/autogen_agentchat/agents/_message_filter_agent.py
  • python/packages/autogen-agentchat/tests/test_message_filter_agent_order.py (new)

…y_filter

_apply_filter iterated per_source in config order and appended each
source's matches, emitting messages in config order rather than their
original chronological order. This broke the class's own documented
example (A->B->A->B->C graph where B sees A's newer message before
its own prior reply).

Fixed by sorting the result list by each message's original position
in the input sequence before returning it.

Fixes microsoft#7971
@Varshith-Kali

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MessageFilterAgent orders filtered messages by per_source config order, not chronological order

1 participant