Skip to content

.NET: [Bug]: Exception in workflow, that is added as agent, results in json serialisation error message instead of exception #8012

Description

Description

Have a workflow that throws an exception. Have the workflow registered as an agent.

Call the agent. Instead of the actual exception being logged, it results in a JSON serialisation error towards the user.

This was an issue in Semantic Kernel already: microsoft/semantic-kernel#10708

Code Sample

var workflowAsAgent = builder
    .AddWorkflow("super-agent", CreateWorkflowDelegate)
    .AddAsAIAgent();  // Now the workflow can be used as an agent

Error Messages / Stack Traces

Internal (swallowed) exception:

Exception has occurred: CLR/System.InvalidOperationException
Exception thrown: 'System.InvalidOperationException' in Microsoft.Agents.AI.Workflows.dll: 'Executor 'AggregatorExecutor' cannot send messages of type 'MySolution.Workflow.RawAggregate'.'
   at Microsoft.Agents.AI.Workflows.InProc.InProcessRunnerContext.<SendMessageAsync>d__30.MoveNext() in /home/vsts/work/1/s/agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs:line 235

What the user sees:

Serialization and deserialization of 'System.Reflection.MethodBase' instances is not supported. Path: $.TargetSite. (Code: execution_error)

Image

Package Versions

    <PackageVersion Include="Microsoft.Agents.AI" Version="1.20.0" />
    <PackageVersion Include="Microsoft.Agents.AI.A2A" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.DevUI" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.A2A" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.A2A.AspNetCore" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.AGUI.AspNetCore" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.AspNetCore" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.OpenAI" Version="1.20.0-alpha.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Workflows" Version="1.20.0" />
    <PackageVersion Include="Microsoft.Agents.AI.Workflows.Generators" Version="1.20.0" />

.NET Version

.Net 10.0

Additional Context

No response

Metadata

Metadata

Labels

.NETUsage: [Issues, PRs], Target: .NetreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowworkflowsUsage: [Issues, PRs], Target: Workflows

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions