Python: Integrate message injection into harness agent#7027
Merged
Conversation
Contributor
Contributor
There was a problem hiding this comment.
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
MessageInjectionMiddlewareintocreate_harness_agentby 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_idboundaries; 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. |
TaoChenOSU
approved these changes
Jul 9, 2026
moonbox3
approved these changes
Jul 10, 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 .NET
HarnessAgentenables message injection by default (viaUseMessageInjection), letting a user queue additional input while an agentturn is already running so it is picked up within the same run. The Python
harness lacked this. This PR brings the Python
create_harness_agentand theharness 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_agentnow always wires inMessageInjectionMiddleware(mirroring the .NET harness's
UseMessageInjection). It is always on withno opt-out because it is a no-op when no messages are queued for the
session.
agent_runner.py,app.py,state_driver.py,components/agent_status.py) now supports injecting input during astreaming 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.
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-
Noneresponse_idchanges, matching Python's streaming semantics.What is the impact of these changes?
surface change required from callers.
harness runs are unaffected.
What do you want reviewers to focus on?
MessageInjectionMiddlewareand itsparity with the .NET
UseMessageInjectiondefault.Related Issue
Fixes #7026
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.