Skip to content

Conversation

@lokitoth
Copy link
Member

@lokitoth lokitoth commented Dec 10, 2025

Motivation and Context

When hosted using AsAgent(), Workflows were not exposing inner errors coming as Exceptions (through raised WorkflowErrorEvent)

Description

The fix is to convert the Message property to an ErrorContent on the way out, rather than rely on the default "empty update" to collect the raw event.

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.

When hosted using .AsAgent(), Workflows were not exposing inner errors coming as Exceptions (through the WorkflowErrorEvent)

The fix is to convert their message to an ErrorContent on the way out, rather than rely on the default "empty update" to collect the raw event.
Copilot AI review requested due to automatic review settings December 10, 2025 20:36
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Dec 10, 2025
@github-actions github-actions bot changed the title fix: Expose WorkflowErrorEvent as ErrorContent .NET: fix: Expose WorkflowErrorEvent as ErrorContent Dec 10, 2025
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

This PR fixes a bug where workflows hosted using .AsAgent() were not exposing inner errors coming from exceptions through the WorkflowErrorEvent. The fix converts error events to ErrorContent objects so they can be properly surfaced to consumers.

Key Changes:

  • Added an Exception property to WorkflowErrorEvent for direct access to the underlying exception
  • Modified WorkflowThread.CreateUpdate to accept a raw representation parameter
  • Added handling for WorkflowErrorEvent in workflow execution to convert exceptions to ErrorContent

Reviewed changes

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

File Description
WorkflowErrorEvent.cs Adds public Exception property to expose the underlying exception data
WorkflowThread.cs Updates CreateUpdate signature to include raw representation and adds error event handling to convert exceptions to ErrorContent
WorkflowHostSmokeTests.cs Adds comprehensive smoke tests validating both direct error content streaming and exception-to-error-content conversion

return new WorkflowBuilder(agent).Build();
}

private async static Task InvokeAsAgentAndProcessResponseAsync(Workflow workflow)
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The method signature does not follow the C# coding guideline for async methods. Async methods that return Task should have the 'Async' suffix in their name.

Copilot generated this review using guidance from repository custom instructions.

private async static Task InvokeAsAgentAndProcessResponseAsync(Workflow workflow)
{
List<AgentRunResponseUpdate> updates = await workflow.AsAgent("WorkflowAgent")
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

According to the C# coding guidelines, prefer defining variables using types rather than var to help users understand the types involved.

Copilot generated this review using guidance from repository custom instructions.
.ToListAsync();

bool hadErrorContent = false;
foreach (AgentRunResponseUpdate update in updates)
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

According to the C# coding guidelines for unit tests, Arrange, Act, and Assert comments should be added for each test to clearly separate the test phases.

Copilot generated this review using guidance from repository custom instructions.
}
}

private static Workflow CreateWorkflow(bool failByThrowing)
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

According to the C# coding guidelines, prefer defining variables using types rather than var to help users understand the types involved.

Copilot generated this review using guidance from repository custom instructions.
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.

4 participants