Repository navigation
feat: implement multi-turn AMD in the voice core - #8785
Draft
chenghao-mou wants to merge 104 commits into
Draft
chenghao-mou wants to merge 104 commits into
chenghao-mou wants to merge 104 commits into
Conversation
Observations the session emits, answers AMD sends, the reply decision, the opening, the detach cancel and the attach command, as docs/proposals/amd.md names them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While a run is attached, the session holds speech authorization by default and replies to a committed turn only on that turn's decision (docs/proposals/amd.md, implementation step 1). - The scheduler keeps a held head chosen, not current, until the hold opens or the head is the opening. - A commit holds authorization in the same transition, denies a parked turn, cancels an unplayed older reply and interrupts the current speech. - A decision applies only to the latest committed turn; a turn back from its hook before its decision parks for it. - The silence hold measures from the latest speech boundary and opens only on the deadline it armed. - Detach cancels what it forbids, restores interruptions, settles parked turns and turns still in their hook, then removes the gate. - The gate emits every AmdObservation as VoiceEffect::Amd and journals GateStep and SpeechStep::AuthorizationHeld. - While attached: min_words is skipped, interruptions are forced on, say() and generate_reply() are refused, handoffs are refused, on_user_turn_exceeded and deferred tool replies are skipped, and participant audio is discarded until Activated. Realtime sessions are refused at attach until step 4. The runtime drops the observations until the AMD executor exists (step 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The architecture check refuses comments that point at a docs page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
correction_replaces_the_words looked for the session's final of a case's utterance by the case's own index, which counts from 0 across the case. The session numbers a stream's utterances from 1, in the order they started on that stream. A second utterance's final then matched the first one's number and read as a correction of it. The rule now counts the utterances started on the utterance's stream up to its start. An utterance with no start in the case keeps its index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One test per transition and local rule of the proposal's session side, written against the protocol alone: the hold at commit, keyed and dropped decisions, decisions before and after the customer hook, local supersession, the silence hold timed from backdated VAD boundaries with the eot_delay and commit fallbacks, the entry hold, the opening, every Detach step, the rules while attached, stage instructions, the DTMF tool, preemptive adoption and the observations AMD receives. They sit beside the gate's own tests, in amd_gate_rule_tests.rs and amd_gate_reply_tests.rs. Wired to the gate's surface: answers arrive as VoiceEvent::Amd, attach takes its call, VoiceEffect::Amd names its fields, a forbidding detach is DetachCancel::ForbidReplies and a stopped turn ends as TurnEnd::Stopped. SEND_DTMF_TOOL names the built-in tool. No assertion changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The DST side of the gate's first step: - AMD inputs (attach, activate, decide, detach) sent by a scripted answerer: a search actor with its own stream that attaches in one non-realtime run in five, then answers each turn the session reported, at once or late, now and then for a stale turn, and completes after a drawn number of decisions, with a turn in its hook or a reply held. The release phase answers what AMD still owes. - The recording keeps what the gate observed, opens an AmdTurn per reported commit, and keeps each model request's messages, so a rule can tell which turn a request answers and what it carried. - Rules for the protocol (reply_follows_decision, gate_settles, gate_answers_are_keyed, adopted_request_matches, detached_is_prompt, completion_respects_wait) and for spec invariants 7, 8, 9, 10 and 15. They judge requests, audio at the sink, saved items and the fake VAD's ground truth. - Authored stories for the gate, ported from tests/test_amd.py and the proposal's list. The runtime has no AMD executor yet, so the scripted answerer needs its own way in and out of the loop, for test and dst builds only: an AmdTap hands each VoiceEffect::Amd to an observer (VoiceSession::observe_amd), and VoiceSession::answer_amd sends an answer as VoiceEvent::Amd, as the executor will. Production drops the observations, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four of the ported unit tests failed against the gate for reasons in the tests, not in the gate: - reply_to took any of a request's last two items as the words it answers. A superseded or denied turn commits its user item just before the next turn's, so the newer reply matched the older words. It now reads the request's newest user message. - The uninterruptible-drop test counted the earlier say() as a reply. It now asks whether the dropped turn's words were answered. - The forbidding-detach test played the opening and then committed a turn, but every commit under the gate interrupts the current speech. The playing and the queued speech now both predate the attach. - The opening-instructions test ran on a harness with no LLM, and opening instructions need one (spec §5.1). No assertion changed what it checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rules: - gate_settles asked for a TurnEnded after the run's Detached. Detached is the run's last observation; a turn its detach settled is judged by its outcome instead. - adopted_request_matches judged a heard preemptive generation by the first decision sent. A detach replaces a decision stored while the turn is in its hook, so it now uses the decision applied: the stored one once both it and the hook's return came, else the detach's. It also no longer counts an agent's own send_dtmf_events as AMD's. - gate_cleans_up did not count an adopted preemptive generation as the answer to a turn after the detach. - only_the_opening_plays_first picked the opening as the speech created before the driver's next input, but the session applies Activated after the driver moves on. It reads GateStep::OpeningBypass, the owner the proposal names for invariant 15. Stories: - The correction stories committed under automatic detection and moved on after 100 ms, so the final replaced uncommitted words. They now use manual turns and wait a second, as turns/correction.rs does. - The stage follow-up story sent its tool call to the discarded preemptive generation's chat, and its tool returned nothing, which asks no follow-up. It now uses the reply's chat and a value. - The wait-at-close story ended before the close finished: the close waits on the hosted on_exit until its 30 s bound, as without AMD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A decision with dtmf only kept the reply from adopting the preemptive generation; the reply's request never offered the tool. Python's AMD adds send_dtmf_events to a machine-ivr reply unless the agent has a tool with that id (detector.py on_reply_generation), and the proposal keeps that: the only tool AMD adds is the built-in send_dtmf_events, to a reply whose decision sets dtmf. The gate now gives such a reply, and a correction's remake of it, the advertised tools plus the send_dtmf_events declaration of livekit.agents.beta. An agent's own tool with that id is kept and never doubled. A preemptive generation never gets it. The host runs the tool's body, as it runs every tool. No host attaches AMD yet, so no production reply offers it until the host does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A speech fixes allow_interruptions at creation, and the gate forces interruptions on while a run is attached. A preemptive generation made during the run and adopted by a turn that Detach settled kept the forced value, so an agent with allow_interruptions=False could be cut off after AMD completed. The proposal requires an adopted generation to take the restored value. When the gate applies a decision, the reply now takes the session's current interruptibility, which is the restored one after Detach. Only the gate's path does this; an ungated adoption is unchanged. Found by the ivr_then_human_with_an_uninterruptible_agent story. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every AMD rule had probe: None, so nothing showed a rule could make an expectation against production. Each now has a probe: a real session with the scripted answerer's inputs, as the authored stories drive it, built from shared helpers in fakes::amd::probe. every_probe_reaches_its_contract runs all eleven. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 1024-seed survey reached the AMD rules in runs the stories do not build. Each finding was the rule's: - A request answered a turn when the turn's item was its last user message. A storage partition's text can follow that item, and a host generate_reply after the detach can end with an older turn's item. A request now answers the turn whose item is the newest turn item in it, and only a turn reply or a preemptive generation answers a turn. - A refused attach (a handoff in flight) counted as an attached run. - gate_settles waited only for the first hook issued after the commit. A turn waits behind every older turn's hook still running; one a newer turn superseded never gets its own. It now waits for its own hook, or for those older ones. - gate_settles asked a turn for a reply or its saved words. A hook that answers StopResponse or raises ignores the turn, as Python does, and the uninterruptible drop and paused scheduling end it with no reply. - gate_cleans_up timed a turn after the detach from its commit, though it waited behind an older turn's customer hook. - machine_reply_waits_for_silence judged the silence at the reply's first audio. Python releases the hold once and then leaves the reply to the session, so a false interruption's resume can play it inside a new silence. It now judges the silence when the gate let the reply go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two existing rules failed in runs with AMD attached: - forwarded_while_enabled owed every frame pushed while input was enabled to the recogniser and the detector. The gate discards participant audio from the attach until Activated (spec §5.2). Frames pushed in that window are now owed to no stream, and one heard from it fails the rule. - speech_is_heard found a speech silent past its bound with nothing to wait on. The proposal has it wait legitimately while the gate holds authorization, and under the silence hold until the detector's ground truth shows the needed silence; a release gives the bound again. lk_agents_voice::amd re-exports Hold so the rule can read the step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second survey pass, over seeds 0-2047, found more rule errors: - stage_instructions_never_saved, dtmf_only_when_allowed and machine_reply_waits_for_silence read the first decision sent. A detach replaces a decision stored while the turn is in its hook, so they now read the decision applied (AmdView::deciding). - A turn waits behind every older turn's hook, including one issued after its own commit; the hook wait now counts those too. - gate_settles asked a turn that ended as replied for a model request. A reply the session made can still fail to reach its model (an injected port failure) or be interrupted first. It also asked a dropped turn for its words, though a reply scheduling rejected (a drain begun while the turn waited) is a traced refusal, as on the ungated path, and a turn with no words has none to keep. - gate_cleans_up asked every turn after the detach to be answered within a bound. Whether it is depends on the session's ordinary rules (hooks, interrupts, a turn that asked for no reply, faults). The proposal's invariant 10 is that the gate is gone: the rule now checks that no hold and no gate step follow Detached, apart from a late answer the session drops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A turn's observations (ReplyCreated, TurnEnded, SilenceHold) go only to the run that gated it, and to none after its Detach. A turn Detach settled no longer reports to a second run attached meanwhile. - A turn records at commit whether the run was active. Only a bound turn's decision moves the hold, so an allow for a turn committed before Activated keeps Hold::Entry even when its hook returns later. - AMD's interruptions are a requirement laid over every option layer, so a host override_options entered during AMD does not turn them off. At detach the layers decide again. - A tool update that arrives under AMD owes no deferred reply, and a reply rendered when AMD attached is not scheduled. - The close releases the gate as Detach would (Keep, turns settled to no reply, Detached reported), so a draining close plays what the gate held. - A decision for a turn that ended without one is dropped as TurnEnded. - The opening is recorded only when the scheduler admitted it. - A correction after Detach remakes the gated reply with the same stage instructions and tools. - AmdCommand::Attach carries the DTMF ToolSpec; the core no longer copies its schema. State: Latest holds a TurnReply enum (Waiting, Parked, Decided, Applied, Ended) in place of decision, settled and Gate.parked; a Detach-settled decision rides on the pending or decided turn instead of AgentActivity::amd_settled; the gated reply and its request payload live on the activity; gate_remake and gate_reply_speech are one query; reply_to_turn and the correction share ReplyPayload; turn instructions have a TurnInstructionsScope; TurnEnd::HeldForHandoff is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…posal's steps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d rules - gate_settles: an applied allow requires a heard reply, or evidence independent of the session's report (a traced scheduling refusal, an injected fault, the person or host acting, the close, a model or voice the case still owes). A deny requires the words kept and no reply. TurnEnd::Dropped and ReplyCreated alone no longer count. - gate_cleans_up: a turn committed after Detached with nothing in its way gets a reply again; a refused attach is not the gate acting. - speech_is_heard: the gate exemption is per speech. The opening never waits on the hold; a reply to a bound turn with an applied allow waits only on its silence hold. - machine_reply_waits_for_silence: judged at the authorization instant; a detach exempts only a reply it let go. - only_the_opening_plays_first: the window stays open until an allow is applied to a bound turn; at most one say or generate_reply bypasses a run's hold; a speech authorized before the attach is exempt; speech after the run completed does not count against the opening. - forwarded_while_enabled: a frame pushed during the AMD discard and fed to STT or VAD after activation fails, beyond the activation instant. - adopted_request_matches: the agent-declares-DTMF waiver covers only requests after the declaration. - gate_answers_are_keyed: a request is blamed on a stray decision only if no allow of its own came first. Rule and story comments state the rule instead of citing the proposal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… astray The search may now attach a second run after the first completed, complete before the first decision or before activation, send the latest turn's decision twice, and answer for a turn the session has not committed (AmdDecideAhead) or for an earlier run's turn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
observations_pair fails a run that hears the same AgentBusy twice in a row, a second SilenceHold entry or an exit without one, or a silence hold for a turn whose applied decision asked for no silence. Probed with a voicemail greeting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pletion A greeting held at the head plays during a draining close, and the run hears Detached. A correction after Detach remakes the unheard reply with its stage instructions. Both fail before the gate fixes. Story comments state the rule instead of citing the proposal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turn observations go only to the gating run. A turn binds at commit. The close releases the gate locally. Attach carries the DTMF ToolSpec. AMD's interruptions lie over every option layer. Deferred tool replies owed under AMD are dropped. A held head keeps the opening behind it, as in Python. Invariant 7 is judged when the gate lets the reply go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The records the AMD machine needs: categories and stages, the prediction, menu and completion events with the spec's fields, the options with their defaults and the constructor's checks, and the effects a run asks of its executor. A classifier request carries the stage, the previous prediction, the recommended list, the speech duration and at most 20 history items, and renders its state and dual transcripts as Python's json.dumps does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Amd steps on session observations, classifier and menu results, AMD finals, the callee leg and its deadlines, and answers with effects. It ports the stage transitions of _fsm.py and the rules detector.py keeps around them: the likely-human downgrade, the counters, forgetting the category after an error or timeout, and completing on a stage the application handles. A turn's reply is decided as soon as its prediction exists. The request, the late-final wait and the right to reply are owned apart, so an empty turn reuses a pending result. Completion detaches in the same transition and settles pending turns with the "AMD completed" row; amd_completed follows once the session detached and the legs closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 118 tests ported from Python's detector scenarios now drive the machine through its own types: `Prediction`, `AmdReason`, `MenuObserved` with `session_id`, `ClassifierItem`, `AmdSetup` and the options with `opening_text` and `opening_instructions`. `stage::next` returns an `Option`, and `state_json` is parsed before the tests compare it. `CancelClassify` names no request; the harness takes the request in flight. Three items come from the tests' side. `In::Classified` carries a `Classification` with the model time the leg measured, because Python times only the `classify` call. `ClassifyRequest` names its session turn. `stage` exports `LIKELY_HUMAN_STAGES`, and `HISTORY_LIMIT` is public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`stage::next` matches the terminal stages and returns one effect. The machine drops `WatchedSpeech.live`: the gate's `AgentBusy` already counts every queued or playing speech except the preemptive generation. It also drops speech tracking before activation, since the gate reports participant speech only once it is active. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The run activates before the gate applies `Activated`, so a commit in between reaches an active run while the gate treats the turn as unbound and never holds for it. `TurnCommitted` now carries `bound`, set from the gate's own state, so the run can give that turn the first row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A menu result at or after its 5 s deadline is dropped, as a late classifier result is, whichever reaches the machine first. A menu with more than 20 options fails Python's validation, so it is not observed instead of being truncated. `AmdEffect::CancelMenu` stops the leg where Python cancels `_menu_atask`, when a new extraction replaces it, at its deadline and at completion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gate sends `ReplyCreated`, then `TurnEnded { Replied }`, then enters
the silence hold. The machine released a held reply on any turn end, so
at the inference timeout limit it detached while the reply still needed
silence. A held reply now lasts from its allowed decision until
`SilenceHold { held: false }`, or until a turn end that prevents the
reply. A turn that asked for no reply, or ended before its prediction,
is never held.
At the inference timeout limit the machine completes before the turn's
decision unless the reply would wait for silence, as Python's
`_record_prediction` runs `_update_idle` first. The speech clock now
keeps where the silence starts, from the latest speech end or from the
commit minus `eot_delay`, to tell.
A turn the gate did not bind gets the first row and no AMD turn. Ended
turns older than the newest prediction are pruned. The test harness
sends gate observations in the gate's order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…error The Python binding now names a ValueError and a TimeoutError as host error kinds, and AMD's classifier gives them an inference_error prediction, as Python's _classify does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reply's run refuses an offered tool without policy metadata, so a reply that AMD allowed DTMF failed before its first request. The gate now adds the tool's default policies to the reply's agent frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A string default for a field of an enum record of the same module is now emitted as the member, so the model's default is the value a validated one would be. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Declare AMD's options, events, entry and decision-model port in ABI, give the session an enter_amd command and the run a host class, forward each prediction and the completion to the remote session host, and regenerate the bindings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AMD(session, ...) selects the models, enters a run on the session, closes the models it created, runs the DTMF tool and delivers the run's events. session.amd names the running detector. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each test is named after the `tests/test_amd.py` test on main it ports and drives a call through the public API: the person speaks into the session's microphone and AMD's classifier is a model scripted by the turn's words. They cover options and their errors, events, entry refusals, model selection and ownership, completion and listeners, classifier failures, decision models, the Inference feature header (through a local gateway), the session rules while AMD runs, stage instructions, the DTMF tool, and predictions and completions forwarded to the remote session host (over the console socket). They fail against the stub. test_dtmf_tool_propagates_cancelled_publish passes already: v2.0's tool propagates cancellation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One row for each of the 228 tests of `tests/test_amd.py` on main: the new Python host test, the Rust unit tests, DST rules and stories that check the same behavior, or why it is out of scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`tests/host/test_amd_host.py` repeated most of `test_amd.py`. Drop its duplicates and keep one file: - `test_an_ivr_reply_runs_the_dtmf_tool` moves as it is. - `test_a_human_at_call_start_completes_at_once` also checks that the prediction reaches listeners before the completion, that a second AMD is refused while one runs, and that every `execute()` returns the same object. - `test_decision_model_error_is_an_inference_error` also checks a decision model that raises `ValueError`. - `_choice_model` uses `llm.DecisionModel` without type ignores. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four tests asserted `main`'s mechanics rather than AMD's behavior: - `test_machine_silence_default_and_validation` read the default from `inspect.signature(AMD)`. v2.0 declares it once, on `AMDOptions`. - `test_llm_calls_use_session_connection_options` compared the provider's options with the session's. v2.0's framework runs the retries and gives the provider one attempt with `max_retry=0`. - The Inference gateway kept the headers in a plain dict. The client sends header names in lowercase; compare them case-insensitively. - The two handoff tests waited for `current_agent`, which names the arriving agent at once. Wait for the handoff's history item, as `main` awaits the handoff's task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`compose_extra` let the instance's `extra_kwargs` replace the call's key by key, so a model's own `extra_headers` replaced the call's whole header map and AMD's `X-LiveKit-Client-Feature: AMD` was lost. Merge the two maps; the call's header wins on a shared name, as in `main`'s `inference.LLM.chat`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`main`'s AMD takes an `llm.DecisionModel`, and its tests build one; v2.0 had no such type, and AMD accepted any object with `capabilities.decision_kinds` and `evaluate()`. Add `main`'s `llm.DecisionModel`, `Choice`, `Probability`, `Score`, their results and `DecisionResponse` as a thin host type in `llm/decisions.py`. `evaluate()` validates the decisions and the response as `main` does and makes one attempt; it does not retry and emits no metrics. AMD accepts only an `llm.DecisionModel`, and the ABI's decision proxy names it as its host type. `_choose` builds an `llm.Choice` and reads an `llm.ChoiceResult`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`AMD.__aenter__` created the models it names by strings before the session refused the attach, and a refused instance became `finished`. `main` checks the session first, so a refused entry creates no model and the same instance can enter once the session allows it. - `AmdCommand::Check` answers with the attach's refusals, in the same order, and installs nothing. The host asks it through `VoiceSession.check_amd(amd_stt)` before its classifier and opening checks, as `detector.py` orders them. - The check and the attach take the session's handoff turn before they are sent. An `update_agent()` called just before them sets its toolsets up before its command reaches the loop, so without the turn the loop did not yet see that handoff in flight. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`beta.send_dtmf_events` returned a plain string, and on a failure
returned failure text that quoted the room's error. `main` (spec §11.1)
returns `ToolResult(..., reply_required=False)`, so a sent key asks for
no follow-up reply, and raises `ToolError("Failed to send DTMF
events.")` with no cause, so the provider's error never reaches the
model or a log.
The core now answers `Result<String, SendDtmfError>`: one fixed
`ToolError` message for a room that is not connected or a key it
refused. The tool wraps the answer in a `ToolResult` and raises the
error from `None`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The core refused these while AMD's gate was attached, but the host never raised: `say()` and `generate_reply()` returned a handle whose `exception()` held the refusal, and `update_agent()` was dropped in silence. `main` raises `RuntimeError` from each while `session.amd` is set. Raise the same errors, with `main`'s messages; the core still refuses a reply or handoff that reaches it another way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ption Port `main`'s `test_amd_preserves_false_interruption_resume`, the one AMD test without v2.0 coverage. A realtime model whose server detection the session switched off, with interruptions off in the session: AMD forces its screening reply interruptible, a noise pauses it, and with no words it resumes once, uninterrupted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The proposal now lists each difference that remains between v2.0's `AMD` and `main`'s, and why: options on `AMDOptions`, string-valued enums, the thin `llm.DecisionModel`, no `ivr_detection`, listener errors, and the session's entry check before model creation. It links the coverage table from the implementation order. The coverage table describes the merged state: the implementation's dev tests merged, the tests that read v2.0's contracts, the header merge, the DTMF contract, and the false-interruption gap closed by a Rust test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`compose_extra` merged the model's `extra_headers` with the call's but compared names exactly, so a model header that differs from the call's only in case stayed beside it. `Headers` kept the call's value on the wire, by the order of the merge alone. A model's `extra_headers` that was not a map dropped the call's headers, so AMD's client feature tag never reached the gateway. Remove the model's headers that name a call header in any case, then add the call's. A model value that is not a map gives way to the call's map. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`main` accepts `float("inf")` for every timeout and for
`machine_silence_threshold`. v2.0 refused it as not positive, or as
negative for the threshold. Map `inf` to `Duration::MAX`, on which
every deadline saturates. NaN and negative values stay refused with
`main`'s messages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A classifier failure outside the provider taxonomy ended the run with `internal_error` but logged nothing. `main`'s `_on_task_done` logs "amd task failed" at ERROR with only `error_type`, the exception's class name. Log the same record from the classifier leg, and restore `main`'s assertions in `test_unexpected_inference_errors_finish_with_internal_error`: an ERROR record exists, carries `error_type` and has no `exc_info`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`voice.amd.__all__` exported the records the host hands the runtime (`AmdEntry`, `AmdLlm`, `AmdDecision`, `AmdStt`, `AmdClassifier`, `AmdChoiceRequest`, `AmdEvent`), because the file's `path` placed every record of its module there. Drop the file-level `path` and name it on each public record. The host imports the binding records from `_generated.amd`. The decision model's label now calls `_label`, the startup log's helper, so the host keeps one label function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`send_dtmf_events` mapped every publish error to
`SendDtmfError::Failed`, so a publish the host cancelled reached the
model as `ToolError("Failed to send DTMF events.")`. Add
`SendDtmfError::Cancelled`, raised as `asyncio.CancelledError`, for a
host error of kind `Cancelled`.
Record the tool's contract in `docs/tools.md`: it asks for no
follow-up reply after a send. Drop the e2e test's unused second reply.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`_complete` awaited the owned models' close before it cleared `session._amd`, so `say()`, `generate_reply()` and `update_agent()` kept raising during a slow close. `main`'s `_finish` detaches before `_cleanup` closes the models. Clear `session.amd` and AMD's DTMF tool first, then close, then resolve `execute()` and fire `amd_completed`. Port `test_slow_resource_close_does_not_keep_amd_attached` for the owned STT and LLM. The Python host stays the owner of the models it creates from strings: the runtime has no close port for a host LLM or STT, so `OwnedModels` stays for a host that hands the runtime a closer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`__aenter__` read the models' `provider` and `model` for its startup log after `enter_amd`, outside the cleanup guard. A property that raised left the accepted run attached, so the session stayed gated and the models AMD created stayed open. Read the labels before the attach, and guard the rest of the setup: an error closes the run and the owned models before it propagates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Entering AMD on a session that is not running raised "VoiceSession isn't running". Raise `main`'s "start AgentSession before entering AMD" with v2.0's class name. `AMD.emit` failed the run when `inspect.signature` could not read a listener. Call such a listener with every argument, as `rtc.EventEmitter.emit` does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A `human` prediction completes the run before its listeners hear it, on `main` too: `_record_prediction` runs the `COMPLETE` effect first, and `_finish` ignores the listener's later `internal_error`. Pin it, so the reason stays `finished` when such a listener raises. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y check - The remote session host hears a prediction and the completion before the run's host reads them (spec §13). - `AmdRun::fail`, a host listener that raised, ends the run with `internal_error`, and a later failure or close changes nothing. - `check` (`AmdCommand::Check`) answers as the attach would on an idle, an attached and a closed session, and attaches nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Python host API section now records: the unstarted-session message, `inf` timeouts, the removed `push_audio`, the private binding records, the cancelled DTMF publish and the tool's no-reply contract, listeners of the completing prediction and the window before a listener's failure arrives, `session.amd` cleared before the owned models close, the "amd task failed" log, and case-insensitive header merging. The runtime section names the host as the owner of the models it creates and the deadlock of a toolset `setup()` that awaits AMD entry under its own handoff. The coverage table counts the rows these fixes changed and lists the host tests that port no single test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been 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.
Implements the multi-turn AMD proposal (#8766) on v2.0, in five steps:
_fsm.pyanddetector.pyrules that answers the gate.AMD(session, ...)withmain's names, events and model selection, plus a thinllm.DecisionModel.docs/proposals/amd.mdlists the remaining differences frommain;amd-test-coverage.mdmaps each ofmain's 228 AMD tests to its v2.0 test.Outside AMD:
send_dtmf_eventsnow returns a result that asks for no follow-up reply and raisesToolErroron failure, as onmain. A call's inference headers now win over a model's, in any case. The branch also fixescorrection_replaces_the_words, which numbered utterances differently from the session.Review focus:
amd_gate.rs,amd/machine/,runtime/src/voice/amd/,activity/realtime/gated.rs,voice/amd.py, and the DST rules underrules/amd/.Initial prompt and agent context
Model: Claude Opus 5.5. For each step, one agent wrote the tests and another wrote the implementation, in parallel and without seeing each other's work; a third merged them. Claude Fable 5.2 and GPT-6.2 Astra reviewed each merge before its fix commits.
🤖 Generated with Claude Code