OpenSource-Hub

agents

フレームワーク

livekit/agents

リアルタイム音声 AI エージェントを構築するためのフレームワーク。

概要

LiveKit は、リアルタイム対話エージェントを作成するためのオープンソース Python フレームワークです。STT、LLM、TTS 統合、タスクスケジューリング、WebRTC クライアント、電話統合、RPC データ交換、セマンティックな発話区切り検出をサポートします。マルチエージェントのハンドオフと組み込みテストフレームワークを提供します。

README プレビュー

\n\n\n  \n  \n  \n\n\n\n\n\n\n[](https://pepy.tech/projects/livekit-agents)\n[](https://livekit.io/join-slack)\n[](https://twitter.com/livekit)\n[](https://deepwiki.com/livekit/agents)\n[](https://github.com/livekit/livekit/blob/master/LICENSE)\n\n\n\nLooking for the JS/TS library? Check out [AgentsJS](https://github.com/livekit/agents-js)\n\n## What is Agents?\n\n\n\nThe Agent Framework is designed for building realtime, programmable participants\nthat run on servers. Use it to create conversational, multi-modal voice\nagents that can see, hear, and understand.\n\n\n\n## Features\n\n- **Flexible integrations**: A comprehensive ecosystem to mix and match the right STT, LLM, TTS, and Realtime API to suit your use case.\n- **Integrated job scheduling**: Built-in task scheduling and distribution with [dispatch APIs](https://docs.livekit.io/agents/build/dispatch/) to connect end users to agents.\n- **Extensive WebRTC clients**: Build client applications using LiveKit's open-source SDK ecosystem, supporting all major platforms.\n- **Telephony integration**: Works seamlessly with LiveKit's [telephony stack](https://docs.livekit.io/sip/), allowing your agent to make calls to or receive calls from phones.\n- **Exchange data with clients**: Use [RPCs](https://docs.livekit.io/home/client/data/rpc/) and other [Data APIs](https://docs.livekit.io/home/client/data/) to seamlessly exchange data with clients.\n- **Semantic turn detection**: Uses a transformer model to detect when a user is done with their turn, helps to reduce interruptions.\n- **MCP support**: Native support for MCP. Integrate tools provided by MCP servers with one line of code.\n- **Builtin test framework**: Write tests and use judges to ensure your agent is performing as expected.\n- **Open-source**: Fully open-source, allowing you to run the entire stack on your own servers, including [LiveKit server](https://github.com/livekit/livekit), one of the most widely used WebRTC media servers.\n\n## Installation\n\nTo

FAQ (5)

トラブル対応
ワーカーのメモリ使用量を削減するために、LiveKit Agents の EOT 重みプリロードを無効にするにはどうすればよいですか?

PR #7580 を含む LiveKit Agents のリリースにアップグレードしてから、LIVEKIT_AGENTS_PRELOAD_EOT=0 を指定してワーカーを起動してください。無効化の値としては 0、false、no、off が使用できます。

一時的にシェルから起動する場合:

export LIVEKIT_AGENTS_PRELOAD_EOT=0
python your_worker.py

systemd ワーカーの場合は、以下を追加してください:

[Service]
Environment=LIVEKIT_AGENTS_PRELOAD_EOT=0

これにより、軽量な VAD のプリロードは維持したまま、約 240 MB の end-of-turn モデルのプリロードをスキップします。後でローカルの TurnDetector が実際に使用された場合、その重みは初回使用時に遅延的にロードされます。Linux の forkserver では、EOT プリロードはデフォルトで有効のままです。1 台のホストで複数のワーカーを実行する場合は、1 つの AgentServer で num_idle_processes を大きく設定することで、ワーカーごとにロードする代わりに単一のコピーを共有することもできます。

参照 Issue #7579
トラブル対応
LiveKit Agents の THREAD executor がシャットダウン時に「job did not ack shutdown in time」でハングする問題を修正するにはどうすればよいですか?

livekit-agents を **1.8.3 以降**にアップグレードしてください。このシャットダウンの競合状態は PR #7225 で修正されました。1.8.1 を含むバージョンでは、アイドル状態のプリウォーム済み THREAD ランナーが、シャットダウンの確認応答が読み取られる前に終了すると、ハングする可能性があります。

pip install --upgrade 'livekit-agents>=1.8.3'

uv を使用している場合:

uv add 'livekit-agents>=1.8.3'

その後、ワーカーを再起動し、アイドル状態のランナーが初期化された後に SIGTERM/Ctrl+C を送信してください。ワーカーは job did not ack shutdown in time エラーを繰り返すことなく、速やかにシャットダウンするはずです。

すぐにアップグレードできない場合は、このハングが発生しない JobExecutorType.PROCESS を使用してください。2回目のシグナルを送信してもプロセスが強制終了されるだけであり、グレースフルな回避策ではありません。

参照 Issue #7226
トラブル対応
LiveKit Agents で JobExecutorType.THREAD を使用した際に発生する "ResourceWarning: unclosed event loop" を修正する方法

この問題は、livekit-agents==1.8.4 などの影響を受けるバージョンで発生します。_ProcClient.run() は asyncio イベントループを作成しますが、保留中のタスクのキャンセル、非同期ジェネレーターのシャットダウン、スレッドループのリセット、ループのクローズを行いません。

**推奨される修正:** PR fix(ipc): close the job loop when the runner exits(issue #7629 を修正)を含むリリースに livekit-agents をアップグレードしてください。

すぐにアップグレードできない場合は、_ProcClient.run() 内の finally ブロックにパッチを適用し、asyncio.run() と同じシャットダウンシーケンスを実行してください。

finally:
    loop_monitor.stop_monitoring(loop)
    try:
        pending = [t for t in asyncio.all_tasks(loop) if not t.done()]
        for task in pending:
            task.cancel()
        if pending:
            loop.run_until_complete(
                asyncio.gather(*pending, return_exceptions=True)
            )
        loop.run_until_complete(loop.shutdown_asyncgens())
        loop.run_until_complete(loop.shutdown_default_executor())
    finally:
        asyncio.set_event_loop(None)
        loop.close()

一時的な回避策として、スレッドの代わりにプロセス分離を使用してください。

server = AgentServer(job_executor_type=JobExecutorType.PROCESS)

修正後、完了したジョブループは is_closed() == True を返すようになり、Python は ResourceWarning: unclosed event loop を出力しなくなります。

参照 Issue #7629
トラブル対応
LiveKit Agents で Muse STT のトランスクリプトと end-of-turn イベントが遅延するのはなぜですか?また、音声ラグを修正するにはどうすればよいですか?

根本原因:SpeechStream._send_audio(livekit-plugins-meta)において、ペーシングクロック(pacing_origin)はストリームの開始時ではなく、最初のパケットが*送信*された時点で開始されます。_runは先に_connect_ws()をawaitするため、Muse websocketの接続中にキューに入ったオーディオフレームは永続的なオフセットを生じさせます。ペーシングは実時間より速く送信されることはなく、バックログが追いつかれることもないため、ストリームの残り全体で、すべてのパケットが接続時間分だけ遅れて送信されます(例:接続時間300 ms ≈ 221 msの一定の遅延)。これにより、トランスクリプトとend-of-turnイベントが同じ分だけ遅延します。

修正(PR #7890):最初の送信時ではなく、ストリームの実行開始時にペーシングクロックを開始するようにしました。ソケットの準備ができ次第、バッファされたバックログは直ちにフラッシュされ、後続のパケットは従来どおり実時間に対してペーシングされます。

修正版リリースまでの回避策:_input_chにキューイングされたフレームがまだ残っている間はペーシングのスリープをスキップするよう、_send_audioをモンキーパッチします(バッファが空になってからのみスリープ)。影響が確認されたもの:livekit-agents==1.8.6、muse-voice-transcribe-1.0を使用したlivekit-plugins-meta==1.8.6。

参照 Issue #7876
トラブル対応
LiveKit Agentsは、最終トランスクリプトがアラビア文字、CJK、デーヴァナーガリー、またはウルドゥー文字の句読点を追加しただけの場合に、なぜプリエンプティブ生成を無効化するのですか?

影響を受けるバージョン: livekit-agents 1.8.3 および main @ 57b3227。_transcripts_equivalent() は split_words(..., ignore_punctuation=True) を呼び出しますが、livekit/agents/tokenize/_basic_word.py の句読点除去リストは ASCII のみです。そのため、アラビア語の ، ؛ ؟、ウルドゥー語の ۔、デーヴァナーガリーの ।、全角 CJK の ,。 が単語に付着したまま残り、最終的なトランスクリプトが異なって表示され、preemptive generation invalidated ... because the transcript ... changed がトリガーされます。

既存の ASCII 句読点に加えて、すべての Unicode 句読点カテゴリ(P*)を除去するようにトークナイザーを修正してください:

import unicodedata

def _is_punctuation(char: str) -> bool:
    return (
        char in tokenize.tokenizer.PUNCTUATIONS
        or unicodedata.category(char).startswith("P")
    )

ignore_punctuation=True が文字をフィルタリングするすべての箇所で、_basic_word.py 内にこのチェックを使用してください。これにより、カテゴリ S を持つ $ や + などの記号、およびカテゴリ Mn を持つアラビア語の発音区別符号が保持されます。

以下で検証してください:

from livekit.agents.voice.agent_activity import _transcripts_equivalent

assert _transcripts_equivalent("مرحبا كيف حالك", "مرحبا، كيف حالك؟")
assert _transcripts_equivalent("你好 我很好", "你好,我很好。")
assert _transcripts_equivalent("आप कैसे हैं", "आप कैसे हैं।")

パッチを適用したパッケージを再ビルドまたは再インストールしてください。上流の修正がリリースされたら、pip install -U livekit-agents でアップグレードしてください。

参照 Issue #7506