Skip to content

add customized ChatAgentContainer support #6731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZenWayne
Copy link
Contributor

@ZenWayne ZenWayne commented Jun 29, 2025

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

#6730

Checks

@ekzhu ekzhu requested a review from Copilot June 29, 2025 15:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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_class to not isinstance(agent_instance, expected_class)
  • Continues to raise a ValueError only 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):

Comment on lines 907 to 908
raise ValueError("Factory registered using the wrong type.")

Copy link
Preview

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

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

Include expected and actual types in the ValueError to aid debugging. For example: raise ValueError(f"Factory registered using the wrong type: expected {expected_class.__name__}, got {type(agent_instance).__name__}.").

Suggested change
raise ValueError("Factory registered using the wrong type.")
raise ValueError(
f"Factory registered using the wrong type: expected {expected_class.__name__}, got {type(agent_instance).__name__}."
)

Copilot uses AI. Check for mistakes.

@ZenWayne
Copy link
Contributor Author

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
Related function call

  1. BaseGroupChat._create_participant_factory(_base_group_chat.py#L146)
  2. BaseGroupChat._init(_base_group_chat.py#L167)
  3. factory called(_single_threaded_agent_runtime.py#L906)

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.

1 participant