Skip to content

Python: keep agent loop marker from provider SDKs - #7860

Open
Eduard van Valkenburg (eavanvalkenburg) wants to merge 1 commit into
microsoft:mainfrom
eavanvalkenburg:eavanvalkenburg-fix-agent-loop-marker
Open

Python: keep agent loop marker from provider SDKs#7860
Eduard van Valkenburg (eavanvalkenburg) wants to merge 1 commit into
microsoft:mainfrom
eavanvalkenburg:eavanvalkenburg-fix-agent-loop-marker

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

Agent loop middleware stamps _agent_loop_iteration into run options so turn-scoped context providers can defer their after_run work to the loop boundary. Because remaining run options are also forwarded as provider-specific options, the private marker reached provider SDKs and caused real clients such as Ollama and Foundry to reject the unexpected keyword argument.

This change keeps the marker available for provider scoping while preventing framework-private metadata from crossing the chat-client transport boundary.

Description & Review Guide

  • What are the major changes? Remove _agent_loop_iteration from the final merged chat options passed to the client, without removing it from SessionContext.options. Add streaming and non-streaming regression coverage using a strict transport signature.
  • What is the impact of these changes? Harness agents with an active loop predicate can call strict provider SDKs successfully, provider-specific options continue to pass through, and turn-scoped providers still run once at the loop boundary.
  • What do you want reviewers to focus on? Confirm that filtering the single reserved key at the outbound options copy is the narrowest boundary and preserves the loop marker semantics introduced in Python: defer turn-scoped after_run providers to the agent loop boundary #7289.

Related Issue

Fixes #7821

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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 42a18a81-57d5-4912-8dbd-f1a48db57a45

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

Prevents the agent-loop marker from reaching provider SDKs while preserving loop-scoped provider behavior.

Changes:

  • Removes _agent_loop_iteration from outbound chat options.
  • Adds streaming and non-streaming regression coverage with strict option validation.

Reviewed changes

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

File Description
python/packages/core/agent_framework/_agents.py Filters the private loop marker at the client boundary.
python/packages/core/tests/core/test_harness_loop.py Verifies marker filtering and provider-option forwarding.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _agents.py4624490%600, 655, 1225, 1270, 1341–1345, 1444, 1474, 1511, 1606, 1634, 1647, 1696, 1698, 1707–1712, 1717, 1719, 1725–1726, 1733, 1735–1736, 1744–1745, 1748–1750, 1760–1765, 1769, 1774, 1776
TOTAL48159449690% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9731 36 💤 0 ❌ 0 🔥 2m 40s ⏱️

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

MAF Automated Review — Iteration 1

Result: No findings
Scope: full PR (1 commit(s)): 11be6b80f408
Model: gpt-5.6-sol

Overview

The change removes the framework-private loop marker only from the copied options sent to chat clients, while preserving it in SessionContext.options for turn-scoped provider lifecycle handling. The shared preparation path covers streaming and non-streaming calls, and the regression test verifies both strict transport compatibility and preservation of ordinary provider options. No publishable Critical, High, or Medium issue was established.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: agent-loop marker reaches the provider SDK (core 1.15.0)

3 participants