[BREAKING] Python: Change background-agent loop helper to resolve the provider from the agent#6735
Open
westey-m wants to merge 1 commit into
Open
Conversation
…add feedback message builder.
Contributor
Contributor
There was a problem hiding this comment.
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_runningto resolve the provider fromagent.context_providers(signature becomesbackground_tasks_running()). - Adds
background_tasks_running_messageto generate anext_messagenudge 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. |
TaoChenOSU
approved these changes
Jun 25, 2026
giles17
approved these changes
Jun 25, 2026
eavanvalkenburg
approved these changes
Jun 26, 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 & Context
The harness exposes
todos_remaining/todos_remaining_messageloop helpers that drive anAgentLoopMiddlewareuntil the agent's todos are complete. The equivalent for background work wasincomplete: there was a
background_tasks_running(provider)check that required the caller to passthe
BackgroundAgentsProviderexplicitly, and there was no companionnext_messagehelper.That explicit-provider shape does not fit
create_harness_agent, which builds its context providersinternally — callers wiring
loop_should_continue/loop_next_messagedo not have a handle tothe
BackgroundAgentsProvider. Resolving the provider directly from the running agent(
agent.context_providers) is the better design and matches howtodos_remainingalready works.Description & Review Guide
What are the major changes?
background_tasks_runningto resolve theBackgroundAgentsProviderfrom therunning agent (via
_resolve_context_provider) instead of taking it as an argument — so it worksin a harness agent where the caller has no access to the provider. New signature is
background_tasks_running(); the predicate readssession/agentand loops while any persistedtask is
RUNNING.background_tasks_running_message, anext_messagehelper mirroringtodos_remaining_message: it lists the still-running tasks (#<id> (<agent>): <description>) andreminds the agent to wait for them to finish and retrieve their results, returning
Nonewhen thesession/agent/provider is unavailable or nothing is running.
_running_background_tasks(session, agent)backs both helpers.AGENTS.md.What is the impact of these changes?
create_harness_agent'sloop_should_continue/loop_next_message, consistent with the todos pair.background_tasks_runningis an experimental harness helper; its signature changed frombackground_tasks_running(provider)tobackground_tasks_running(). Callers now pass the agentvia the standard loop kwargs rather than the provider.
What do you want reviewers to focus on?
next_messagereminder.Related Issue
Fixes #6734
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.