python-server: Rich Interactions runtime + choices kind (AskUserQuestion) - #479
Merged
Conversation
…ion) Port the Rich Interactions framework runtime and the `choices` kind to the Python server (Wave 2 of the polyglot effort), mirroring the Rust reference (PR #475). Framework (interaction.py): kind-agnostic InteractionKind protocol, InteractionRegistry catalog (default: choices), and a session-keyed PendingInteractions park/resume registry generalizing the write-confirmation ConfirmationRegistry. Per turn, the runner registers per-kind request_<kind> raise tools (interaction_tools.py): rich channels park on an asyncio future (emit interaction_required, await submit_interaction, resume with the canonical payload); text-only channels degrade to the kind's conversational directive and submit through the generic submit_interaction tool. A submit_interaction dispatcher action routes values to the kind validator — invalid -> retryable interaction_invalid (turn stays parked), valid -> resume. Capability gating from the session's declared `supports` (choice_chips), captured connection-local. The choices kind (choices.py) mirrors choices.rs: request_choices { questions (1-4), reason } with 2-4 options + optional multiSelect; validate_choices (all answered, labels in options, single=one pick XOR other, multi>=1, blank other dropped, one-pass errors); enumerated fallback directive; capability choice_chips. Tests: validator unit tests + the park/resume WS integration test (raise -> interaction_required -> submit_interaction -> resume; invalid-then-resubmit; fallback without capability), validating the shared choices conformance fixtures. Full python/server suite green (364 passed); ruff + compileall clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YbN45JeWDbcjvFqGJvmVD3
🦋 Changeset detectedLatest commit: 3c8b410 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CI runs `ruff format --check`; apply it (line-length reflow only, no logic change). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YbN45JeWDbcjvFqGJvmVD3
brentrager
enabled auto-merge (squash)
August 18, 2026 22:47
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.
Problem
Wave 2 of the full-polyglot Rich Interactions effort. The Rust reference merged in #475 (framework runtime + the
choiceskind / AskUserQuestion). This ports that runtime and thechoiceskind to the Python server, mirroring the reference.Solution
Framework (
interaction.py) — the kind-agnostic runtime, generalizing the existing write-confirmation park/resume:InteractionKindprotocol (kind/capability/tool_schema/parse_request/validate/fallback_directive),InteractionRegistrycatalog (default:choices),InteractionRequest/InteractionOutcome/InteractionFieldError.PendingInteractions— a session-keyed park/resume registry that is the kind-agnostic generalization ofconfirmation.py'sConfirmationRegistry(asyncio future instead of a bool verdict).Per-turn tools (
interaction_tools.py) — mirrors the RustRequestInteractionTool+SubmitInteractionTool, with the bridge folded into the tool coroutine:request_<kind>raise tool per hosted kind. Rich channel (capability insupports): park — emitinteraction_required, awaitsubmit_interaction, resume with the canonical payload. Fallback channel: return the kind's conversational directive (no park).submit_interactiontool, registered only when ≥1 kind is on the fallback path.Wiring:
submit_interactiondispatcher action (peek → match interactionId → validate → invalid emits retryableinteraction_invalidand keeps the turn parked, valid resolves the park); capability gating from the session's declaredsupports(captured connection-local atcreate_conversation_session);interaction_required/interaction_invalidprotocol builders (double-nesteddata.data, matching the shared event schemas).The
choiceskind (choices.py) mirrorschoices.rs:request_choices { questions (1–4), reason }, each question with a ≤12-char uniqueheaderand 2–4 options + optionalmultiSelect;validate_choices(every question answered; labels ∈ options; single-select one pick XORother, multi-select ≥1; blankotherdropped; all errors in one pass); enumerated fallback directive; capability idchoice_chips.Verification
cd python/server && uv run pytest— 364 passed (12 new: validator unit tests + the park/resume WS integration test — raise →interaction_required→submit_interaction→ resume; invalid-then-resubmit; fallback without capability).spec/conformance/fixtures.jsonchoicesfixtures (spec + values → canonical payload).ruff check+compileallclean.test_tool_config_filters_tools_per_agent) updated: the framework interaction tools are always registered (not subject to the agent allow-list), mirroring the Rust runner.@smooai/smooth-operator-server, minor).🤖 Generated with Claude Code