Skip to content

[BREAKING] Python: Change background-agent loop helper to resolve the provider from the agent#6735

Open
westey-m wants to merge 1 commit into
microsoft:mainfrom
westey-m:python-harness-background-agent-loop
Open

[BREAKING] Python: Change background-agent loop helper to resolve the provider from the agent#6735
westey-m wants to merge 1 commit into
microsoft:mainfrom
westey-m:python-harness-background-agent-loop

Conversation

@westey-m

@westey-m westey-m commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

The harness exposes todos_remaining / todos_remaining_message loop helpers that drive an
AgentLoopMiddleware until the agent's todos are complete. The equivalent for background work was
incomplete: there was a background_tasks_running(provider) check that required the caller to pass
the BackgroundAgentsProvider explicitly, and there was no companion next_message helper.

That explicit-provider shape does not fit create_harness_agent, which builds its context providers
internally — callers wiring loop_should_continue / loop_next_message do not have a handle to
the BackgroundAgentsProvider. Resolving the provider directly from the running agent
(agent.context_providers) is the better design and matches how todos_remaining already works.

Description & Review Guide

  • What are the major changes?

    • Refactored background_tasks_running to resolve the BackgroundAgentsProvider from the
      running agent (via _resolve_context_provider) instead of taking it as an argument — so it works
      in a harness agent where the caller has no access to the provider. New signature is
      background_tasks_running(); the predicate reads session/agent and loops while any persisted
      task is RUNNING.
    • Added background_tasks_running_message, a next_message helper mirroring
      todos_remaining_message: it lists the still-running tasks (#<id> (<agent>): <description>) and
      reminds the agent to wait for them to finish and retrieve their results, returning None when the
      session/agent/provider is unavailable or nothing is running.
    • A shared internal _running_background_tasks(session, agent) backs both helpers.
    • Exported the new helper, updated the module docstring, and documented both helpers in the core
      AGENTS.md.
  • What is the impact of these changes?

    • The two helpers can now be wired straight into create_harness_agent's
      loop_should_continue / loop_next_message, consistent with the todos pair.
    • background_tasks_running is an experimental harness helper; its signature changed from
      background_tasks_running(provider) to background_tasks_running(). Callers now pass the agent
      via the standard loop kwargs rather than the provider.
  • What do you want reviewers to focus on?

    • The resolve-from-agent approach and the wording/format of the next_message reminder.

Related Issue

Fixes #6734

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:56
@moonbox3 moonbox3 added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jun 25, 2026
@westey-m westey-m marked this pull request as ready for review June 25, 2026 13:58
@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_harness
   _loop.py279797%482, 490, 565, 639, 682, 757, 913
TOTAL42568508688% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8327 37 💤 0 ❌ 0 🔥 2m 20s ⏱️

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 Python harness loop helpers for background-agent tasks that match the existing todo-loop helper pattern by resolving BackgroundAgentsProvider from the running agent, enabling direct use with create_harness_agent loop hooks.

Changes:

  • Refactors background_tasks_running to resolve the provider from agent.context_providers (signature becomes background_tasks_running()).
  • Adds background_tasks_running_message to generate a next_message nudge listing still-running background tasks.
  • Updates exports, docs, and adds/updates unit tests to cover the new behavior.

Reviewed changes

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

File Description
python/packages/core/agent_framework/_harness/_loop.py Refactors the background-task loop predicate and introduces a companion next_message helper backed by a shared _running_background_tasks function.
python/packages/core/agent_framework/init.py Exports background_tasks_running_message from the top-level package API.
python/packages/core/AGENTS.md Documents the new helper pair and updated behavior/signature.
python/packages/core/tests/core/test_harness_loop.py Updates existing tests for the new predicate signature and adds coverage for the new background_tasks_running_message helper.

Comment thread python/packages/core/tests/core/test_harness_loop.py
Comment thread python/packages/core/tests/core/test_harness_loop.py

@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: 93% | Result: All clear

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


Automated review by westey-m's agents

@westey-m westey-m changed the title Python: Add background-agent loop helpers that resolve the provider from the agent [BREAKING] Python: Add background-agent loop helpers that resolve the provider from the agent Jun 25, 2026
@westey-m westey-m added the breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible label Jun 25, 2026
@westey-m westey-m changed the title [BREAKING] Python: Add background-agent loop helpers that resolve the provider from the agent [BREAKING] Python: Change background-agent loop helper to resolve the provider from the agent Jun 26, 2026
@westey-m 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 failed status checks Jun 26, 2026
@westey-m 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 failed status checks Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Harness: Change loop evaluator that loops until all background agents are complete to resolve provider from agent

6 participants