Compare commits
10
Commits
d40d7975d7
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fd693a998 | ||
|
|
ddc18eb851 | ||
|
|
7c0af539fe | ||
|
|
7d194813a3 | ||
|
|
07a75c4369 | ||
|
|
9bf4404101 | ||
|
|
a7575e8af0 | ||
|
|
d48dfda85d | ||
|
|
7c53a9b613 | ||
|
|
f31b78f6d6 |
@@ -9,10 +9,14 @@ A complete starter project for building voice AI apps with [LiveKit Agents for P
|
|||||||
The starter project includes:
|
The starter project includes:
|
||||||
|
|
||||||
- A simple voice AI assistant, ready for extension and customization
|
- A simple voice AI assistant, ready for extension and customization
|
||||||
- A voice AI pipeline built on [LiveKit Inference](https://docs.livekit.io/agents/models/inference)
|
- A voice AI pipeline built on [LiveKit Inference](https://docs.livekit.io/agents/models/inference), providing zero-configuration access to [models](https://docs.livekit.io/agents/models) from top labs
|
||||||
with [models](https://docs.livekit.io/agents/models) from OpenAI, Cartesia, and Deepgram. More than 50 other model providers are supported, including [Realtime models](https://docs.livekit.io/agents/models/realtime)
|
- Uses the fast, open-weight Gemma 4 31B model, [hosted by LiveKit](https://docs.livekit.io/agents/models/llm/livekit/) and tuned for optimal performance in voice AI, as the default LLM
|
||||||
|
- Uses Fish Audio S2.1 Pro for TTS, which renders the inline delivery markup that expressive mode relies on
|
||||||
|
- Supports more than 50 models from OpenAI, Cartesia, Deepgram, and other providers
|
||||||
|
- Access to a wide range of other models, including [Realtime models](https://docs.livekit.io/agents/models/realtime), through extensive plugin ecosystem
|
||||||
|
- Expressive mode, enabled by default: the framework injects the TTS provider's markup guide into the LLM prompt, so the model emits inline delivery tags (emotion, pacing, non-verbal sounds) that the TTS renders and the transcript never shows
|
||||||
- Eval suite based on the LiveKit Agents [testing & evaluation framework](https://docs.livekit.io/agents/start/testing/)
|
- Eval suite based on the LiveKit Agents [testing & evaluation framework](https://docs.livekit.io/agents/start/testing/)
|
||||||
- [LiveKit Turn Detector](https://docs.livekit.io/agents/logic/turns/turn-detector/) for contextually-aware speaker detection, with multilingual support
|
- [LiveKit Turn Detector](https://docs.livekit.io/agents/logic/turns/turn-detector/), an end-of-turn model that listens to the user's audio directly, combining semantic understanding with acoustic cues for state-of-the-art accuracy across 14 languages
|
||||||
- [Background voice cancellation](https://docs.livekit.io/transport/media/noise-cancellation/)
|
- [Background voice cancellation](https://docs.livekit.io/transport/media/noise-cancellation/)
|
||||||
- Deep session insights from LiveKit [Agent Observability](https://docs.livekit.io/deploy/observability/)
|
- Deep session insights from LiveKit [Agent Observability](https://docs.livekit.io/deploy/observability/)
|
||||||
- A Dockerfile ready for [production deployment to LiveKit Cloud](https://docs.livekit.io/deploy/agents/)
|
- A Dockerfile ready for [production deployment to LiveKit Cloud](https://docs.livekit.io/deploy/agents/)
|
||||||
@@ -85,20 +89,14 @@ You can load the LiveKit environment automatically using the [LiveKit CLI](https
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
lk cloud auth
|
lk cloud auth
|
||||||
lk app env -w -d .env.local
|
lk app env --write --destination .env.local
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
## Run the agent
|
## Run the agent
|
||||||
|
|
||||||
Before your first run, you must download certain models such as [Silero VAD](https://docs.livekit.io/agents/logic/turns/vad/) and the [LiveKit turn detector](https://docs.livekit.io/agents/logic/turns/turn-detector/):
|
Run this command to speak to your agent directly in your terminal:
|
||||||
|
|
||||||
```console
|
|
||||||
uv run python src/agent.py download-files
|
|
||||||
```
|
|
||||||
|
|
||||||
Next, run this command to speak to your agent directly in your terminal:
|
|
||||||
|
|
||||||
```console
|
```console
|
||||||
uv run python src/agent.py console
|
uv run python src/agent.py console
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ description = "Simple voice AI assistant built with LiveKit Agents for Python"
|
|||||||
requires-python = ">=3.10, <3.15"
|
requires-python = ">=3.10, <3.15"
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"livekit-agents[silero,turn-detector]==1.5.16",
|
"livekit-agents>=1.6.9",
|
||||||
"livekit-plugins-ai-coustics~=0.2",
|
"livekit-plugins-ai-coustics~=0.2",
|
||||||
"python-dotenv",
|
"python-dotenv",
|
||||||
]
|
]
|
||||||
|
|||||||
+25
-21
@@ -7,13 +7,12 @@ from livekit.agents import (
|
|||||||
AgentServer,
|
AgentServer,
|
||||||
AgentSession,
|
AgentSession,
|
||||||
JobContext,
|
JobContext,
|
||||||
JobProcess,
|
TurnHandlingOptions,
|
||||||
cli,
|
cli,
|
||||||
inference,
|
inference,
|
||||||
room_io,
|
room_io,
|
||||||
)
|
)
|
||||||
from livekit.plugins import ai_coustics, silero
|
from livekit.plugins import ai_coustics
|
||||||
from livekit.plugins.turn_detector.multilingual import MultilingualModel
|
|
||||||
|
|
||||||
logger = logging.getLogger("agent")
|
logger = logging.getLogger("agent")
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ class Assistant(Agent):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
# A Large Language Model (LLM) is your agent's brain, processing user input and generating a response
|
# A Large Language Model (LLM) is your agent's brain, processing user input and generating a response
|
||||||
# See all available models at https://docs.livekit.io/agents/models/llm/
|
# See all available models at https://docs.livekit.io/agents/models/llm/
|
||||||
llm=inference.LLM(model="openai/gpt-5.2-chat-latest"),
|
llm=inference.LLM(model="google/gemma-4-31b-it"),
|
||||||
# To use a realtime model instead of a voice pipeline, replace the LLM
|
# To use a realtime model instead of a voice pipeline, replace the LLM
|
||||||
# with a RealtimeModel and remove the STT/TTS from the AgentSession
|
# with a RealtimeModel and remove the STT/TTS from the AgentSession
|
||||||
# (Note: This is for the OpenAI Realtime API. For other providers, see https://docs.livekit.io/agents/models/realtime/)
|
# (Note: This is for the OpenAI Realtime API. For other providers, see https://docs.livekit.io/agents/models/realtime/)
|
||||||
@@ -92,13 +91,6 @@ class Assistant(Agent):
|
|||||||
server = AgentServer()
|
server = AgentServer()
|
||||||
|
|
||||||
|
|
||||||
def prewarm(proc: JobProcess):
|
|
||||||
proc.userdata["vad"] = silero.VAD.load()
|
|
||||||
|
|
||||||
|
|
||||||
server.setup_fnc = prewarm
|
|
||||||
|
|
||||||
|
|
||||||
@server.rtc_session(agent_name="my-agent")
|
@server.rtc_session(agent_name="my-agent")
|
||||||
async def my_agent(ctx: JobContext):
|
async def my_agent(ctx: JobContext):
|
||||||
# Logging setup
|
# Logging setup
|
||||||
@@ -107,23 +99,35 @@ async def my_agent(ctx: JobContext):
|
|||||||
"room": ctx.room.name,
|
"room": ctx.room.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set up a voice AI pipeline using OpenAI, Cartesia, Deepgram, and the LiveKit turn detector
|
# Set up a voice AI pipeline using AssemblyAI, Fish Audio, and the LiveKit turn detector
|
||||||
session = AgentSession(
|
session = AgentSession(
|
||||||
# Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand
|
# Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand
|
||||||
# See all available models at https://docs.livekit.io/agents/models/stt/
|
# See all available models at https://docs.livekit.io/agents/models/stt/
|
||||||
stt=inference.STT(model="deepgram/nova-3", language="multi"),
|
stt=inference.STT(model="assemblyai/universal-3-5-pro", language="en"),
|
||||||
# Text-to-speech (TTS) is your agent's voice, turning the LLM's text into speech that the user can hear
|
# Text-to-speech (TTS) is your agent's voice, turning the LLM's text into speech that the user can hear
|
||||||
# See all available models as well as voice selections at https://docs.livekit.io/agents/models/tts/
|
# See all available models as well as voice selections at https://docs.livekit.io/agents/models/tts/
|
||||||
tts=inference.TTS(
|
tts=inference.TTS(
|
||||||
model="cartesia/sonic-3", voice="9626c31c-bec5-4cca-baa8-f8ba9e84c8bc"
|
model="fishaudio/s2.1-pro", voice="fa4c9eb3dccc4806b382b40d61c6b10a"
|
||||||
),
|
),
|
||||||
# VAD and turn detection are used to determine when the user is speaking and when the agent should respond
|
turn_handling=TurnHandlingOptions(
|
||||||
# See more at https://docs.livekit.io/agents/build/turns
|
# The LiveKit turn detector determines when the user is done speaking and the agent should respond.
|
||||||
turn_detection=MultilingualModel(),
|
# TurnDetector is an end-of-turn model that listens to the user's audio directly, combining
|
||||||
vad=ctx.proc.userdata["vad"],
|
# semantic understanding with acoustic cues (intonation, pitch, rhythm) for state-of-the-art accuracy.
|
||||||
# allow the LLM to generate a response while waiting for the end of turn
|
# AgentSession supplies the required VAD automatically.
|
||||||
# See more at https://docs.livekit.io/agents/build/audio/#preemptive-generation
|
# See more at https://docs.livekit.io/agents/build/turns
|
||||||
preemptive_generation=True,
|
turn_detection=inference.TurnDetector(),
|
||||||
|
# Adaptive interruptions use the turn detector to tell a real interruption from a
|
||||||
|
# backchannel like "mhm" or "right", so the agent keeps talking through the latter.
|
||||||
|
interruption={"mode": "adaptive"},
|
||||||
|
# allow the LLM to generate a response while waiting for the end of turn
|
||||||
|
# See more at https://docs.livekit.io/agents/build/audio/#preemptive-generation
|
||||||
|
preemptive_generation={"enabled": True},
|
||||||
|
),
|
||||||
|
# Expressive mode injects the TTS provider's markup guide into the LLM prompt, so the model
|
||||||
|
# emits inline delivery tags (emotion, pacing, non-verbal sounds) that the TTS renders and
|
||||||
|
# the transcript never shows. Requires a TTS model that supports markup, such as the Fish
|
||||||
|
# Audio model above.
|
||||||
|
expressive=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Start the session, which initializes the voice pipeline and warms up the models
|
# Start the session, which initializes the voice pipeline and warms up the models
|
||||||
|
|||||||
+10
-4
@@ -21,6 +21,14 @@ tasks:
|
|||||||
- task: set_agent_name_if_present
|
- task: set_agent_name_if_present
|
||||||
- task: help_open_sandbox_if_present
|
- task: help_open_sandbox_if_present
|
||||||
|
|
||||||
|
help_install_hint_if_needed:
|
||||||
|
desc: "Print the local install hint, unless the CLI already installed dependencies"
|
||||||
|
status:
|
||||||
|
# Skip when `lk agent init --install` already ran the install task.
|
||||||
|
- test -n "$LIVEKIT_DEPS_INSTALLED"
|
||||||
|
cmds:
|
||||||
|
- echo '{{ indent .INDENT "uv sync" }}'
|
||||||
|
|
||||||
set_agent_name_if_present:
|
set_agent_name_if_present:
|
||||||
status:
|
status:
|
||||||
- test -z "$LIVEKIT_AGENT_NAME"
|
- test -z "$LIVEKIT_AGENT_NAME"
|
||||||
@@ -42,8 +50,7 @@ tasks:
|
|||||||
- echo 'To try your new agent directly in your terminal:'
|
- echo 'To try your new agent directly in your terminal:'
|
||||||
- echo ''
|
- echo ''
|
||||||
- echo '{{ indent .INDENT "cd" }} {{ .REL_PATH }}'
|
- echo '{{ indent .INDENT "cd" }} {{ .REL_PATH }}'
|
||||||
- echo '{{ indent .INDENT "uv sync" }}'
|
- task: help_install_hint_if_needed
|
||||||
- echo '{{ indent .INDENT "uv run" }} {{ .PYTHON_MAIN }} download-files'
|
|
||||||
- echo '{{ indent .INDENT "uv run" }} {{ .PYTHON_MAIN }} console'
|
- echo '{{ indent .INDENT "uv run" }} {{ .PYTHON_MAIN }} console'
|
||||||
|
|
||||||
help_open_web_console:
|
help_open_web_console:
|
||||||
@@ -56,8 +63,7 @@ tasks:
|
|||||||
- echo 'To try your new agent in the web console:'
|
- echo 'To try your new agent in the web console:'
|
||||||
- echo ''
|
- echo ''
|
||||||
- echo '{{ indent .INDENT "cd" }} {{ .REL_PATH }}'
|
- echo '{{ indent .INDENT "cd" }} {{ .REL_PATH }}'
|
||||||
- echo '{{ indent .INDENT "uv sync" }}'
|
- task: help_install_hint_if_needed
|
||||||
- echo '{{ indent .INDENT "uv run" }} {{ .PYTHON_MAIN }} download-files'
|
|
||||||
- echo '{{ indent .INDENT "uv run" }} {{ .PYTHON_MAIN }} dev'
|
- echo '{{ indent .INDENT "uv run" }} {{ .PYTHON_MAIN }} dev'
|
||||||
- echo ''
|
- echo ''
|
||||||
- echo 'Then visit:'
|
- echo 'Then visit:'
|
||||||
|
|||||||
Reference in New Issue
Block a user