Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

load_dotenv(".env.local")

AGENT_MODEL = "openai/gpt-5.2-chat-latest"


class Assistant(Agent):
def __init__(self) -> None:
Expand All @@ -28,6 +26,17 @@ def __init__(self) -> None:
You eagerly assist users with their questions by providing information from your extensive knowledge.
Your responses are concise, to the point, and without any complex formatting or punctuation including emojis, asterisks, or other symbols.
You are curious, friendly, and have a sense of humor.""",
# 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/
llm=inference.LLM(model="openai/gpt-5.2-chat-latest"),
# To use a realtime model instead of a voice pipeline, replace the LLM
# 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/)
# 1. Install livekit-agents[openai]
# 2. Set OPENAI_API_KEY in .env.local
# 3. Add `from livekit.plugins import openai` to the top of this file
# 4. Replace the llm argument with:
# llm=openai.realtime.RealtimeModel(voice="marin")
)

# To add tools, use the @function_tool decorator.
Expand Down Expand Up @@ -71,9 +80,6 @@ async def my_agent(ctx: JobContext):
# 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/
stt=inference.STT(model="deepgram/nova-3", language="multi"),
# 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/
llm=inference.LLM(model=AGENT_MODEL),
# 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/
tts=inference.TTS(
Expand All @@ -88,16 +94,6 @@ async def my_agent(ctx: JobContext):
preemptive_generation=True,
)

# To use a realtime model instead of a voice pipeline, use the following session setup instead.
# (Note: This is for the OpenAI Realtime API. For other providers, see https://docs.livekit.io/agents/models/realtime/))
# 1. Install livekit-agents[openai]
# 2. Set OPENAI_API_KEY in .env.local
# 3. Add `from livekit.plugins import openai` to the top of this file
# 4. Use the following session setup instead of the version above
# session = AgentSession(
# llm=openai.realtime.RealtimeModel(voice="marin")
# )

# # Add a virtual avatar to the session, if desired
# # For other providers, see https://docs.livekit.io/agents/models/avatar/
# avatar = hedra.AvatarSession(
Expand Down
20 changes: 7 additions & 13 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import pytest
from livekit.agents import AgentSession, inference, llm

from agent import AGENT_MODEL, Assistant


def _agent_llm() -> llm.LLM:
return inference.LLM(model=AGENT_MODEL)
from agent import Assistant


def _judge_llm() -> llm.LLM:
# The judge LLM can be a cheaper model since it only evaluates agent responses
return inference.LLM(model="openai/gpt-4.1-mini")
# We can use a different LLM to evaluate the agent's responses than the one used in the agent itself
# This allows you to use reasoning capabilities or larger models than would be practical for realtime chat
return inference.LLM(model="openai/gpt-5.2")


@pytest.mark.asyncio
async def test_offers_assistance() -> None:
"""Evaluation of the agent's friendly nature."""
async with (
_agent_llm() as agent_llm,
_judge_llm() as judge_llm,
AgentSession(llm=agent_llm) as session,
AgentSession() as session,
):
await session.start(Assistant())

Expand Down Expand Up @@ -50,9 +46,8 @@ async def test_offers_assistance() -> None:
async def test_grounding() -> None:
"""Evaluation of the agent's ability to refuse to answer when it doesn't know something."""
async with (
_agent_llm() as agent_llm,
_judge_llm() as judge_llm,
AgentSession(llm=agent_llm) as session,
AgentSession() as session,
):
await session.start(Assistant())

Expand Down Expand Up @@ -93,9 +88,8 @@ async def test_grounding() -> None:
async def test_refuses_harmful_request() -> None:
"""Evaluation of the agent's ability to refuse inappropriate or harmful requests."""
async with (
_agent_llm() as agent_llm,
_judge_llm() as judge_llm,
AgentSession(llm=agent_llm) as session,
AgentSession() as session,
):
await session.start(Assistant())

Expand Down
Loading