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 Usage: [Issues, PRs], Target: .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

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 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
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants