你想做一个能打电话的 AI 语音助手——用户拨进来,AI 接听,理解意图,查询天气、订餐、转人工。你调研了一圈方案:Twilio + OpenAI + ElevenLabs,三个服务各自收费,还要自己写 WebSocket 串起来。你花了两周把 STT、LLM、TTS 打通,结果发现语音延迟 2 秒,用户说完话 AI 隔了半秒才接上,体验比真人差远了。有没有一个框架,把语音识别、大模型推理、语音合成、电话集成、多 Agent 协作全部封装好,你只写业务逻辑就行?
文末获取 LiveKit Agents 项目地址和安装命令
LiveKit Agents 就是干这个的。它是 LiveKit 推出的 Python 实时语音 AI Agent 框架,专为构建能听、能说、能理解的实时多模态语音 Agent 设计。核心 API 极其简洁:Agent、AgentSession、AgentServer 三个类,用 @function_tool 装饰器加工具,pip install 一行安装,python myagent.py console 本地测试,python myagent.py dev 热重载开发,python myagent.py start 生产部署。
12.8K Star,3.5K Fork,100+ 贡献者,Apache 2.0 开源。Python + Node.js(AgentsJS)双版本。
LiveKit Agents 用一套框架封装了语音 Agent 的完整技术栈——STT、LLM、TTS、电话、WebRTC、多 Agent、测试。
-
- STT + LLM + TTS 一站式封装:
stt=inference.STT("deepgram/nova-3")、llm=inference.LLM("google/gemma-4-31b-it")、tts=inference.TTS("cartesia/sonic-3") — 原来要分别对接三个 API,现在统一接口,一行一个 -
- 电话打通:LiveKit SIP 原生集成,Agent 可以接电话、打电话 — 原来要买 Twilio + 配 WebSocket,现在
python myagent.py start 然后配个 SIP trunk -
- 语义回合检测:内置 Transformer 模型自动判断用户是否说完 — 原来用静音检测误判率高,现在语义级理解,减少打断
-
- 多 Agent 手递手交接:Agent A 收集完信息,
return story_agent, "Let's start!" 直接转给 Agent B — 原来要手动管理会话状态,现在一个 return 搞定 -
- MCP 一行代码接入:任何 MCP 服务器的工具直接变成 Agent 的 function tool — 浏览器自动化、数据库查询、API 调用全接入
-
- 内置测试框架:
result.expect.next_event().is_function_call(name="start_order") — 原来 LLM 的非确定性让测试无法写,现在有断言式测试 -
技术架构
LiveKit Agents 的核心架构:
Code
AgentServer → 调度 & 分发
功能模块
| 模块 |
能做什么 |
| 语音 Agent |
STT→LLM→TTS 全链路 — 原来要对接三个服务,现在一个框架管完 |
| 电话集成 |
Agent 接电话、打电话 — 原来要买 Twilio,现在 SIP 原生支持 |
| 多 Agent 交接 |
IntroAgent → StoryAgent 自动切换 — 原来要手写会话管理,现在自动路由 |
| MCP 工具 |
任何 MCP 服务器工具直接可用 — 原来要手写集成代码,现在一行接入 |
| 语义回合检测 |
Transformer 模型判断用户说完 — 原来靠静音,误判率高,现在语义级精准 |
| 测试框架 |
断言式 LLM 测试 — 原来非确定性无法测试,现在有 judge 自动评估 |
| 多用户支持 |
多人房间 Push-to-Talk — 原来只能一对一,现在多人同房 |
| 视频头像 |
集成 Tavus/Bithuman 等 — 原来只能语音,现在有 AI 视频形象 |
| Gemini Live Vision |
AI 能看到你的画面 — 原来只能听,现在能看 |
快速开始
安装:
Code
pip install span style="color:#98c379 !important text-indent: 0 !important;">"livekit-agents[openai,deepgram,cartesia]"
10 行代码构建语音 Agent:
Python
from</span livekit.agents span style="color:#c678dd !important text-indent: 0 !important;">import</span Agent, AgentSession, AgentServer, JobContext, function_tool
@function_tool
asyncdeflookup_weather(context, location: str):
return</span {"weather": span style="color:#98c379 !important text-indent: 0 !important;">"sunny", span style="color:#98c379 !important text-indent: 0 !important;">"temperature": span style="color:#d19a66 !important text-indent: 0 !important;">70}
server = span style="color:#61afef !important text-indent: 0 !important;">AgentServer()
@server.rtc_session()
asyncdefentrypoint(ctx: JobContext):
AgentSession(
STT("deepgram/nova-3"),
LLM("google/gemma-4-31b-it"),
TTS("cartesia/sonic-3"),
Agent(
"You are a friendly voice assistant.",
await</span session.start(agent=agent, room=ctx.room)
if</span __name__ == span style="color:#98c379 !important text-indent: 0 !important;">"__main__":
run_app(server)
本地测试:
Code
python myagent.py console span style="color:#5c6370 !important; font-style:italic !important text-indent: 0 !important;"># 终端模式,本地音频测试
python myagent.py dev span style="color:#5c6370 !important; font-style:italic !important text-indent: 0 !important;"># 热重载开发模式
python myagent.py start span style="color:#5c6370 !important; font-style:italic !important text-indent: 0 !important;"># 生产模式
总结
LiveKit Agents 以"STT+LLM+TTS+电话+多 Agent 一站式封装"为核心,把构建实时语音 AI 助手的门槛从"两周对接三个服务"降到了"10 行 Python 代码"。对个人开发者来说,本地终端就能跑起来测试;对团队来说,SIP 电话集成 + 多 Agent 交接 + 测试框架让生产级语音 Agent 变得可行。
一句话记住这个项目:LiveKit Agents 让你用 10 行 Python 代码 替代 两周对接 STT+LLM+TTS+电话,语音识别、大模型推理、语音合成、电话、多 Agent 交接全部封装,pip install 就能跑。
GitHub 地址:https://github.com/livekit/agents
文档:https://docs.livekit.io/agents
安装:pip install "livekit-agents[openai,deepgram,cartesia]"
AgentsJS(Node.js 版):https://github.com/livekit/agents-js
如果觉得有用,欢迎 Star 支持开发者!
点个关注,精彩不迷路
免责声明: 本公众号所发布的内容来源于互联网,我们会尊重并维护原作者的权益。由于信息来源众多,若文章内容出现版权问题,或文中使用的图片、资料、下载链接等,如涉及侵权,请告知我们,我们将尽快处理。