> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a LiveKit voice agent with Prism

> Build a voice agent in Python with LiveKit and Prism, and talk to it from your browser. The quickstart also shows how to run Prism through LiveKit Inference or on your own LiveKit server.

In this quickstart, you'll build a voice agent with LiveKit and Prism, and talk to it from your browser. The agent answers questions about a made-up cafe. When you ask about opening hours, it calls a function in your code to look them up.

A typical LiveKit voice agent chains three plugins: speech-to-text, an LLM, and text-to-speech. Prism replaces all three. It listens, knows when you've finished talking, and answers out loud. If you've used OpenAI Realtime with LiveKit, Prism takes the same place in your agent. LiveKit still carries the audio between your browser and your agent.

[Your Voice Agent Just Said the Wrong Thing. Here's How to Stop It](https://www.youtube-nocookie.com/embed/VIHyCbWiRQA)

LiveKit's video on Prism: Your voice agent just said the wrong thing. Here's how to stop it.

## What you'll need

* A Rime API key. If you don't have one, [sign up for Rime](https://app.rime.ai/signup/) to create one. With [LiveKit Inference](#use-livekit-inference), you can skip it.
* A [LiveKit Cloud](https://cloud.livekit.io/) project, with its URL, an API key, and the key's secret. [Your own LiveKit server](#use-your-own-livekit-server) works too.
* [uv](https://docs.astral.sh/uv/getting-started/installation/) 0.9.26 or later, which installs Python for the project if needed. The Rime SDK needs Python 3.11 or later.
* A browser with a microphone.

## Build the agent

**1. Create the project**

Create a Python project:

```bash theme={null}
uv init --python 3.12 prism-livekit-agent
cd prism-livekit-agent
```

Install LiveKit Agents and the Rime plugin with its `realtime` extra:

```bash theme={null}
uv add "livekit-agents[codecs]==1.8.11" \
  "livekit-plugins-rime[realtime]==1.8.11" \
  "python-dotenv>=1.1"
```

> [accordion] Use LiveKit Agents 1.7.1
>
> To keep Agents 1.7.1, install the Rime plugin from this pinned commit in LiveKit's official repository instead of the PyPI package.
>
> Add this setting to your project's `pyproject.toml` so uv keeps the published Agents core:
>
> ```toml pyproject.toml theme={null}
> [tool.uv]
> no-sources-package = ["livekit-agents"]
> ```
>
> Install the plugin with Agents 1.7.1:
>
> ```bash theme={null}
> uv add "livekit-agents[codecs]==1.7.1" \
>   "livekit-plugins-rime[realtime] @ git+https://github.com/livekit/agents.git@9d111561400279e49cb947b48763614542a7ebb1#subdirectory=livekit-plugins/livekit-plugins-rime" \
>   "python-dotenv>=1.1"
> ```

**2. Set your credentials**

Create `.env.local` in your project folder with your own values. Your LiveKit Cloud project's settings show its URL and let you create an API key and secret:

```dotenv .env.local theme={null}
LIVEKIT_URL=wss://YOUR_PROJECT.livekit.cloud
LIVEKIT_API_KEY=YOUR_LIVEKIT_API_KEY
LIVEKIT_API_SECRET=YOUR_LIVEKIT_API_SECRET
RIME_API_KEY=YOUR_RIME_API_KEY
```

**3. Save the agent**

Save this script as `agent.py` in your project folder. It registers an agent named `prism-agent`, which starts a Prism session in the `aurora` voice and greets the caller in each room it joins.

```python agent.py theme={null}
from dotenv import load_dotenv
from livekit import agents
from livekit.agents import Agent, AgentServer, AgentSession, function_tool, room_io
from livekit.plugins import rime

load_dotenv(".env.local")


class CafeAgent(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions=(
                "You answer the phone for Juniper Cafe. Answer in one or two short "
                "sentences. For questions about opening hours, use get_opening_hours."
            ),
        )

    @function_tool
    async def get_opening_hours(self) -> str:
        """Look up Juniper Cafe's opening hours for today."""
        return "Juniper Cafe is open from 8 a.m. to 4 p.m. today."


server = AgentServer()


@server.rtc_session(agent_name="prism-agent")
async def prism_agent(ctx: agents.JobContext) -> None:
    model = rime.realtime.RealtimeModel(voice="aurora")
    ctx.add_shutdown_callback(model.aclose)
    session = AgentSession(llm=model)
    await session.start(
        agent=CafeAgent(),
        room=ctx.room,
        room_options=room_io.RoomOptions(text_input=False),
    )
    await session.generate_reply(
        instructions="Greet the caller and ask how you can help."
    )


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

Three parts control the conversation:

* `rime.realtime.RealtimeModel`: connects the agent to Prism and selects its voice.
* `@function_tool`: lets Prism request the cafe's opening hours from your code.
* `generate_reply()`: asks Prism to greet the caller first.

**4. Start the agent**

Run it in development mode from your project folder:

```bash theme={null}
uv run agent.py dev
```

The agent connects to your LiveKit project and logs `registered worker` with `"agent_name": "prism-agent"`. Leave it running. You can ignore the warning that `dev` is deprecated, or use `lk agent dev` from the [LiveKit CLI](https://docs.livekit.io/reference/developer-tools/livekit-cli/#setup) instead.

**5. Talk to the agent**

1. In LiveKit Cloud, open your project's [Agent Console](https://cloud.livekit.io/projects/p_/agents/console).
2. Set the agent name to `prism-agent`.
3. Select **Start a session**.
4. When your browser asks, allow microphone access.

Prism greets you as soon as you join, so you know the session works. Now ask, "What time do you close today?"

The agent should answer that the cafe opens at 8 a.m. and closes at 4 p.m. Then interrupt its next reply to check interruption handling.

If the call doesn't work:

* **The agent never joins:** check that the console's agent name is `prism-agent` and the terminal shows `registered worker`.
* **The agent joins but stays silent:** look for a Rime plugin error in the terminal, and look up its code in [Errors and limits](https://docs.rime.ai/docs/prism/errors.md).

## How Prism changes a LiveKit agent

Prism handles the whole conversation. Keep these constraints in mind when adapting the example:

| Setting | What to use |
| - | - |
| Speech and turn detection | Pass Prism as `llm`. Do not add separate `stt`, `tts`, `vad`, or `turn_detection` settings. |
| Agent speech | Use `generate_reply()`. This agent has no separate TTS model for `session.say()`. |
| Tool calls | Define functions with `@function_tool`. Prism chooses when to call them. |
| Language and voice | Use English and a [Prism voice](https://docs.rime.ai/docs/prism/sessions.md#choose-a-voice). |

For settings, tool restrictions, retries, playback, and history, use the [LiveKit plugin reference](https://docs.rime.ai/api-reference/prism/livekit.md).

To choose your own transcription and language model, use the [LiveKit TTS quickstart](https://docs.rime.ai/docs/quickstart-livekit.md).

## Use LiveKit Inference

You can also reach Prism through [LiveKit Inference](https://docs.livekit.io/agents/models/inference/). It signs in with your LiveKit API key and secret instead of a Rime key, and LiveKit Cloud bills the usage. In the agent above, replace the line that creates the model:

```python theme={null}
from livekit.agents import inference

model = inference.RealtimeModel(model="rime/prism", voice="aurora")
```

Keep the rest of the agent as it is, and leave `RIME_API_KEY` out of `.env.local`. LiveKit's [Rime Prism page](https://docs.livekit.io/agents/models/realtime/rime/) lists the Inference options.

## Use your own LiveKit server

On your own server, which has no Agent Console, send the agent to a room with the LiveKit CLI:

1. In `.env.local`, set `LIVEKIT_URL`, `LIVEKIT_API_KEY`, and `LIVEKIT_API_SECRET` to your server's values, and start the agent the same way.

2. Send the agent to a room. Pass your server details with `--url`, `--api-key`, and `--api-secret`, or set the same three variables in your shell.

   ```bash theme={null}
   lk dispatch create --room prism-test --agent-name prism-agent
   ```

3. Join the `prism-test` room from any LiveKit client with a microphone, such as an app built with [LiveKit's frontend SDKs](https://docs.livekit.io/frontends/).

## Next steps

Now that your agent answers, you can:

* [Take phone calls](https://docs.livekit.io/telephony/) with LiveKit telephony.
* [Write instructions that Prism follows](https://docs.rime.ai/docs/prism/prompting.md), starting with rules for speech.
* [Choose a voice](https://docs.rime.ai/docs/prism/sessions.md#choose-a-voice) that suits your callers.
* [Configure the LiveKit plugin](https://docs.rime.ai/api-reference/prism/livekit.md) for settings, tools, retries, playback, and history.
* [Move an OpenAI Realtime agent](https://docs.rime.ai/docs/prism/migrate-from-openai.md#move-a-livekit-agent) on LiveKit to Prism.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.