refactor: promote steer injection to a first-class pydantic-ai capability - #828
Open
mpfaffenberger wants to merge 2 commits into
Open
refactor: promote steer injection to a first-class pydantic-ai capability#828mpfaffenberger wants to merge 2 commits into
mpfaffenberger wants to merge 2 commits into
Conversation
…lity The Ctrl+T mid-turn steering injector was a closure-based history processor wrapped in ProcessHistory. Rewrite it as SteerInjection, a proper AbstractCapability subclass in harness house style (dataclass, injectable drain/mirror seams, get_serialization_name -> None). It overrides before_model_request directly -- the exact seam ProcessHistory uses -- so registration order against the compaction capability is unchanged: compaction first, then steering, so a fresh steer can never be compacted away on the same call. Feature parity preserved: - drains ONLY now-mode steers (queue-mode stays with the runtime loop) - carries in-effect instructions onto injected requests - resolves attachments via resolve_steer_content - one discrete ModelRequest per steer, appended after existing messages - mirrors injections into agent._message_history for durability - emits the same observability message per steer New unit suite tests the capability contracts directly; the wiring guard and smoke tests in test_runtime_pause_leakage.py updated to the capability seam.
…lity chain Reviewer follow-up: the unit suite exercised the hook through a duck-typed context. Add a TestModel-backed Agent.run() test proving the framework dispatches before_model_request and that the injected steer persists into result.all_messages().
This was referenced Aug 21, 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.
What
The Ctrl+T mid-turn steering injector (
_steer_processor.py) was a closure-based history processor wrapped inProcessHistory. This PR rewrites it asSteerInjection, a genuineAbstractCapabilitysubclass in pydantic-ai-harness house style — dataclass, injectabledrain/mirrorseams,get_serialization_name() -> None(not spec-serializable: seams take callables).Module renamed
_steer_processor.py→_steering.pyto match its promotion.Why
capabilities=[...]; steering was the odd one out hiding behind the genericProcessHistoryadapter.drainandmirrorcallables instead of reaching for globals +agent._message_historyfrom inside a closure — unit tests no longer need the global pause controller.SteerInjection.before_model_requestis the exact hookProcessHistoryuses internally, so compaction-then-steering registration order is byte-for-byte preserved (a fresh steer still can't be compacted away on the same call).Feature parity checklist
now-mode steers (queue-mode stays with the runtime's between-turns loop — no double-inject)resolve_steer_content(steer with a pasted screenshot Just Works)ModelRequestper steer, appended AFTER existing messagesagent._message_historyfor durability across the turn boundaryemit_infoper steerTesting
tests/agents/test_steering_capability.py— 10 contract tests on the capability directly (no-op on empty queue, ordering, instruction carry, mirror behavior, now-vs-queue isolation, native-async hook)test_runtime_pause_leakage.pytests/agents/+tests/plugins/test_steer_queue.py: 423 passedruff check+ruff formatcleanDo not merge yet — under agent review.