Skip to content

Commit 42454b8

Browse files
authored
Merge pull request #3 from livekit-examples/bcherry/updates
Update template
2 parents 97cf1d7 + 7905715 commit 42454b8

File tree

5 files changed

+1930
-1647
lines changed

5 files changed

+1930
-1647
lines changed

README.md

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Voice Agent Hackathon Template
22

3-
Welcome to the Voice Agent Hackathon! This template contains a ready-to-use voice agent built with [AssemblyAI](https://assemblyai.com) and [Rime](https://rime.ai). All you need to run it is a [LiveKit Cloud](https://cloud.livekit.io) project.
3+
Welcome to the Voice Agent Hackathon! This template contains a ready-to-use voice agent built [LiveKit Agents](https://github.com/livekit/agents). All you need is a [LiveKit Cloud](https://cloud.livekit.io) project.
44

55
This starter app is compatible with any [custom web/mobile frontend](https://docs.livekit.io/agents/start/frontend/) or [SIP-based telephony](https://docs.livekit.io/agents/start/telephony/).
66

@@ -46,9 +46,9 @@ Finally, open the [LiveKit Agents Playground](https://agents-playground.livekit.
4646

4747
## Tips for managing background noise
4848

49-
This hackathon may be a noisy place which can make it tricky to test your agent. Here are some tips to help you:
49+
If you're in a noisy hackathon environment, it may be tricky to test your agent. Here are some tips to help you:
5050

51-
1. Use headphones with a microphone and noise isolation features (such as Airpods)
51+
1. Use headphones with a microphone and noise isolation features (such as AirPods Pro)
5252
2. Use the LiveKit [background voice cancellation](https://docs.livekit.io/home/cloud/noise-cancellation/) model (pre-installed in this template)
5353
3. Turn off your microphone in the [Agents Playground](https://agents-playground.livekit.io/#cam=0&mic=1&screen=0&video=0&audio=1&chat=1&theme_color=cyan) and use text input to test your agent instead.
5454

@@ -84,79 +84,8 @@ This project is production-ready and includes a working `Dockerfile`. To deploy
8484

8585
## Models
8686

87-
This project uses models from AssemblyAI and Rime, as well as GPT-4o-mini from Azure OpenAI. By default, these are served through early-access to LiveKit Inference and no extra account is required.
87+
This project uses LiveKit Inference with models from AssemblyAI, OpenAI, and Cartesia. No extra account is required to use these models, which have been selected for their quality and performance.
8888

89-
### AssemblyAI customization
89+
Many more models are available, both through LiveKit Inference and through SDK plugins for a wide variety of third-party APIs. See the [LiveKit Agents documentation](https://docs.livekit.io/agents/models/) for a full list.
9090

91-
To customize the AssemblyAI model, while still using LiveKit Cloud, you can use the following session setup in your [agent code](https://github.com/livekit-examples/voice-agent-hackathon/blob/main/src/agent.py) instead of the version above:
92-
93-
```python
94-
from livekit.agents import inference
95-
96-
session = AgentSession(
97-
stt=inference.STT(model="assemblyai", extra_kwargs={ ... })
98-
)
99-
```
100-
101-
Refer to the [source code](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/inference/stt.py#L57) for available parameters (docs for LiveKit Inference are coming soon)
102-
103-
#### AssemblyAI plugin
104-
105-
To use your own AssemblyAI account, or access additional AssemblyAI features, use the AssemblyAI plugin:
106-
107-
```shell
108-
uv add livekit-agents[assemblyai]
109-
```
110-
111-
```python
112-
from livekit.plugins import assemblyai
113-
114-
session = AgentSession(
115-
stt=assemblyai.STT()
116-
)
117-
```
118-
119-
Refer to the [plugin documentation](https://docs.livekit.io/agents/integrations/stt/assemblyai/) for more information.
120-
121-
### Rime customization
122-
123-
To use a different Rime voice, while still using LiveKit Cloud, just change the voice name after the colon in your [agent code](https://github.com/livekit-examples/voice-agent-hackathon/blob/main/src/agent.py):
124-
125-
```python
126-
session = AgentSession(
127-
tts="rime/arcana:andromeda"
128-
)
129-
```
130-
131-
Refer to the [Rime voices list](https://docs.rime.ai/api-reference/voices) for more information.
132-
133-
#### Rime plugin
134-
135-
To use your own Rime account, or access additional features, use the Rime plugin:
136-
137-
```shell
138-
uv add livekit-agents[rime]
139-
```
140-
141-
```python
142-
from livekit.plugins import rime
143-
144-
session = AgentSession(
145-
tts=rime.TTS(model="arcana", speaker="andromeda")
146-
)
147-
```
148-
149-
Refer to the [plugin documentation](https://docs.livekit.io/agents/integrations/tts/rime/) for more information.
150-
151-
152-
## Other large language models
153-
154-
Refer to the [source code](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/inference/llm.py) for available models (LiveKit Inference docs are coming soon).
155-
156-
```python
157-
session = AgentSession(
158-
llm="azure/gpt-4o-mini"
159-
)
160-
```
161-
162-
Or, use an [LLM plugin](https://docs.livekit.io/agents/integrations/llm/) for a wider range of models and more configuration options.
91+
Happy hacking!

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "voice-agent-hackathon"
77
version = "1.0.0"
8-
description = "Simple voice agent built with LiveKit, AssemblyAI, and Rime"
8+
description = "Simple voice agent built with LiveKit Agents"
99
requires-python = ">=3.9"
1010

1111
dependencies = [
12-
"livekit-agents[turn-detector,silero]~=1.2.11",
12+
"livekit-agents[turn-detector,silero]~=1.2",
1313
"livekit-plugins-noise-cancellation~=0.2",
1414
"python-dotenv",
1515
]

src/agent.py

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
from dotenv import load_dotenv
44
from livekit.agents import (
5-
NOT_GIVEN,
65
Agent,
7-
AgentFalseInterruptionEvent,
86
AgentSession,
97
JobContext,
108
JobProcess,
11-
MetricsCollectedEvent,
129
RoomInputOptions,
1310
WorkerOptions,
1411
cli,
15-
metrics,
1612
)
1713
from livekit.plugins import noise_cancellation, silero
1814
from livekit.plugins.turn_detector.multilingual import MultilingualModel
@@ -54,72 +50,18 @@ def prewarm(proc: JobProcess):
5450

5551

5652
async def entrypoint(ctx: JobContext):
57-
# Logging setup
58-
# Add any other context you want in all log entries here
59-
ctx.log_context_fields = {
60-
"room": ctx.room.name,
61-
}
62-
6353
# Set up a voice AI pipeline using OpenAI, Rime, AssemblyAI, and the LiveKit turn detector
54+
# For a list of all available models, as well as configuration options see
55+
# https://docs.livekit.io/agents/models/
6456
session = AgentSession(
65-
# This starter template uses GPT-4o-mini via LiveKit Cloud.
66-
# For a list of available models, see https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/inference/llm.py
67-
# Or, for a wider range of models, see plugins at https://docs.livekit.io/agents/integrations/llm/
68-
llm="azure/gpt-4o-mini",
69-
# This starter template uses AssemblyAI via LiveKit Cloud.
70-
# To send extra parameters, use the following session setup instead of the version above:
71-
# 1. add `from livekit.agents import inference` to the top of this file
72-
# 2. Use the following session setup instead of the version above:
73-
# stt=inference.STT(model="assemblyai", extra_kwargs={ ... })
74-
# See available configuration at https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/inference/stt.py#L57
75-
#
76-
# Or to use your own AssemblyAI account:
77-
# 1. Install livekit-agents[assemblyai]
78-
# 2. Set ASSEMBLYAI_API_KEY in .env.local
79-
# 3. Add `from livekit.plugins import assemblyai` to the top of this file
80-
# 4. Use the following session setup instead of the version above
81-
# stt=assemblyai.STT()
82-
# See available configuration at https://docs.livekit.io/agents/integrations/stt/assemblyai/
83-
stt="assemblyai",
84-
# This starter template uses Rime via LiveKit Cloud
85-
# To change the voice, alter the voice name (currently "luna") after the colon.
86-
# See available voices at https://docs.rime.ai/api-reference/voices
87-
#
88-
# Or, to use your own Rime account:
89-
# 1. Install livekit-agents[rime]
90-
# 2. Set RIME_API_KEY in .env.local
91-
# 3. Add `from livekit.plugins import rime` to the top of this file
92-
# 4. Use the following session setup instead of the version above
93-
# tts=rime.TTS(model="arcana", speaker="luna")
94-
# See available configuration at https://docs.livekit.io/agents/integrations/tts/rime/
95-
tts="rime/arcana:luna",
57+
stt="assemblyai/universal-streaming:en",
58+
llm="openai/gpt-4.1-mini",
59+
tts="cartesia/sonic-2:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc",
9660
turn_detection=MultilingualModel(),
9761
vad=ctx.proc.userdata["vad"],
9862
preemptive_generation=True,
9963
)
10064

101-
# sometimes background noise could interrupt the agent session, these are considered false positive interruptions
102-
# when it's detected, you may resume the agent's speech
103-
@session.on("agent_false_interruption")
104-
def _on_agent_false_interruption(ev: AgentFalseInterruptionEvent):
105-
logger.info("false positive interruption, resuming")
106-
session.generate_reply(instructions=ev.extra_instructions or NOT_GIVEN)
107-
108-
# Metrics collection, to measure pipeline performance
109-
# For more information, see https://docs.livekit.io/agents/build/metrics/
110-
usage_collector = metrics.UsageCollector()
111-
112-
@session.on("metrics_collected")
113-
def _on_metrics_collected(ev: MetricsCollectedEvent):
114-
metrics.log_metrics(ev.metrics)
115-
usage_collector.collect(ev.metrics)
116-
117-
async def log_usage():
118-
summary = usage_collector.get_summary()
119-
logger.info(f"Usage: {summary}")
120-
121-
ctx.add_shutdown_callback(log_usage)
122-
12365
# Start the session, which initializes the voice pipeline and warms up the models
12466
await session.start(
12567
agent=Assistant(),
@@ -137,7 +79,7 @@ async def log_usage():
13779
await session.generate_reply(
13880
instructions="""
13981
The user has just finished getting their first voice agent up and running.
140-
Welcome them to the Voice Agent Hackathon and wish them good luck!
82+
Wish them good luck with their hackathon project!
14183
""",
14284
allow_interruptions=False,
14385
)

tests/test_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def _llm() -> llm.LLM:
8-
return inference.LLM(model="azure/gpt-4o-mini")
8+
return inference.LLM(model="openai/gpt-4.1-mini")
99

1010

1111
@pytest.mark.asyncio

0 commit comments

Comments
 (0)