Skip to content

Add C# GroupChat tool approval sample for multi-agent orchestrations#3374

Merged
SergeyMenshykh merged 12 commits intomainfrom
copilot/add-csharp-sample-agent-approvals
Jan 27, 2026
Merged

Add C# GroupChat tool approval sample for multi-agent orchestrations#3374
SergeyMenshykh merged 12 commits intomainfrom
copilot/add-csharp-sample-agent-approvals

Conversation

Copy link
Contributor

Copilot AI commented Jan 22, 2026

Motivation and Context

Adds C# equivalent of the Python group_chat_builder_tool_approval.py sample to demonstrate human-in-the-loop approvals within multi-agent workflows.

Description

Implements a deployment workflow where QA and DevOps agents collaborate, with production deployment requiring human approval.

Implementation:

  • Program.cs - Two-phase workflow: run until approval needed, handle approval, resume
  • DeploymentGroupChatManager.cs - Custom speaker selection extending GroupChatManager using agent Name property for selection
  • Tools defined with ApprovalRequiredAIFunction wrapper for sensitive operations
  • Event handling for FunctionApprovalRequestContent during workflow execution
  • Solution Integration: Added project to agent-framework-dotnet.slnx solution file in /Samples/GettingStarted/Workflows/Agents/ folder
  • File Encoding: All C# source files use UTF-8 with BOM encoding as required by the repository's formatter

Key patterns demonstrated:

// Approval-required tool
new ApprovalRequiredAIFunction(AIFunctionFactory.Create(DeployToProduction))

// Custom speaker selection using agent Name property
protected override ValueTask<AIAgent> SelectNextAgentAsync(
    IReadOnlyList<ChatMessage> history, CancellationToken cancellationToken)
{
    AIAgent agent = this._agents.First(a => a.Name == "QAEngineer");
    return new ValueTask<AIAgent>(agent);
}

// Approval handling
FunctionApprovalRequestContent? approvalRequest = e.Update.Contents
    .OfType<FunctionApprovalRequestContent>()
    .FirstOrDefault();

Technical notes:

  • Override methods in GroupChatManager subclasses from external assemblies must use protected (not protected internal)
  • Tools passed via ChatClientAgent constructor, not as settable properties
  • Agent selection uses the Name property (set during agent creation) rather than the auto-generated Id property
  • C# source files must use UTF-8 encoding with BOM to comply with the repository's code formatter requirements

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

This section details on the original issue you should resolve

<issue_title>E2E sample of agent approvals in multi-agent orchestrations</issue_title>
<issue_description>The outcome of this task is that we have a test or sample of agent approvals being used within a multi-agent orchestration.

There is an AIAgent Executor which will be used for multi-agent orchestration so you should collaborate with respective owners of .Net and Python implementations.</issue_description>

<agent_instructions>Add a C# sample that is equivalent to this Python sample - https://github.com/microsoft/agent-framework/blob/main/python/samples/getting_started/workflows/tool-approval/group_chat_builder_tool_approval.py.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@dmytrostruk Python sample: https://github.com/microsoft/agent-framework/blob/main/python/samples/getting_started/workflows/tool-approval/group_chat_builder_tool_approval.py

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 22, 2026 13:39
Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Copilot AI changed the title [WIP] Add C# sample for agent approvals in multi-agent orchestration Add C# GroupChat tool approval sample for multi-agent orchestrations Jan 22, 2026
Copilot AI requested a review from SergeyMenshykh January 22, 2026 13:49
@SergeyMenshykh
Copy link
Member

@copilot add this project to the solution

@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET labels Jan 22, 2026
@github-actions github-actions bot changed the title Add C# GroupChat tool approval sample for multi-agent orchestrations .NET: Add C# GroupChat tool approval sample for multi-agent orchestrations Jan 22, 2026
Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

@copilot add this project to the solution

Added to the solution in commit 237e5a6. The GroupChatToolApproval project is now included in the /Samples/GettingStarted/Workflows/Agents/ folder in alphabetical order.

Copilot AI changed the title .NET: Add C# GroupChat tool approval sample for multi-agent orchestrations Add C# GroupChat tool approval sample for multi-agent orchestrations Jan 22, 2026
Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
@SergeyMenshykh
Copy link
Member

@copilot dotnet build failed with the errors:
Running formatters.
/app/dotnet/samples/GettingStarted/Workflows/Agents/GroupChatToolApproval/DeploymentGroupChatManager.cs(1,1): error CHARSET: Fix file encoding. [/app/dotnet/samples/GettingStarted/Workflows/Agents/GroupChatToolApproval/GroupChatToolApproval.csproj]
/app/dotnet/samples/GettingStarted/Workflows/Agents/GroupChatToolApproval/Program.cs(1,1): error CHARSET: Fix file encoding. [/app/dotnet/samples/GettingStarted/Workflows/Agents/GroupChatToolApproval/GroupChatToolApproval.csproj]

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Jan 27, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 27, 2026
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit c860385 Jan 27, 2026
15 checks passed
This was referenced Jan 27, 2026
@crickman crickman deleted the copilot/add-csharp-sample-agent-approvals branch February 4, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E2E sample of agent approvals in multi-agent orchestrations

5 participants