Skip to content

.NET: Alliscode/fix declarative autosend output#7217

Open
alliscode wants to merge 3 commits into
microsoft:mainfrom
alliscode:alliscode/fix-declarative-autosend-output
Open

.NET: Alliscode/fix declarative autosend output#7217
alliscode wants to merge 3 commits into
microsoft:mainfrom
alliscode:alliscode/fix-declarative-autosend-output

Conversation

@alliscode

Copy link
Copy Markdown
Member

This pull request introduces improvements to how message IDs are assigned and handled for streaming agent responses, ensuring that all related updates share a stable identifier and that completion events do not duplicate content. It also adds and updates tests to verify the correct assignment and propagation of message and response IDs, and corrects the emission of completion events in streaming workflows.

Stable Message ID Assignment and Propagation:

  • Streaming agent response updates now receive a stable MessageId that is reused for all updates belonging to the same logical message, ensuring consistent identification across updates. This applies both in AgentProviderExtensions.InvokeAgentAsync and AIAgentHostExecutor. [1] [2]

  • The SendActivityExecutor now assigns both MessageId and ResponseId to messages and updates, and ensures these are correctly propagated through all related events.

Workflow Session and Completion Event Handling:

  • The workflow session tracks streamed message IDs and, when emitting completion events, avoids duplicating content that has already been streamed. Instead, it emits a completion event with empty contents for observability. [1] [2] [3]

Test Enhancements and Coverage:

  • Unit tests have been updated and expanded to verify that all streaming updates for a message share the same MessageId, and that response events reference the correct IDs. New tests also ensure that auto-send behavior is correctly honored and that completion events are emitted as expected without content duplication. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Test Infrastructure and Mocking:

  • Test agent and provider implementations have been adjusted to better simulate missing MessageId scenarios and to validate the new stable message ID logic.

Minor Code Cleanups:

  • Added missing using System; directives in relevant files. [1] [2]

These changes collectively improve the reliability and clarity of agent response streaming, making it easier to track and correlate updates and final responses throughout the workflow system.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Restore completed responses for workflow-conversation agents while preventing hosted workflow adapters from materializing streamed responses twice.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c2d86826-ead0-40bc-b84b-a513ac4d325f
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c2d86826-ead0-40bc-b84b-a513ac4d325f
Copilot AI review requested due to automatic review settings July 20, 2026 15:00
@giles17 giles17 added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Jul 20, 2026
@github-actions github-actions Bot changed the title Alliscode/fix declarative autosend output .NET: Alliscode/fix declarative autosend output Jul 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves streaming response correlation in the .NET workflow stack by (1) generating stable MessageIds for streaming updates that lack them, and (2) avoiding duplicated content when forwarding completion events after content was already streamed.

Changes:

  • Assign stable MessageId values across related streaming AgentResponseUpdates in AIAgentHostExecutor and declarative AgentProviderExtensions.
  • Track streamed message IDs in WorkflowSession and suppress duplicate completion content, while still emitting an “observable” completion event with empty contents.
  • Expand/update unit tests to validate stable MessageId propagation, auto-send behavior, and completion-event emission without duplication.
Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs Updates smoke tests to assert completion events remain observable without duplicating streamed text; adds scenarios around suppression boundaries.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AIAgentHostExecutorTests.cs Adds coverage ensuring the executor assigns one stable MessageId across streaming updates and propagates it to the completed response.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/SendActivityExecutorTest.cs Verifies SendActivityExecutor propagates MessageId/ResponseId consistently into update + response events.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/InvokeAzureAgentExecutorTest.cs Adds tests for autoSend defaulting to true and honoring explicit values for event emission.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Extensions/AgentProviderExtensionsTest.cs Adjusts test updates to use ChatResponseUpdate and asserts stable generated MessageId across events/response.
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowSession.cs Tracks streamed message IDs and avoids duplicating already-streamed message content during completion forwarding.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Generates stable MessageId for streaming updates (per response/role) when missing.
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/SendActivityExecutor.cs Ensures SendActivity emits update + response with consistent MessageId/ResponseId.
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Extensions/AgentProviderExtensions.cs Generates stable MessageId for declarative streaming updates when missing.

Review details

  • Files reviewed: 9/9 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 5 | Confidence: 89% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by alliscode's agents

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c2d86826-ead0-40bc-b84b-a513ac4d325f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants