Skip to content

fix: use type(self) for polymorphic dispatch in CodeExecutorAgent#7437

Open
r266-tech wants to merge 2 commits intomicrosoft:mainfrom
r266-tech:fix/polymorphism-code-executor-agent
Open

fix: use type(self) for polymorphic dispatch in CodeExecutorAgent#7437
r266-tech wants to merge 2 commits intomicrosoft:mainfrom
r266-tech:fix/polymorphism-code-executor-agent

Conversation

@r266-tech
Copy link
Copy Markdown

@r266-tech r266-tech commented Mar 22, 2026

Fixes #7205

The on_messages_stream method in CodeExecutorAgent called _reflect_on_code_block_results_flow via the concrete class name, breaking polymorphism for subclasses that override this method.

Change

python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py:

Before After
CodeExecutorAgent._reflect_on_code_block_results_flow(...) type(self)._reflect_on_code_block_results_flow(...)

This matches the fix already applied to AssistantAgent for the same pattern (issue #5953).

Test

Added test_subclass_reflection_override_is_called in test_code_executor_agent.py:

  • Creates a _CustomAgent subclass with a tracking override of _reflect_on_code_block_results_flow
  • Runs on_messages_stream end-to-end via ReplayChatCompletionClient
  • Asserts the subclass override is dispatched, not the base-class method

Fixes microsoft#7205

The on_messages_stream method called CodeExecutorAgent._reflect_on_code_block_results_flow
via the concrete class name, breaking polymorphism for subclasses that override this method.

Changed to type(self)._reflect_on_code_block_results_flow to ensure the correct
subclass implementation is called, matching the pattern used in AssistantAgent
(fix for microsoft#5953).
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.

Polymorphism issue: CodeExecutorAgent calls classmethod via concrete class in on_messages_stream

1 participant