Skip to content

.NET: Added support for polymorphic type as workflow output#4485

Open
peibekwe wants to merge 3 commits intomainfrom
peibekwe/workflow-output-bugfix
Open

.NET: Added support for polymorphic type as workflow output#4485
peibekwe wants to merge 3 commits intomainfrom
peibekwe/workflow-output-bugfix

Conversation

@peibekwe
Copy link
Contributor

@peibekwe peibekwe commented Mar 5, 2026

Description

Added support for polymorphic type as workflow output and enable executors to return instance of derived class which inherits from the base class.

Fixes #4134

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@peibekwe peibekwe self-assigned this Mar 5, 2026
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Mar 5, 2026
@github-actions github-actions bot changed the title Added support for polymorphic type as workflow output .NET: Added support for polymorphic type as workflow output Mar 5, 2026
@peibekwe peibekwe marked this pull request as ready for review March 5, 2026 00:48
Copilot AI review requested due to automatic review settings March 5, 2026 00:48
Copy link
Contributor

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

Adds support for workflow outputs to be validated polymorphically so executors can return derived instances when their declared workflow output type is a base class (fixing issue #4134).

Changes:

  • Update executor output validation to accept derived types for declared yield/output types.
  • Add unit tests covering derived, multi-level derived, exact-type, and unrelated-type output behaviors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs Adjusts CanOutput logic to validate outputs polymorphically (base-class inheritance).
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/PolymorphicOutputTests.cs Adds regression coverage for derived outputs and ensures unrelated outputs still fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: InvalidOperationException when returning a derived type as workflow output

3 participants