.NET: Add background agents support to HarnessAgent#5977
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.BackgroundAgentsandBackgroundAgentsProviderOptionsto configure background agents support. - Updated
HarnessAgentto automatically includeBackgroundAgentsProviderwhen 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
BackgroundAgentsProviderexists. 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);
}
peibekwe
approved these changes
May 20, 2026
SergeyMenshykh
approved these changes
May 21, 2026
SergeyMenshykh
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Description
Contribution Checklist