Skip to content

.NET: add workflow agent tool call message filtering#6882

Open
Oxygen56 wants to merge 1 commit into
microsoft:mainfrom
Oxygen56:fix-workflow-agent-tool-call-filter
Open

.NET: add workflow agent tool call message filtering#6882
Oxygen56 wants to merge 1 commit into
microsoft:mainfrom
Oxygen56:fix-workflow-agent-tool-call-filter

Conversation

@Oxygen56

@Oxygen56 Oxygen56 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

Fixes #6874.

When a workflow is hosted as an AIAgent, internal tool-call messages from nested agent execution can be surfaced in the hosted agent response. If that response is passed to another agent, the downstream provider can receive FunctionCallContent / FunctionResultContent for tool calls it did not issue and reject the request.

Description & Review Guide

  • What are the major changes?
    • Adds a non-breaking AsAIAgent(filterToolCallMessages: true, ...) overload.
    • Carries the option into WorkflowHostAgent / WorkflowSession.
    • Filters FunctionCallContent and FunctionResultContent from streamed agent response updates, aggregated agent response messages, and workflow output chat messages before they are surfaced by the hosted workflow agent.
    • Keeps the default behavior unchanged.
  • What is the impact of these changes?
    • Existing callers continue to see tool-call content unless they opt in.
    • Opted-in hosted workflow agents expose regular response content without internal tool-call IDs.
  • What do you want reviewers to focus on?
    • Whether the option should apply to all hosted workflow chat outputs handled here, or only the AgentResponseUpdateEvent path.
    • The overload shape chosen to preserve the existing public signature.

Related Issue

Fixes #6874

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings July 2, 2026 11:39
@giles17 giles17 added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Jul 2, 2026
@Oxygen56 Oxygen56 marked this pull request as ready for review July 2, 2026 11:39

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

Adds an opt-in switch to the .NET workflow-hosted agent surface to filter tool-call transcript content (function call/result contents) from surfaced messages, with unit coverage to validate default vs filtered behavior.

Changes:

  • Introduces filterToolCallMessages option on Workflow.AsAIAgent(...) and threads it through WorkflowHostAgentWorkflowSession.
  • Implements filtering in WorkflowSession so FunctionCallContent / FunctionResultContent are removed from streamed updates and message-derived updates.
  • Adds smoke tests covering default behavior (preserves tool call contents) and filtered behavior (removes tool call contents while preserving text).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs Adds test workflows and assertions validating tool-call content preservation vs filtering in both streaming and non-streaming runs.
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowSession.cs Implements the core filtering logic and applies it when yielding AgentResponseUpdates from workflow events.
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostingExtensions.cs Adds a new AsAIAgent overload exposing the filterToolCallMessages toggle.
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs Propagates filterToolCallMessages into created/deserialized WorkflowSessions.
dotnet/src/Microsoft.Agents.AI.Workflows/Futures.cs Updates XML doc cref to a specific AsAIAgent overload signature.

/// </para>
/// <para>
/// <b>Interaction with <see cref="WorkflowHostingExtensions.AsAIAgent"/>.</b> When this flag
/// <b>Interaction with <see cref="WorkflowHostingExtensions.AsAIAgent(Workflow, string?, string?, string?, IWorkflowExecutionEnvironment?, bool, bool)"/>.</b> When this flag
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

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Feature]: A filterToolCallMessages: bool option on AsAIAgent()

3 participants