Skip to content

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

Merged
SergeyMenshykh merged 12 commits into
mainfrom
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 into
mainfrom
copilot/add-csharp-sample-agent-approvals

Conversation

Copilot AI commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@copilot add this project to the solution

@markwallace-microsoft markwallace-microsoft added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .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>

Copilot AI commented Jan 22, 2026

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Contributor

@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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E2E sample of agent approvals in multi-agent orchestrations

6 participants