Skip to content

.NET: [Bug]: Workflow telemetry crashes on CodeInterpreterToolCallContent when Workflow EnableSensitiveData = true #5066

@brandonh-msft

Description

@brandonh-msft

Description

When a workflow-enabled .NET agent uses a hosted codeInterpreter tool and workflow OpenTelemetry has EnableSensitiveData = true, the workflow crashes while emitting telemetry for the inter-executor message.

What happened:

  • A hosted Foundry agent routed a request to a local declarative agent.
  • The local declarative agent used codeInterpreter successfully.
  • As the workflow continued, Microsoft.Agents.AI.Workflows.Observability.WorkflowTelemetryContext attempted to serialize a message containing Microsoft.Extensions.AI.CodeInterpreterToolCallContent.
  • The workflow failed with System.NotSupportedException because that runtime type is not supported by the workflow telemetry serializer for the polymorphic base type Microsoft.Extensions.AI.AIContent.

Expected behavior:

  • Workflow telemetry should be able to serialize code-interpreter-related AIContent payloads when sensitive data logging is enabled, or gracefully fall back to a safe representation without failing workflow execution.
  • This should not require callers to mutate or drop code interpreter content from the actual message stream.

Steps to reproduce:

  1. Build a workflow using Microsoft.Agents.AI.Workflows with .WithOpenTelemetry(o => o.EnableSensitiveData = true, ...).
  2. Use a declarative/local agent that has - kind: codeInterpreter in its tool list.
  3. Let the workflow route a turn where the local agent invokes code interpreter.
  4. Observe the workflow fail during telemetry emission.

Current workaround:

  • Set workflow telemetry EnableSensitiveData = false for the workflow layer. This avoids the crash, but it also removes raw workflow message payloads from workflow telemetry.
  • Agent/tool telemetry can still remain sensitive-data-enabled separately.

Code Sample

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();
kind: Prompt
name: local-data-agent
tools:
  - kind: codeInterpreter

Error Messages / Stack Traces

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)

Package Versions

  • Microsoft.Agents.AI.AzureAI: 1.0.0-rc4
  • Microsoft.Agents.AI.Declarative: 1.0.0-rc4
  • Microsoft.Agents.AI.Workflows: 1.0.0-rc4
  • Microsoft.Agents.AI.AzureAI.Persistent: 1.0.0-preview.260311.1
  • Azure.AI.Projects: 2.0.0-beta.1
  • OpenAI: 2.9.0

.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 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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions