Repository navigation
Python: add signal protocol for AgentLoopMiddleware autonomous loops - #9162
Open
Mark Licata (marklicata) wants to merge 2 commits into
Open
Mark Licata (marklicata) wants to merge 2 commits into
Mark Licata (marklicata) wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mark Licata (marklicata)
deployed
to
github-app-auth
October 7, 2026 15:34 — with
GitHub Actions
Active
Mark Licata (marklicata)
deployed
to
github-app-auth
October 7, 2026 15:34 — with
GitHub Actions
Active
5 tasks done
Mark Licata (marklicata)
deployed
to
github-app-auth
October 7, 2026 15:34 — with
GitHub Actions
Active
5 tasks done
Mark Licata (marklicata)
deployed
to
github-app-auth
October 7, 2026 15:37 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Exit metadata can remain stale, and the public API does not consistently match its documented experimental scope and exit-reason contract.
4 open findings
What changed in this PR
Adds a Python signal protocol for autonomous AgentLoopMiddleware termination and typed exit-reason reporting.
Changes:
- Adds task-complete and human-input signal parsing.
- Stamps iteration-cap metadata for streaming and non-streaming loops.
- Exports and tests the new public APIs.
| File | Description |
|---|---|
test_harness_loop.py |
Tests signal parsing and loop exits. |
AGENTS.md |
Documents the signal protocol. |
_signals.py |
Implements signals and exit reasons. |
_loop.py |
Stamps iteration-cap metadata. |
__init__.pyi |
Exposes typed public imports. |
__init__.py |
Adds runtime public exports. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Mark Licata (marklicata)
marked this pull request as ready for review
October 7, 2026 15:56
Mark Licata (marklicata)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 7, 2026 15:56
Mark Licata (marklicata)
deployed
to
github-app-auth
October 7, 2026 15:57 — with
GitHub Actions
Active
…imental markers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mark Licata (marklicata)
deployed
to
github-app-auth
October 7, 2026 16:15 — with
GitHub Actions
Active
This branch was successfully deployed
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
Agents running inside
AgentLoopMiddlewarehave no standard way to say "I'm done" or "I need a human". Each team writes its ownshould_continuepredicate. This adds a text-based signal protocol so the agent can communicate loop termination intent directly in its response text:TASK_COMPLETE: <summary>: agent signals it is done; loop stopsNEED_INPUT: <question>: agent needs human input; loop stopsThis is the Python half of the work previously proposed in #8993, split per language at the reviewers' request. The .NET counterpart is #9163.
Description & Review Guide
What are the major changes?
SignalParser/signal_should_continue()(agent_framework._harness._signals): drop-inshould_continuepredicate forAgentLoopMiddleware. It scans assistant messages only, so user-role nudges injected between iterations are ignored.LoopExitReason: typed exit reason strings"completed","iteration_cap_reached","need_input","cancelled"get_loop_exit_reason(response): reads the exit reason from assistant text first, thenadditional_properties; a signal always wins over the iteration capAgentLoopMiddlewarenow stampsadditional_properties["loop_exit_reason"] = "iteration_cap_reached"when the cap fires (streaming and non-streaming)agent_framework;__init__.pyiandpackages/core/AGENTS.mdupdatedWhat is the impact of these changes?
Additive and marked experimental. Loops that don't use
SignalParsersee no behavior change beyond the newloop_exit_reasonstamp when the cap fires.What do you want reviewers to focus on?
get_loop_exit_reason: assistant text first,additional_propertiessecond, so a signal on the final allowed iteration is reported ascompleted, notiteration_cap_reachedRelated Issue
Part of #8860, together with #9163 for .NET. The issue is closed manually once both PRs have merged.
Contribution Checklist
🤖 Generated with Claude Code