Skip to content

Follow-up continuation: limitation, workaround, and the deterministic agent design

Status: design reference for the custom conversation agent we will build later. The prompt workaround below is live; the deterministic agent is not built or approved yet. This doc is the build spec and the record of why it is needed. Date: 2026-12-03 Evidence: observed on production conversation.fast (Kiais fast via core llama_cpp), 2026-12-03, text-only and on the c3-b TV satellite. Labels: observed / documented / inferred. Companion: troubleshooting record (how to diagnose live), Kiais integration (prompt history, deployment).

1. The limitation

Home Assistant decides whether to keep the microphone open for a follow-up answer only by the last character of the assistant reply. components/conversation/chat_log.py:

@property
def continue_conversation(self) -> bool:
    last_msg = self.content[-1]
    return (
        last_msg.role == "assistant"
        and last_msg.content is not None
        and last_msg.content.strip().endswith(("?", ";", "?"))
    )

The flag is copied into the result (components/conversation/util.py, async_get_result_from_chat_log → ConversationResult.continue_conversation), sent to the satellite in the ESPHome INTENT_END event (components/esphome/assist_satellite.py), and the firmware acts on it (webos-voice-satellite, crates/esphome-api/src/voice.rs, finish_run): continue_conversation → a follow-up run without wake word, same conversation id; otherwise re-arm to wake-word mode.

There is no config knob and no structured "I am asking a question" signal in the Assist LLM API — the heuristic is the only mechanism. Commercial assistants do not parse punctuation: they signal "keep listening" as structured dialog state (Alexa shouldEndSession: false + Dialog.ElicitSlot/Delegate, Google expectUserResponse/expected_inputs, Siri's dialog model). That is the gap a custom agent can close locally.

2. Failure-mode catalog (observed)

All on conversation.fast, 2026-12-03. The mic closed because the reply did not end in ?.

# Reply shape Example (sanitized) Ends Why it fails
A Imperative clarification, no ? "Dime qué prefieres." s no question mark at all
B Question then option list "¿Qué música te apetece ahora? Tengo celta, clásica de Bach, Dvořák, Tchaikovsky, o algo más cañero como Eskorbuto." . contains ? but ends in .
C Question then a trailing sentence "¿En qué habitación? La del salón está encendida." . same as B

Shape B is the fast model's habit: question first, then options, ending in a period. It recurred even after a prompt rule forbade enumerating options — "don't list options" fights the model and loses. The workaround that works folds the options into the question (§3).

Related fast-tier slip (same family, different mechanism): a spoken "Error: Unexpected tool argument response: Expecting ',' delimiter…" is the model emitting malformed tool-call JSON that llama_cpp fails to json.loads (_decode_tool_arguments). The Kiais gateway forwards function.arguments byte-identical (it only repairs tool names), so this is upstream model output, transient, fixed by retry. The future agent should handle it gracefully (§5.3).

3. Current workaround (live): fold options into the question

The ambiguity rule in the llama_cpp "Fast" subentry prompt, as applied 2026-12-03 (second iteration; the first only forbade imperatives and did not stop shape B):

Si la petición es ambigua, responde con una sola pregunta corta que acabe en «?» y nada más. Si quieres ofrecer opciones, mételas dentro de la pregunta, por ejemplo «¿Qué música te apetece: celta, clásica o rock?» o «¿En qué habitación?». Nunca uses imperativos como «Dime qué prefieres» ni añadas una frase después de la pregunta: si el final no lleva «?», el micrófono se cierra y no se oye la respuesta.

Verified text-only: "Pon música" → "¿Qué música te apetece: celta, clásica o rock?", continue_conversation: true.

Limits: still a heuristic on a small model — it reduces but cannot guarantee compliance. When it slips, the user re-wakes (conversation id is kept, so context survives). Application path and the delayed-.storage-save gotcha are in the troubleshooting record. Do not "fix" this by making the satellite always listen after every reply: that re-opens the false-wake exposure EXP-015/G4 exists to measure on the TV satellites.

4. The deterministic design (the future agent)

4.1 Core idea

A custom conversation agent builds its own ConversationResult, so it can override continue_conversation with a rule that does not depend on the last character. ConversationResult is a mutable dataclass (continue_conversation: bool), so the override is a few lines. The existing prototype scripts/voice-assistant/custom_components/kiais_conversation/ already implements the full agent (own Kiais HTTP client, tool loop, streaming) and currently defers to HA's rule at conversation.py:196:

# continue_conversation follows Home Assistant's rule (the answer ends in "?").
return conversation.async_get_result_from_chat_log(user_input, chat_log)

4.2 The override

result = conversation.async_get_result_from_chat_log(user_input, chat_log)
last = chat_log.content[-1]
if last.role == "assistant" and last.content:
    # Keep the mic open if the reply asks a question anywhere, even when it then
    # lists options and ends in '.' (the fast model's habitual shape B).
    result.continue_conversation = _asks_question(last.content)
return result

Detection rule _asks_question, from simplest to most precise:

  • "?" in text — catches shapes B and C; may over-trigger on a stray ? quoted in a statement.
  • Spanish interrogative regex ¿[^?]*\? (or a trailing ¿…?) — fewer false positives; still misses an imperative clarification (shape A), which is fine because that is not a question.
  • Best: have the model emit an explicit signal (a dedicated tool or a structured field) and read that instead of parsing text — the commercial-assistant pattern. Requires the model to comply, so combine with the regex as a fallback.

Whatever the rule, keep it conservative enough not to hold the mic open on plain statements (false-wake / always-listening exposure, §3).

4.3 Deployment (what it actually costs)

The prototype is reference-only today; production runs core llama_cpp. To ship the deterministic rule:

  1. Vendor the component into the chart: apps/home-assistant/custom_components/kiais_conversation/
  2. a ConfigMap template (GitOps), per the fallback section of kiais-integration.md.
  3. Add a config entry pointing at Kiais (fast, same prompt / Assist API), and switch the Kiwi pipeline's conversation_engine to the new agent.
  4. Restart HA; re-verify streaming, the Kiais tool-call stream quirk, the tool loop, and Spanish error speech.
  5. Own the maintenance: the prototype re-implements the LLM client / tool loop / streaming that core llama_cpp already provides, so it must keep parity with HA's Assist API and the Kiais quirk on every HA upgrade. This ongoing cost is why kiais-integration.md recommends core llama_cpp and why this is deferred until the prompt workaround proves insufficient.

4.4 Alternatives considered

  • Always continue (brief follow-up window after every reply): deterministic but keeps the mic open more → false-wake exposure on the TV (EXP-015/G4). Rejected as the default.
  • Upstream HA fix: make core continue_conversation detect a question (or let the LLM signal it explicitly). The proper long-term fix, but a core feature request we do not control locally. Worth filing; the custom agent is the local bridge until then.

5. Requirements for the future agent

  1. Deterministic follow-up (§4): continue when the reply asks a question, regardless of trailing text; do not hold the mic open on plain statements.
  2. Parity with core llama_cpp: Assist API tools, streamed deltas, the Kiais stream quirk handling, temperature/max_tokens/top_p from the subentry, Spanish error speech.
  3. Graceful malformed tool-call JSON: on json.loads failure of tool arguments, retry the completion once (or attempt a conservative repair) instead of speaking the parse error. Log the raw arguments for diagnosis; never speak a stack trace.
  4. No regression in tool-call correctness (fast tier ~93% baseline, experiments/conversation-agent-eval.md).
  5. Privacy: chat logs hold raw household STT — do not persist them beyond the session, never commit them, shred scratch.

6. Acceptance / test plan

Text-only via POST /api/conversation/process (agent under test), assert the returned continue_conversation flag — no audio, no satellite, no action:

Probe Expected reply Expected flag
"¿Está encendida la luz?" a room question ending ? true
"Pon música" a music question ending ? (options folded in) true
Regression shape B: force a question + trailing options any reply containing ? true (the deterministic fix)
A plain statement / action confirmation no question false

Then on-satellite: a music request → clarifying question → answer without re-waking, same conversation id. Re-run the false-wake screen if the continuation window changes.

References

  • Troubleshooting record — live diagnosis, prompt application path.
  • Kiais integration — prompt history, deployment, rollback, the stream quirk.
  • Conversation agent evaluation — fast-tier tool-call correctness.
  • Prototype: scripts/voice-assistant/custom_components/kiais_conversation/conversation.py.
  • HA core: components/conversation/chat_log.py, util.py, models.py; components/esphome/assist_satellite.py; components/llama_cpp/entity.py.
  • Satellite: webos-voice-satellite crates/esphome-api/src/voice.rs (finish_run).