Skip to content

fix: preserve TextMentionTermination.sources across serialization round-trip#7933

Open
HumphreySun98 wants to merge 1 commit into
microsoft:mainfrom
HumphreySun98:fix/text-mention-termination-sources
Open

fix: preserve TextMentionTermination.sources across serialization round-trip#7933
HumphreySun98 wants to merge 1 commit into
microsoft:mainfrom
HumphreySun98:fix/text-mention-termination-sources

Conversation

@HumphreySun98

Copy link
Copy Markdown

Why are these changes needed?

TextMentionTermination accepts a sources argument that restricts which
message sources are checked for the termination text:

term = TextMentionTermination("stop", sources=["assistant"])

However TextMentionTerminationConfig only stored text, and
_to_config/_from_config only serialized/restored text. So a condition
configured with sources silently loses that restriction after a declarative
dump_component() / load_component() round-trip, and the reloaded condition
then fires on any source (including user or other agents) — a behavior
change on save/load.

The sibling SourceMatchTermination already round-trips its sources field
correctly (and the existing declarative test asserts it), which makes this an
inconsistency rather than an intentional omission.

This PR adds sources to TextMentionTerminationConfig and serializes/restores
it in _to_config/_from_config, with a regression test covering both the
sources-restricted and unrestricted cases.

Related issue number

N/A — found during review. Fixes a serialization round-trip data loss;
SourceMatchTermination is the correct reference behavior.

Checks

  • I've included any doc changes needed for https://microsoft.github.io/autogen/ (none required for this change).
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed (ran ruff, mypy, and the relevant pytest locally).

…nd-trip

`TextMentionTermination` accepts a `sources` argument that restricts which
message sources are checked, but `TextMentionTerminationConfig` only stored
`text`, and `_to_config`/`_from_config` only serialized/restored `text`. As a
result, a condition configured with `sources` silently lost that restriction
after a `dump_component()` / `load_component()` round-trip and then fired on any
source — a behavior change on save/load. The sibling `SourceMatchTermination`
already round-trips its `sources` field correctly.

Add `sources` to the config model and serialize/restore it in
`_to_config`/`_from_config`, with a regression test covering both the
sources-restricted and unrestricted cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@ErenAta16 ErenAta16 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the round-trip test — passes for both the sources-restricted and unrestricted cases. Worth noting this brings TextMentionTermination in line with SourceMatchTermination, which the PR description says already round-trips sources correctly — so this was an inconsistency between two conceptually similar termination conditions rather than a one-off oversight, which matches what I'd expect from how these config classes tend to drift when a field gets added to the runtime class but not mirrored into _to_config/_from_config.

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.

2 participants