SingleThreadedAgentRuntime to use subclass check for factory_wrapper instead of equality#6731
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the agent factory in SingleThreadedAgentRuntime to accept subclasses of ChatAgentContainer by replacing a strict type equality check with an isinstance check.
- Switched
type_func_alias(agent_instance) != expected_classtonot isinstance(agent_instance, expected_class) - Continues to raise a
ValueErroronly when the instance is not an instance or subclass of the expected class
Comments suppressed due to low confidence (1)
python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py:906
- Add a unit test that verifies a subclass of the expected class is accepted by this check and that non-matching types still trigger the error.
if expected_class is not None and not isinstance(agent_instance, expected_class):
|
this is because participant_factory is hard coded in BaseGroupChat._create_participant_factory(_base_group_chat.py#L146) so that when it called by singlethread runtime, the agent factory requiement does not satified because it has to be match exactly as ChatAgentContainer |
Co-authored-by: Copilot <[email protected]>
|
@ZenWayne I made some changes please review. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6731 +/- ##
==========================================
+ Coverage 76.42% 80.44% +4.01%
==========================================
Files 343 237 -106
Lines 20982 17864 -3118
Branches 406 0 -406
==========================================
- Hits 16035 14370 -1665
+ Misses 4674 3494 -1180
+ Partials 273 0 -273
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
LGTM, Thanks for the merge! |
The agent factory in SingleThreadedAgentRuntime does not support customized class that inherited from ChatAgentContainer
Now change the judge expression to
if expected_class is not None and not isinstance(agent_instance, expected_class):
raise ValueError("Factory registered using the wrong type.")
instead of exactly match
Why are these changes needed?
To support Customized ChatAgentContainer that can ajust the logic after an event or a message published by ChatAgentContainer, which achieved by inheriting ChatAgentContainer
Related issue number
Resolves #6730
Checks