agents README

The project's README from github.com/livekit/agents. As one markdown file: README.md.

The LiveKit icon, the name of the repository and some sample code in the background.

PyPI - Version PyPI Downloads Slack community Twitter Follow Ask DeepWiki for understanding the codebase License


Looking for the JS/TS library? Check out AgentsJS

What is Agents?

The Agent Framework is designed for building realtime, programmable participants that run on servers. Use it to create conversational, multi-modal voice agents that can see, hear, and understand.

Features

Installation

To install the core Agents library, along with plugins for popular model providers:

pip install "livekit-agents[openai,deepgram,cartesia]"

Docs and guides

Documentation on the framework and how to use it can be found here

Building with AI coding agents

If you're using an AI coding assistant to build with LiveKit Agents, we recommend the following setup for the best results:

  1. Install the LiveKit Docs MCP server — Gives your coding agent access to up-to-date LiveKit documentation, code search across LiveKit repositories, and working examples.

  2. Install the LiveKit Agent Skill — Provides your coding agent with architectural guidance and best practices for building voice AI applications, including workflow design, handoffs, tasks, and testing patterns.

    npx skills add livekit/agent-skills --skill livekit-agents
    

The Agent Skill works best alongside the MCP server: the skill teaches your agent how to approach building with LiveKit, while the MCP server provides the current API details to implement it correctly.

Core concepts

Usage

Simple voice agent


from livekit.agents import (
    Agent,
    AgentServer,
    AgentSession,
    JobContext,
    RunContext,
    cli,
    function_tool,
    inference,
)


@function_tool
async def lookup_weather(
    context: RunContext,
    location: str,
):
    """Used to look up weather information."""

    return {"weather": "sunny", "temperature": 70}


server = AgentServer()


@server.rtc_session()
async def entrypoint(ctx: JobContext):
    session = AgentSession(
        vad=inference.VAD(),
        # any combination of STT, LLM, TTS, or realtime API can be used
        # this example shows LiveKit Inference, a unified API to access different models via LiveKit Cloud
        # to use model provider keys directly, replace with the following:
        # from livekit.plugins import deepgram, openai, cartesia
        # stt=deepgram.STT(model="nova-3"),
        # llm=openai.LLM(model="gpt-4.1-mini"),
        # tts=cartesia.TTS(model="sonic-3", voice="9626c31c-bec5-4cca-baa8-f8ba9e84c8bc"),
        stt=inference.STT("deepgram/nova-3", language="multi"),
        llm=inference.LLM("google/gemma-4-31b-it"),  # low-latency gemma, hosted on LiveKit
        tts=inference.TTS("cartesia/sonic-3", voice="9626c31c-bec5-4cca-baa8-f8ba9e84c8bc"),
    )

    agent = Agent(
        instructions="You are a friendly voice assistant built by LiveKit.",
        tools=[lookup_weather],
    )

    await session.start(agent=agent, room=ctx.room)
    await session.generate_reply(instructions="greet the user and ask about their day")


if __name__ == "__main__":
    cli.run_app(server)

You'll need the following environment variables for this example:

Multi-agent handoff


This code snippet is abbreviated. For the full example, see the LiveKit docs

...
class IntroAgent(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions=f"You are a story teller. Your goal is to gather a few pieces of information from the user to make the story personalized and engaging."
            "Ask the user for their name and where they are from"
        )

    async def on_enter(self):
        self.session.generate_reply(instructions="greet the user and gather information")

    @function_tool
    async def information_gathered(
        self,
        context: RunContext,
        name: str,
        location: str,
    ):
        """Called when the user has provided the information needed to make the story personalized and engaging.

        Args:
            name: The name of the user
            location: The location of the user
        """

        context.userdata.name = name
        context.userdata.location = location

        story_agent = StoryAgent(name, location)
        return story_agent, "Let's start the story!"


class StoryAgent(Agent):
    def __init__(self, name: str, location: str) -> None:
        super().__init__(
            instructions=f"You are a storyteller. Use the user's information in order to make the story personalized."
            f"The user's name is {name}, from {location}",
            # override the default model, switching to Realtime API from standard LLMs
            llm=openai.realtime.RealtimeModel(voice="echo"),
            chat_ctx=chat_ctx,
        )

    async def on_enter(self):
        self.session.generate_reply()


@server.rtc_session()
async def entrypoint(ctx: JobContext):
    userdata = StoryData()
    session = AgentSession[StoryData](
        vad=inference.VAD(),
        stt="deepgram/nova-3",
        llm="google/gemma-4-31b-it",  # low-latency gemma, hosted on LiveKit
        tts="cartesia/sonic-3:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc",
        userdata=userdata,
    )

    await session.start(
        agent=IntroAgent(),
        room=ctx.room,
    )
...

Testing

Automated tests are essential for building reliable agents, especially with the non-deterministic behavior of LLMs. LiveKit Agents include native test integration to help you create dependable agents.

@pytest.mark.asyncio
async def test_no_availability() -> None:
    llm = google.LLM()
    async with AgentSession(llm=llm) as sess:
        await sess.start(MyAgent())
        result = await sess.run(
            user_input="Hello, I need to place an order."
        )
        result.expect.skip_next_event_if(type="message", role="assistant")
        result.expect.next_event().is_function_call(name="start_order")
        result.expect.next_event().is_function_call_output()
        await (
            result.expect.next_event()
            .is_message(role="assistant")
            .judge(llm, intent="assistant should be asking the user what they would like")
        )

Examples

For more examples and detailed setup instructions, see the examples directory. For even more examples, see the python-agents-examples repository.

🎙️ Starter Agent

A starter agent optimized for voice conversations.

Code

☎️ Outbound caller

Agent that makes outbound phone calls

Code

🔌 MCP support

Use tools from MCP servers

Code

📝 Multi-user transcriber

Produce transcriptions from all users in the room

Code

🎥 Video avatars

Add an AI avatar with Tavus, Bithuman, LemonSlice, and more

Code

👁️ Gemini Live vision

Full example (including iOS app) of Gemini Live agent that can see.

Code

Running your agent

Testing in terminal

python myagent.py console

Runs your agent in terminal mode, enabling local audio input and output for testing. This mode doesn't require external servers or dependencies and is useful for quickly validating behavior.

Developing with LiveKit clients

python myagent.py dev

Starts the agent server and enables hot reloading when files change. This mode allows each process to host multiple concurrent agents efficiently.

The agent connects to LiveKit Cloud or your self-hosted server. Set the following environment variables:

You can connect using any LiveKit client SDK or telephony integration. To get started quickly, try the Agents Playground.

Running for production

python myagent.py start

Runs the agent with production-ready optimizations.

License

The Agents framework is licensed under Apache-2.0. The LiveKit turn detection models are licensed under the LiveKit Model License.

Contributing

The Agents framework is under active development in a rapidly evolving field. We welcome and appreciate contributions of any kind, be it feedback, bugfixes, features, new plugins and tools, or better documentation. You can file issues under this repo, open a PR, or chat with us in the LiveKit community.

Development setup

This project uses uv for package management. To install dependencies for development:

uv sync --all-extras --dev

Examples

This project includes many examples in the examples directory. To run them, create the file examples/.env with credentials for LiveKit Server and any necessary model providers (see examples/.env.example), then run:

uv run examples/voice_agents/basic_agent.py dev

For more information, see the examples README.

Tests

Unit tests are in the tests directory and can be run with:

uv run pytest --unit

Integration tests for each plugin require various API credentials and run automatically in GitHub CI for PRs submitted by project maintainers. See the tests workflow for details.

Formatting

This project uses ruff for formatting and linting:

uv run ruff format
uv run ruff check --fix

Documentation

To generate docs locally with pdoc:

uv sync --all-extras --group docs
uv run --active pdoc --skip-errors --html --output-dir=docs livekit


LiveKit Ecosystem
Agents SDKsPython · Node.js
LiveKit SDKsBrowser · Swift · Android · Flutter · React Native · Rust · Node.js · Python · Unity · Unity (WebGL) · ESP32 · C++
Starter AppsPython Agent · TypeScript Agent · React App · SwiftUI App · Android App · Flutter App · React Native App · Web Embed
UI ComponentsReact · Android Compose · SwiftUI · Flutter
Server APIsNode.js · Golang · Ruby · Java/Kotlin · Python · Rust · PHP (community) · .NET (community)
ResourcesDocs · Docs MCP Server · CLI · LiveKit Cloud
LiveKit Server OSSLiveKit server · Egress · Ingress · SIP
CommunityDeveloper Community · Slack · X · YouTube

agents (livekit/agents)

Searching Database…

14.8K ·GitHub
这是什么?LiveKit 的开源 Python 框架,用于构建实时语音 AI 智能体:这些是可编程的参与者,运行在服务器上,能够看见、听见、理解内容,并通过 WebRTC 与用户对话。
它是我调用的托管 API,还是我自己运行的代码?是一个代码框架,不是托管服务:你用 Python 编写智能体逻辑,自己运行智能体进程——既可以完全自托管整套技术栈(包括 LiveKit 的 WebRTC 服务器),也可以连接到 LiveKit Cloud。
我怎么才能让第一个智能体跑起来?先安装 Agents 核心库,再安装你所用的模型服务商对应的插件,设置 LIVEKIT_URL、LIVEKIT_API_KEY 和 LIVEKIT_API_SECRET 这几个环境变量,然后以终端模式启动,就能通过本地的麦克风和扬声器与你的智能体对话了。
只是想试用一下,也需要 LiveKit 服务器或付费的 API 密钥吗?终端模式测试完全不需要任何外部服务器或依赖。但要有真实会话(客户端接入或电话通话),就需要一个 LiveKit 部署——LiveKit Cloud 或你自托管的服务器——以及你所选模型服务商的凭据。
它会不会把我绑定在 LiveKit 的付费云服务上?不会——框架和 LiveKit 服务器都是完全开源的,你可以在自己的机器上运行整套技术栈;LiveKit Cloud 只是上手更快的一种方式。
所有东西都是宽松许可吗,包括模型在内?Agents 框架采用 Apache-2.0 许可,但内置的轮次检测模型是按单独的 LiveKit Model License 发布的——如果你想把模型用于商业再分发,最好先确认一下这个许可。
我可以接入哪些语音和大模型服务商?它自带一个插件生态,涵盖 STT、LLM、TTS 和 Realtime API 的各种集成,可以按使用场景自由组合——示例中就有 OpenAI 和 Google 的 Gemini Live 等。
我的智能体能拨打和接听真实电话吗?可以——它与 LiveKit 的电话技术栈集成,同一个智能体既能外呼电话,也能接听普通手机打来的电话。
它怎么避免智能体在别人话说一半时插嘴?框架内置了一个基于 transformer 的语义轮次检测模型,用来判断用户是否真的说完了,从而减少过早打断的情况。
我能为语音智能体写自动化测试吗?可以——框架原生支持测试集成:你可以编写测试,并借助裁判(judge)机制,让智能体在 LLM 输出不确定的情况下依然保持可靠。
Creator
livekit
Size
45.5 MB
Stars
14.8K
Age
2y
Commits · 90 Days