-
Notifications
You must be signed in to change notification settings - Fork 892
.NET: fix: Expose WorkflowErrorEvent as ErrorContent #2762
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
base: main
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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
Exceptionproperty toWorkflowErrorEventfor direct access to the underlying exception - Modified
WorkflowThread.CreateUpdateto accept a raw representation parameter - Added handling for
WorkflowErrorEventin workflow execution to convert exceptions toErrorContent
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) |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
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.
|
|
||
| private async static Task InvokeAsAgentAndProcessResponseAsync(Workflow workflow) | ||
| { | ||
| List<AgentRunResponseUpdate> updates = await workflow.AsAgent("WorkflowAgent") |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
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.
| .ToListAsync(); | ||
|
|
||
| bool hadErrorContent = false; | ||
| foreach (AgentRunResponseUpdate update in updates) |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
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.
| } | ||
| } | ||
|
|
||
| private static Workflow CreateWorkflow(bool failByThrowing) |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
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.
Motivation and Context
When hosted using
AsAgent(),Workflows were not exposing inner errors coming asExceptions (through raisedWorkflowErrorEvent)Description
The fix is to convert the
Messageproperty to anErrorContenton the way out, rather than rely on the default "empty update" to collect the raw event.Contribution Checklist
Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.