Add Optional Control for Participant Auto-Linking in MultimodalAgent #971
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.
Overview
This PR introduces a new feature to control the automatic linking of participants to the MultimodalAgent when they join a room or when the agent starts. By default, the agent automatically links the first participant it encounters, but this behavior may not always be desirable for certain use cases, such as when developers want to manage which participant is linked manually. The change is designed to maintain backward compatibility while providing additional flexibility.
Key Changes
auto_link_on_connect Flag:
Introduced an auto_link_on_connect flag (default: True) to allow developers to enable or disable the automatic linking of participants when they connect to a room.
If auto_link_on_connect is set to False, the agent will only link participants when explicitly requested via the _link_participant method.
The flag is respected in both the start method (during agent initialization) and in the _on_participant_connected method (when a new participant joins the room).
Modifications in start Method:The start method now checks the auto_link_on_connect flag before automatically linking participants upon agent startup. If the flag is disabled, the agent will log that auto-linking is disabled but will not automatically link any participant.
Modifications in
_on_participant_connected
: The participant connection handler (_on_participant_connected) now respects the auto_link_on_connect flag. If the flag is disabled, the method will not link the participant and will log this action for debugging purposes.Backward Compatibility
By default, the
auto_link_on_connect
flag is set to True, preserving the original functionality for existing users of the SDK who rely on automatic participant linking.The new flag only impacts users who explicitly set
auto_link_on_connect=False
, providing them with greater control over when participants are linked.Use Cases
This feature is useful in scenarios where an application needs more granular control over which participants the agent listens to and when this linking happens (e.g., for moderation purposes or custom workflows that require selective participant listening).
Testing:
Verified that the agent behaves as expected when
auto_link_on_connect
is True (default behavior).Verified that participants are not automatically linked when
auto_link_on_connect=False
and that manual linking via _link_participant still works as intended.Conclusion
This PR enhances the flexibility of the MultimodalAgent by allowing developers to decide when participants should be linked, without disrupting the original automatic behavior that other users rely on.