Skip to content

Polymorphism issue: CodeExecutorAgent calls classmethod via concrete class in on_messages_stream #7205

@Momo-Not-Emo

Description

@Momo-Not-Emo

What happened?

Describe the bug
In CodeExecutorAgent.on_messages_stream, the class method _reflect_on_code_block_results_flow is invoked via the concrete class name:

async for reflection_response in CodeExecutorAgent._reflect_on_code_block_results_flow(
system_messages=system_messages,
model_client=model_client,
model_client_stream=model_client_stream,
model_context=model_context,
agent_name=agent_name,
inner_messages=inner_messages,
):
yield reflection_response # Last reflection_response is of type Response so it will finish the routine

This introduces a static binding to CodeExecutorAgent and breaks polymorphism for subclasses that override _reflect_on_code_block_results_flow.

This appears to be the same pattern and root cause as a previously reported polymorphism bug:

To Reproduce
Create a child class of CodeExecutorAgent and override method _reflect_on_code_block_results_flow. When calling on_messages_stream on an agent of the custom class, it still calls the parent class's methods.

Expected behavior
The override methods should be be called.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python dev (main branch)

Other library version.

No response

Model used

No response

Model provider

None

Other model provider

No response

Python version

None

.NET version

None

Operating system

None

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions