Skip to content

Fix output task messages 6150 #6678

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 14 commits into
base: main
Choose a base branch
from

Conversation

tejas-dharani
Copy link
Contributor

Why are these changes needed?

The existing run_stream methods used fragile count-based logic (count <= len(task)) to skip task messages during streaming. This approach was brittle and broke when team structure changed or task composition varied, particularly affecting SocietyOfMindAgent's ability to properly encapsulate inner team messages.

This PR adds an output_task_messages parameter to run_stream methods to provide explicit control over task message inclusion in streams, replacing the fragile count-based logic with robust message filtering.

Related issue number

Closes #6150

Checks

…on guide- Fix version format from 0.4.0-dev-1 to 0.4.0-dev.1 for all packages- Remove reference to non-existent Microsoft.AutoGen.Extensions package- Add correct extension packages: Aspire, MEAI, and SemanticKernel- Fix typo: RuntimeGatewway -> RuntimeGateway- Improve documentation structure with clear section headersFixes microsoft#6244
Fix issue microsoft#6277 where TextMessage was used but not imported in three code cells
of the custom agents documentation, causing NameError when users run the examples.

Changes:
- Add TextMessage to imports in ArithmeticAgent section
- Add TextMessage to imports in GeminiAssistantAgent section
- Add TextMessage to imports in Declarative GeminiAssistantAgent section

The CountDownAgent section already had the correct import.

Fixes microsoft#6277
…ic in run_stream. Replaces brittle count-based task message filtering with explicit output_task_messages parameter. Enables proper SocietyOfMindAgent encapsulation while maintaining backward compatibility.
- Set output_task_messages default to False for backward compatibility
- Fix duplicate task message logic in base_group_chat.py
- Update 20+ streaming tests to handle task message offset
- Correct protocol definition in _task.py

All test suites now pass (165 tests). Fixes regression from previous commit.
@victordibia
Copy link
Collaborator

@tejas-dharani ,
For PRs like this with breaking changes, can we take the following approach

  • Scope all changes to the focus of the PR title (there are dotnet related things here)
  • First discuss the design, side effects etc in the original issue
  • Second, can you confirm that you have written tests and run the entire CI to verify that there are NO errors associated with your changes? ie you have run poe check as indicated here

There is a chance that future PRs that do not follow the above might be closed without review.

@tejas-dharani
Copy link
Contributor Author

tejas-dharani commented Jun 16, 2025

@tejas-dharani , For PRs like this with breaking changes, can we take the following approach

  • Scope all changes to the focus of the PR title (there are dotnet related things here)
  • First discuss the design, side effects etc in the original issue
  • Second, can you confirm that you have written tests and run the entire CI to verify that there are NO errors associated with your changes? ie you have run poe check as indicated here

There is a chance that future PRs that do not follow the above might be closed without review.

Hi @victordibia,
Thanks for the feedback! To confirm:

Separate branches: Created individual branches for each issue
Design discussion: Will discuss in original issues going forward
Testing: Written tests, ran full CI poe check twice
Documentation: Read contributing.md and python/readme.md

Appreciate the guidance on the workflow!

@ekzhu ekzhu requested a review from Copilot June 17, 2025 23:49
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 replaces brittle count-based logic for filtering task messages in streaming methods with an explicit output_task_messages parameter, making message inclusion more robust across varying team structures.

  • Added output_task_messages flag to run_stream in team, task, and agent implementations
  • Updated SocietyOfMindAgent and BaseChatAgent to leverage the new flag
  • Revised tests and documentation to align with the new parameter behavior

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/custom-agents.ipynb Imported TextMessage for examples
python/packages/autogen-agentchat/tests/test_society_of_mind_agent.py Added tests for output_task_messages parameter and its default behavior
python/packages/autogen-agentchat/tests/test_group_chat.py Adjusted result indexing to skip task messages in streams
python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py Introduced output_task_messages parameter and message filtering logic
python/packages/autogen-agentchat/src/autogen_agentchat/base/_task.py Documented output_task_messages argument in run_stream
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.py Updated inner team calls to use output_task_messages=False
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py Added output_task_messages argument and conditional yields
docs/dotnet/core/installation.md Updated .NET package versions and added extension package listings


# Should have exactly one task message (from the outer level)
assert len(task_messages_in_soma) == 1
assert len(inner_task_messages_in_soma) == 1
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

The test description indicates that inner task messages should not be forwarded, but this assertion expects one inner task message. Adjust the expected count to 0 or update the assertion to match the intended behavior.

Suggested change
assert len(inner_task_messages_in_soma) == 1
assert len(inner_task_messages_in_soma) == 0

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have solved the issue.

# Skip adding task messages to output_messages again if they were already added initially
if output_task_messages and received_messages_count < task_messages_count:
received_messages_count += 1
yield message
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

This block yields the same task messages a second time when output_task_messages is true, causing duplicates. Remove the redundant yield message to prevent duplicate streaming of task messages.

Suggested change
yield message

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have solved the issue.

@@ -263,21 +263,22 @@ async def test_round_robin_group_chat(runtime: AgentRuntime | None) -> None:

# Test streaming.
model_client.reset()
index = 0
stream_index = 0
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

[nitpick] The variable stream_index is introduced but never used. Consider removing it to reduce noise and improve readability.

Suggested change
stream_index = 0

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have solved the issue.

…stallation guide- Fix version format from 0.4.0-dev-1 to 0.4.0-dev.1 for all packages- Remove reference to non-existent Microsoft.AutoGen.Extensions package- Add correct extension packages: Aspire, MEAI, and SemanticKernel- Fix typo: RuntimeGatewway -> RuntimeGateway- Improve documentation structure with clear section headersFixes microsoft#6244"

This reverts commit 6d9fb2e.
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.

Adding a output_task_messages to run_stream methods to avoid messages in task are included.
2 participants