Skip to content

.NET: Add background agents support to HarnessAgent#5977

Merged
westey-m merged 4 commits into
microsoft:mainfrom
westey-m:harness-background-agents
May 21, 2026
Merged

.NET: Add background agents support to HarnessAgent#5977
westey-m merged 4 commits into
microsoft:mainfrom
westey-m:harness-background-agents

Conversation

@westey-m
Copy link
Copy Markdown
Contributor

Motivation and Context

Description

  • Add background agents support to HarnessAgent

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 May 20, 2026 18:06
@moonbox3 moonbox3 added the .NET label May 20, 2026
@github-actions github-actions Bot changed the title Add background agents support to HarnessAgent .NET: Add background agents support to HarnessAgent May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class “background agents” wiring to HarnessAgent so callers can provide background agents via options (rather than manually injecting a BackgroundAgentsProvider into AIContextProviders), and updates tests + a sample accordingly.

Changes:

  • Added HarnessAgentOptions.BackgroundAgents and BackgroundAgentsProviderOptions to configure background agents support.
  • Updated HarnessAgent to automatically include BackgroundAgentsProvider when a non-empty background agent collection is provided.
  • Updated unit tests and the Harness background-agents sample to use the new options-based configuration.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgentOptions.cs Adds new options for configuring background agents and provider options.
dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgent.cs Wires BackgroundAgentsProvider into default context providers when configured.
dotnet/tests/Microsoft.Agents.AI.Harness.UnitTests/HarnessAgentOptionsTests.cs Extends options tests to cover the new properties.
dotnet/tests/Microsoft.Agents.AI.Harness.UnitTests/HarnessAgentTests.cs Adds tests for inclusion/exclusion of BackgroundAgentsProvider.
dotnet/samples/02-agents/Harness/Harness_Step02_Research_WithBackgroundAgents/Program.cs Switches the sample to use BackgroundAgents instead of manually adding the provider.
Comments suppressed due to low confidence (1)

dotnet/tests/Microsoft.Agents.AI.Harness.UnitTests/HarnessAgentTests.cs:1321

  • This test claims to verify that multiple background agents are passed to the provider, but it only checks that a BackgroundAgentsProvider exists. Consider asserting that both agent names appear in the provider’s generated context (or otherwise verifying the provider was constructed with both agents).
    /// <summary>
    /// Verify that multiple background agents are all passed to the provider.
    /// </summary>
    [Fact]
    public void BackgroundAgentsProvider_IncludesMultipleAgents()
    {
        // Arrange
        var chatClient = new Mock<IChatClient>().Object;
        var agent1Mock = new Mock<AIAgent>();
        agent1Mock.Setup(a => a.Name).Returns("Agent1");
        var agent2Mock = new Mock<AIAgent>();
        agent2Mock.Setup(a => a.Name).Returns("Agent2");
        var options = CreateAllDisabledOptions();
        options.BackgroundAgents = [agent1Mock.Object, agent2Mock.Object];

        // Act
        var agent = new HarnessAgent(chatClient, TestMaxContextWindowTokens, TestMaxOutputTokens, options);
        var innerAgent = agent.GetService<ChatClientAgent>();

        // Assert
        Assert.NotNull(innerAgent?.AIContextProviders);
        Assert.Contains(innerAgent!.AIContextProviders!, p => p is BackgroundAgentsProvider);
    }

Comment thread dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgent.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgentOptions.cs
@westey-m westey-m enabled auto-merge May 21, 2026 10:30
@westey-m westey-m added this pull request to the merge queue May 21, 2026
Merged via the queue into microsoft:main with commit 4050107 May 21, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants