Skip to content

Python: HarnessAgent: Disable compaction when max tokens not provided#6410

Merged
eavanvalkenburg merged 5 commits into
microsoft:mainfrom
westey-m:python-disable-compaction-when-max-tokens-missing
Jun 10, 2026
Merged

Python: HarnessAgent: Disable compaction when max tokens not provided#6410
eavanvalkenburg merged 5 commits into
microsoft:mainfrom
westey-m:python-disable-compaction-when-max-tokens-missing

Conversation

@westey-m

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

Copy link
Copy Markdown
Contributor

Motivation and Context

Aligning the .net and python versions by having the max token params optional and where it just gracefully disable compaction if not provided.

#6333

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings June 9, 2026 10:59
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels Jun 9, 2026
@github-actions github-actions Bot changed the title HarnessAgent: Disable compaction when max tokens not provided Python: HarnessAgent: Disable compaction when max tokens not provided Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _skills.py10213796%294, 541, 1007, 1022, 1024–1025, 1381–1382, 1394–1395, 1625, 1654, 2117, 2573–2574, 2709, 2714, 2717, 2722, 2749, 2754, 2808, 2817, 2822, 2825, 2830, 2854, 2859, 3101–3102, 3451, 3678–3679, 3706–3707, 3714–3715
packages/core/agent_framework/_harness
   _agent.py80495%154, 375–376, 378
TOTAL38569441588% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7742 34 💤 0 ❌ 0 🔥 2m 7s ⏱️

@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: 89%

✓ Correctness

The PR correctly makes max_context_window_tokens and max_output_tokens optional in create_harness_agent, gracefully disabling compaction when they're not provided. The logic in _assemble_compaction_provider is sound: it returns None when disable_compaction is True, when no before_strategy can be resolved, or when token params are missing and no custom strategy is given. Validation properly guards against None. The remaining changes are cosmetic reformatting. No correctness issues found.

✓ Security Reliability

This PR makes max_context_window_tokens and max_output_tokens optional in create_harness_agent, disabling compaction gracefully when they are not provided. The validation logic correctly guards against invalid values when provided, the compaction assembly safely returns None when a before-strategy cannot be resolved, and the default_opts handling correctly skips max_tokens when max_output_tokens is None. The remaining changes are formatting-only (test files, _skills.py). No security or reliability issues identified.

✓ Test Coverage

The new tests cover the primary scenarios well (both params omitted, custom before-strategy override, disable_compaction precedence). However, there is a coverage gap for the 'partial token params' case where only one of max_context_window_tokens or max_output_tokens is provided — compaction is silently disabled with no test documenting this behavior, which represents a likely user misconfiguration path.

✓ Failure Modes

The PR cleanly makes token params optional and disables compaction when both are omitted. The main concern is an operational silent-failure path: when a user provides only ONE of the two token params (e.g., max_context_window_tokens without max_output_tokens), compaction is silently disabled with no log warning, making a likely misconfiguration invisible.

✗ Design Approach

The optional-token change is mostly aligned with the stated goal, but it accidentally makes one documented customization path unreachable: a caller can no longer supply an after_compaction_strategy without also supplying a before strategy or token budget. That means the new design silently drops a valid post-run-only compaction configuration.

Flagged Issues

  • _assemble_compaction_provider now returns None whenever no before-strategy can be resolved, so a caller-provided after_compaction_strategy is silently ignored (python/packages/core/agent_framework/_harness/_agent.py:94-95). This conflicts with the CompactionProvider contract that either strategy may be None to skip that phase, meaning after_strategy alone is a valid configuration (python/packages/core/agent_framework/_compaction.py:1194, 1232-1236).

Automated review by westey-m's agents

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

This PR aligns the Python HarnessAgent behavior with the .NET version by making token budget parameters optional and automatically disabling compaction when they aren’t supplied, while updating docs and tests to reflect the new default behavior.

Changes:

  • Made max_context_window_tokens / max_output_tokens optional in create_harness_agent and disabled default compaction when they’re omitted.
  • Updated harness sample README to document “minimal setup” vs “with compaction”.
  • Added unit tests covering compaction behavior when token params are omitted and when custom strategies/flags are provided; applied minor formatting-only updates in MCP test files.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
python/packages/core/agent_framework/_harness/_agent.py Makes token budgets optional and changes compaction/default options assembly accordingly.
python/packages/core/tests/core/test_harness_agent.py Adds coverage for the new “no token params disables compaction” behavior and override precedence.
python/samples/02-agents/harness/README.md Updates sample docs to reflect optional token parameters and compaction being opt-in.
python/packages/core/agent_framework/_skills.py Minor formatting-only changes.
python/packages/core/tests/core/test_mcp_skills.py Minor formatting-only changes.
python/packages/core/tests/core/test_mcp_observability.py Minor formatting-only changes.

Comment thread python/packages/core/agent_framework/_harness/_agent.py
Comment thread python/packages/core/agent_framework/_harness/_agent.py Outdated
westey-m and others added 2 commits June 9, 2026 17:11
Reject max_output_tokens=0 (must be positive), mirroring
max_context_window_tokens. Addresses PR review feedback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Jun 10, 2026
Merged via the queue into microsoft:main with commit 8dde9ef Jun 10, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants