Thanks to visit codestin.com
Credit goes to github.com

Skip to content

.NET: feat: Implement message filtering to exclude non-portable content typ…#5410

Merged
lokitoth merged 10 commits into
microsoft:mainfrom
tarockey:feature/dotnet-workflow-agent-message-filters
May 5, 2026
Merged

.NET: feat: Implement message filtering to exclude non-portable content typ…#5410
lokitoth merged 10 commits into
microsoft:mainfrom
tarockey:feature/dotnet-workflow-agent-message-filters

Conversation

@tarockey

Copy link
Copy Markdown
Contributor

This is a draft PR, happy to close it or modify based on discussion.

Motivation and Context

Closes #5338

When a Foundry server-side agent with server-side tools (MCP, web search, code interpreter, Fabric Data Agent, etc.) runs as part of a multi-agent workflow, the Responses API returns output-only items like mcp_list_tools, reasoning, web_search_call, and fabric_dataagent_preview_call in its response. These items were being forwarded as-is to the next agent in the workflow via context.SendMessageAsync(response.Messages...).

When the receiving agent sent its own Responses API request, the Microsoft.Extensions.AI library round-tripped these items via ChatMessage.RawRepresentation, including them as input items. The Responses API rejected the request with invalid_payload / invalid_request_error because these are output-only item types that are not valid as input.

This makes multi-agent workflows involving Foundry server-side agents with server-side tools unusable.

Description

Adds FilterForwardableMessages to AIAgentHostExecutor that sanitizes response messages before forwarding them into the workflow. The filter does two things:

  1. Strips non-portable content: Only content items with recognized portable types (TextContent, DataContent, UriContent, FunctionCallContent, FunctionResultContent, ToolApprovalRequestContent, ToolApprovalResponseContent, HostedFileContent, ErrorContent) are retained. Server-side artifacts like reasoning tokens and provider-specific tool call items are dropped.

  2. Strips RawRepresentation: New ChatMessage objects are constructed without the provider-specific RawRepresentation, preventing the Microsoft.Extensions.AI library from round-tripping the original output-only items (e.g., mcp_list_tools) as input to the next agent.

Messages that contain zero portable content items after filtering are dropped entirely.

What is NOT affected:

  • Streaming AgentResponseUpdates yielded via YieldOutputAsync — these fire before the filter and retain full fidelity
  • AgentResponse events emitted via EmitAgentResponseEvents — unaffected
  • DurableTask checkpoint serialization — RawRepresentation is [JsonIgnore] and was never persisted
  • AIContent.RawRepresentation on individual content items — preserved; only the message-level RawRepresentation is stripped

Known follow-up: HandoffAgentExecutor has a similar unfiltered path at sharedState.Conversation.AddMessages(result.Response.Messages) that would need an equivalent fix if Foundry server-side agents participate in handoff workflows.

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.

Copilot AI review requested due to automatic review settings April 21, 2026 19:59
@moonbox3 moonbox3 added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Apr 21, 2026
@github-actions github-actions Bot changed the title DRAFT feat: Implement message filtering to exclude non-portable content typ… .NET: DRAFT feat: Implement message filtering to exclude non-portable content typ… Apr 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses a .NET Workflows interoperability bug where provider-specific, output-only Responses API items (e.g., reasoning/tool call artifacts) were being forwarded between agents and then round-tripped as invalid input, causing invalid_payload errors when chaining Foundry-backed agents.

Changes:

  • Added a message sanitization step in AIAgentHostExecutor to forward only “portable” AIContent types and to strip ChatMessage.RawRepresentation.
  • Dropped messages that become empty after content filtering (at the message level).
  • Added unit tests covering filtering of non-portable content and stripping of RawRepresentation.

Reviewed changes

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

File Description
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Filters forwarded response messages to remove output-only artifacts and strips message-level RawRepresentation before forwarding.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AIAgentHostExecutorTests.cs Adds tests validating content filtering behavior and RawRepresentation stripping for forwarded messages.

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated
@tarockey tarockey marked this pull request as ready for review April 24, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows

Projects

Status: Community PR

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Foundry Responses API based agents fail in Workflows when Foundry hosted tools are used.

5 participants