Agent state stays "speaking" after a realtime reply in sessions without audio output
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
バグは AgentActivity._realtime_generation_task_impl にあり、listening への遷移が if audio_output is not None: の分岐内に置かれています。音声出力なしで状態をリセットするパイプラインの LLM パスと比較し、_update_agent_state がどこで呼ばれているかを確認してください。完了の条件は、テキストのみのリアルタイム応答が listening で終わること(バックグラウンドの発話が残っている場合は thinking)であり、音声出力のないセッションをカバーするテストを含めることです。
索引モデルが issue の本文から書いたものです。
説明
Bug Description
In a session without audio output, a realtime model's reply leaves the agent state at speaking. It never goes back to listening. Clients that take turns on lk.agent.state hang after the first realtime reply. Our text-mode interviews and our simulation harness are both affected.
In AgentActivity._realtime_generation_task_impl, the transition back to listening sits inside if audio_output is not None:. A text-only session has no audio output, so it never takes that branch. The pipeline (STT-LLM-TTS) path resets the state without an audio output, so the two paths behave differently.
Expected Behavior
After a realtime generation finishes, the agent state goes to listening, or to thinking while background speeches remain, whether or not the session has an audio output. This matches the pipeline LLM path.
Reproduction Steps
1. Set LIVEKIT_API_KEY and LIVEKIT_API_SECRET and run the script below. No room is needed.
2. Compare the pipeline LLM with the two realtime models.
import asyncio, sys
from livekit.agents import Agent, AgentSession, inference
async def run(model):
is_realtime = model in ("google/gemini-3.8-live", "openai/gpt-realtime-2.1")
llm = inference.RealtimeModel(model, modalities=["text"]) if is_realtime else inference.LLM(model)
session = AgentSession(llm=llm)
states = []
session.on("agent_state_changed", lambda ev: states.append(ev.new_state))
await session.start(agent=Agent(instructions="You are a friendly interviewer."))
await session.generate_reply(instructions="Ask the user one short question.")
await asyncio.sleep(2)
print(f"=== {model}: states {states} -> final {session.agent_state!r}")
await session.aclose()
for m in sys.argv[1:]:
asyncio.run(run(m))
# python repro.py google/gemma-4-31b-it google/gemini-3.8-live openai/gpt-realtime-2.1
Output:
=== google/gemma-4-31b-it: states ['listening', 'thinking', 'speaking', 'listening'] -> final 'listening'
=== google/gemini-3.8-live: states ['listening', 'speaking'] -> final 'speaking'
=== openai/gpt-realtime-2.1: states ['listening', 'speaking'] -> final 'speaking'
The reply text is delivered in every case. Only the state is stuck, and it happens with both realtime providers.
Operating System
macOS 15
Models Used
LiveKit Inference: google/gemini-3.8-live, openai/gpt-realtime-2.1 (realtime, modalities=["text"]); google/gemma-4-31b-it as the pipeline comparison
Package Versions
livekit-agents==1.8.8
# also present on main (597e6b49)
Session/Room/Call IDs
No response
Proposed Solution
# In AgentActivity._realtime_generation_task_impl, update the agent state whether or not
# there's an audio output, and keep only the audio-specific work under the check:
self._session._update_agent_state("thinking" if self._background_speeches else "listening")
if audio_output is not None:
self._on_end_of_agent_speech(ended_at=time.time())
if self.interruption_enabled:
self.interruption_by_audio_activity_enabled = True
current_span.set_attribute(trace_types.ATTR_SPEECH_INTERRUPTED, speech_handle.interrupted)
Additional Context
Text-only realtime sessions are useful when the realtime model's text output is spoken by a separate TTS, or when the same agent serves both voice and text interviews. The only workaround we've found is setting the state to listening through the private _update_agent_state when a realtime reply finishes without an audio output.
Screenshots and Recordings
No response
- 主要言語
- Python
- スター
- 14.6k
- フォーク
- 3.9k
- 平均マージ
- 3日 1時間
- マージ済み PR(30日)
- 166
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
livekit/agents のほかの issue
-
Assistant markup is stripped from chat history when expressive mode is off対応中かも @ShivamSharma43 が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hosts再び着手できるかも @AbarnaaSree が 48 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
livekit/agents#7022 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Google LLM plugin leaves Gemini thinking tokens out of completion_tokens対応中かも @ninglinLiu が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
Muse STT audio buffered before the websocket connection stays delayed for the whole stream対応中かも @DEVJHAWAR11 が今日担当しました。 オープンbug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
livekit/agents#7876 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
docs: the dev-setup table and AGENTS.md name the reviewed_by guard that CI's Changelog job runsオープンarea: tools documentation good first issue ready for a contributor
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
eyalgolan/statecraft-israel#873 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 5 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信