return new WorkflowBuilder(foundryExecutor)
.AddEdge(foundryExecutor, bindings.FoundryMessageRouter)
.AddEdge(foundryExecutor, bindings.FoundryMessagesRouter)
.AddEdge(bindings.FoundryMessageRouter, localExecutor)
.AddEdge(bindings.FoundryMessagesRouter, localExecutor)
.AddEdge(bindings.FoundryMessageRouter, foundryExecutor)
.AddEdge(bindings.FoundryMessagesRouter, foundryExecutor)
.AddEdge(localExecutor, bindings.LocalMessageRouter)
.AddEdge(localExecutor, bindings.LocalMessagesRouter)
.AddEdge(bindings.LocalMessageRouter, foundryExecutor)
.AddEdge(bindings.LocalMessagesRouter, foundryExecutor)
.WithOutputFrom(bindings.FoundryMessageRouter, bindings.FoundryMessagesRouter)
.WithOpenTelemetry(o =>
{
o.EnableSensitiveData = true;
}, Activities.AppActivitySource)
.Build();
Workflow error: WorkflowErrorEvent System.Reflection.TargetInvocationException: Error invoking handler for Microsoft.Agents.AI.Workflows.TurnToken
---> System.NotSupportedException: Runtime type 'Microsoft.Extensions.AI.CodeInterpreterToolCallContent' is not supported by polymorphic type 'Microsoft.Extensions.AI.AIContent'. Path: $.Contents.
---> System.NotSupportedException: Runtime type 'Microsoft.Extensions.AI.CodeInterpreterToolCallContent' is not supported by polymorphic type 'Microsoft.Extensions.AI.AIContent'.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_RuntimeTypeNotSupported(Type baseType, Type runtimeType)
at System.Text.Json.Serialization.Metadata.PolymorphicTypeResolver.TryGetDerivedJsonTypeInfo(Type runtimeType, JsonTypeInfo& jsonTypeInfo, Object& typeDiscriminator)
at System.Text.Json.Serialization.JsonConverter.ResolvePolymorphicConverter(Object value, JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Converters.IEnumerableDefaultConverter`2.OnWriteResume(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Converters.ListOfTConverter`2.OnWriteResume(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, Exception innerException)
at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue)
at System.Text.Json.JsonSerializer.WriteStringAsObject(Object value, JsonTypeInfo jsonTypeInfo)
at Microsoft.Agents.AI.Workflows.Observability.WorkflowTelemetryContext.SerializeForTelemetry(Object value)
at Microsoft.Agents.AI.Workflows.Observability.WorkflowTelemetryContext.StartMessageSendActivity(String sourceId, String targetId, Object message)
at Microsoft.Agents.AI.Workflows.InProc.InProcessRunnerContext.SendMessageAsync(String sourceId, Object message, String targetId, CancellationToken cancellationToken)
This was reproduced in a Discord bot workflow that coordinates a hosted Foundry agent and a local declarative agent. The local agent has both function tools and a hosted codeInterpreter tool.
The code interpreter execution itself works. The crash occurs only when workflow telemetry tries to serialize the workflow message payload containing CodeInterpreterToolCallContent.
From a consumer perspective this looks like an SDK issue in workflow observability serialization, not in the agent/tool execution path.
Description
When a workflow-enabled .NET agent uses a hosted
codeInterpretertool and workflow OpenTelemetry hasEnableSensitiveData = true, the workflow crashes while emitting telemetry for the inter-executor message.What happened:
codeInterpretersuccessfully.Microsoft.Agents.AI.Workflows.Observability.WorkflowTelemetryContextattempted to serialize a message containingMicrosoft.Extensions.AI.CodeInterpreterToolCallContent.System.NotSupportedExceptionbecause that runtime type is not supported by the workflow telemetry serializer for the polymorphic base typeMicrosoft.Extensions.AI.AIContent.Expected behavior:
AIContentpayloads when sensitive data logging is enabled, or gracefully fall back to a safe representation without failing workflow execution.Steps to reproduce:
Microsoft.Agents.AI.Workflowswith.WithOpenTelemetry(o => o.EnableSensitiveData = true, ...).- kind: codeInterpreterin its tool list.Current workaround:
EnableSensitiveData = falsefor the workflow layer. This avoids the crash, but it also removes raw workflow message payloads from workflow telemetry.Code Sample
Error Messages / Stack Traces
Package Versions
.NET Version
.NET 10
Additional Context
This was reproduced in a Discord bot workflow that coordinates a hosted Foundry agent and a local declarative agent. The local agent has both function tools and a hosted
codeInterpretertool.The code interpreter execution itself works. The crash occurs only when workflow telemetry tries to serialize the workflow message payload containing
CodeInterpreterToolCallContent.From a consumer perspective this looks like an SDK issue in workflow observability serialization, not in the agent/tool execution path.