Skip to content

Python: Integrate message injection into harness agent#7027

Merged
moonbox3 merged 3 commits into
microsoft:mainfrom
westey-m:python-integrate-nudging
Jul 10, 2026
Merged

Python: Integrate message injection into harness agent#7027
moonbox3 merged 3 commits into
microsoft:mainfrom
westey-m:python-integrate-nudging

Conversation

@westey-m

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

Copy link
Copy Markdown
Contributor

Motivation & Context

The .NET HarnessAgent enables message injection by default (via
UseMessageInjection), letting a user queue additional input while an agent
turn is already running so it is picked up within the same run. The Python
harness lacked this. This PR brings the Python create_harness_agent and the
harness console sample to parity, so users can nudge/steer a running harness
agent without waiting for the current turn to finish.

Description & Review Guide

  • What are the major changes?

    • create_harness_agent now always wires in MessageInjectionMiddleware
      (mirroring the .NET harness's UseMessageInjection). It is always on with
      no opt-out because it is a no-op when no messages are queued for the
      session.
    • The harness console sample (agent_runner.py, app.py, state_driver.py,
      components/agent_status.py) now supports injecting input during a
      streaming run: text submitted mid-turn is enqueued via the middleware and
      drained into the ongoing run; the queued-message display is kept in sync and
      consumed messages are echoed to the output area.
    • The planning-output observer was made robust to multi-response runs (message
      injection can trigger a follow-up model invocation): only the last
      response's text is retained for structured-output (JSON) parsing, earlier
      responses are flushed as plain text. Boundaries are detected via non-None
      response_id changes, matching Python's streaming semantics.
    • Test and doc-sample touch-ups accompanying the wiring.
  • What is the impact of these changes?

    • Message injection is available by default for harness agents, with no API
      surface change required from callers.
    • The behavior is additive and a no-op when nothing is queued, so existing
      harness runs are unaffected.
  • What do you want reviewers to focus on?

    • The always-on/no-opt-out decision for MessageInjectionMiddleware and its
      parity with the .NET UseMessageInjection default.

Related Issue

Fixes #7026

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 July 9, 2026 17:41
@giles17 giles17 added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jul 9, 2026
@westey-m westey-m marked this pull request as ready for review July 9, 2026 17:42
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_harness
   _agent.py118496%191, 557–558, 560
TOTAL44099527088% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8834 33 💤 0 ❌ 0 🔥 2m 16s ⏱️

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

Integrates always-on message injection into the Python harness agent and updates the harness console sample to support queueing user input mid-stream, bringing behavior closer to the .NET harness.

Changes:

  • Wire MessageInjectionMiddleware into create_harness_agent by default and document the behavior.
  • Update the harness console runner/UI to enqueue streaming-time input and display/echo queued messages.
  • Harden planning-mode structured-output collection for multi-response runs by tracking response_id boundaries; add/adjust tests and sample touch-ups.

Reviewed changes

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

Show a summary per file
File Description
python/packages/core/agent_framework/_harness/_agent.py Always appends MessageInjectionMiddleware to harness agent middleware stack.
python/packages/core/AGENTS.md Documents default harness wiring including always-on message injection.
python/packages/core/tests/core/test_harness_agent.py Adds/updates tests asserting message injection is wired by default and middleware ordering expectations.
python/samples/02-agents/harness/console/agent_runner.py Adds streaming-time input enqueueing and queued-message syncing/echoing during streaming.
python/samples/02-agents/harness/console/app.py Routes text submissions during streaming to the runner and updates status/placeholder behavior.
python/samples/02-agents/harness/console/components/agent_status.py Adds queued-message status line rendering.
python/samples/02-agents/harness/console/observers/base.py Updates observer typing/docs to use AgentResponseUpdate metadata.
python/samples/02-agents/harness/console/observers/planning_output.py Switches to on_response_update and tracks response_id boundaries to keep only the last response for JSON parsing.
python/samples/02-agents/harness/console/state_driver.py Extends UX protocol + simple console driver with queued-message display hook.
python/samples/02-agents/security/email_security_example.py Adjusts sample string quoting in scenario output.
python/samples/02-agents/harness/build_your_own_claw/claw_step01_meet_your_claw.py Minor whitespace/formatting touch-up.
python/samples/02-agents/harness/build_your_own_claw/claw_step02_working_with_data.py Minor whitespace/formatting touch-up.
python/samples/02-agents/harness/build_your_own_claw/claw_step03_scaling_capabilities.py Minor import ordering/whitespace touch-up.

Comment thread python/samples/02-agents/harness/console/agent_runner.py
Comment thread python/samples/02-agents/harness/console/state_driver.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: 86% | Result: All clear

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


Automated review by westey-m's agents

@moonbox3 moonbox3 added this pull request to the merge queue Jul 10, 2026
Merged via the queue into microsoft:main with commit ce96fd4 Jul 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 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: Integrate message injection into harness agent

5 participants