Skip to content

.NET: Add BackgroundTaskCompletionLoopEvaluator for harness background agents - #6736

Merged
westey (westey-m) merged 3 commits into
microsoft:mainfrom
westey-m:dotnet-harness-background-agent-loop
Jun 26, 2026
Merged

westey (westey-m) merged 3 commits into
microsoft:mainfrom
westey-m:dotnet-harness-background-agent-loop

Conversation

@westey-m

Copy link
Copy Markdown
Collaborator

Motivation & Context

A harness agent that delegates work to background agents can finish its own turn while those background tasks are still running, stopping before their results are available. This adds a LoopEvaluator that keeps re-invoking the harness agent until every background task has reached a terminal state, so the agent cannot declare the work done while tasks are still in flight. It complements the existing TodoCompletionLoopEvaluator and is opt-in.

Description & Review Guide

  • What are the major changes?
    • BackgroundAgentsProvider gains a public GetIncompleteTasks(AgentSession?) that refreshes in-flight task state (finalizing just-finished tasks) and returns only the tasks that are still Running.
    • New BackgroundTaskCompletionLoopEvaluator (+ BackgroundTaskCompletionLoopEvaluatorOptions): resolves the BackgroundAgentsProvider at evaluation time from the looped agent via GetService, applies in every mode (no mode gating), and continues with a customizable feedback message while running tasks remain. The feedback template supports {incomplete_task_count} and {incomplete_tasks} placeholders and matches the wording of the parallel Python implementation.
    • Unit tests covering provider resolution, running→continue (with task list/count), terminal→stop, no-tasks→stop, custom template, and GetIncompleteTasks returning only running tasks.
  • What is the impact of these changes?
    • Purely additive and opt-in. Existing behavior is unchanged unless a consumer adds this evaluator to a LoopAgent.
  • What do you want reviewers to focus on?
    • Provider resolution via the GetService decorator chain (no constructor wiring).
    • The "only Running is incomplete" semantics — Completed, Failed, and Lost are all terminal (a Lost task can never be waited on, so blocking on it would loop forever).

Related Issue

Fixes #6733

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings June 25, 2026 13:57
@moonbox3 Evan Mattson (moonbox3) added the .NET Usage: [Issues, PRs], Target: .Net label Jun 25, 2026
@westey-m
westey (westey-m) marked this pull request as ready for review June 25, 2026 13:58

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 a new opt-in .NET harness LoopEvaluator that prevents a looped harness agent from declaring completion while background-agent tasks are still running, by re-invoking until all tasks reach a terminal state.

Changes:

  • Adds BackgroundTaskCompletionLoopEvaluator (+ options) that resolves BackgroundAgentsProvider via GetService and continues the loop while any tasks remain Running, with configurable feedback templating.
  • Extends BackgroundAgentsProvider with GetIncompleteTasks(AgentSession?) to refresh/finalize in-flight tasks and return only still-running tasks.
  • Introduces unit tests covering evaluator behavior and the provider’s “running-only” incomplete semantics.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
dotnet/src/Microsoft.Agents.AI/Harness/Loop/BackgroundTaskCompletionLoopEvaluator.cs New loop evaluator that continues while background tasks are running and emits templated feedback.
dotnet/src/Microsoft.Agents.AI/Harness/Loop/BackgroundTaskCompletionLoopEvaluatorOptions.cs Options type for configuring the evaluator’s feedback template.
dotnet/src/Microsoft.Agents.AI/Harness/BackgroundAgents/BackgroundAgentsProvider.cs Adds GetIncompleteTasks that refreshes task state and returns only Running tasks.
dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/Loop/BackgroundTaskCompletionLoopEvaluatorTests.cs New unit tests for evaluator/provider behavior and feedback formatting.

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 92% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by westey-m's agents

@westey-m
westey (westey-m) added this pull request to the merge queue Jun 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jun 26, 2026

This branch was previously deployed

1 inactive deployment
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.

.NET: Harness: Add a LoopCompletionEvaluator for background agents

5 participants