Skip to content

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
// First speaker after initial user message
if (this.IterationCount == 0)
{
AIAgent qaAgent = this._agents.First(a => a.Id == "QAEngineer");
Copy link
Member

@SergeyMenshykh SergeyMenshykh Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Shouldn't the Name property be used here and in line 44 instead of Id?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use the Name property as mentioned above instead of the Id property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 2535dde. Changed from a.Id to a.Name on both lines 39 and 44.

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>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

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

Fixed in commit 7610a6d. Added UTF-8 BOM to both DeploymentGroupChatManager.cs and Program.cs to match the encoding requirements for C# source files in this repository.

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

3 participants