steep-balloon-41261
01/02/2026, 6:02 AMtall-airline-16756
01/02/2026, 6:02 AMtall-airline-16756
01/02/2026, 6:03 AMtall-airline-16756
01/02/2026, 6:04 AMtall-airline-16756
01/02/2026, 6:07 AMpip install pytest
• Access to any STT/TTS/LLM services your agent uses, or ability to run the agent in console/simulated mode.
Test strategy (high level)
1. Start or reuse a LiveKit test room.
2. Start your voice agent instance (the code under test) and have it join the room.
3. Start an evaluation/simulated user agent that joins the same room and sends spoken or text prompts (the evaluation agent can use RoomInputOptions with allow_agent_input=True / participant_kinds=[ParticipantKind.AGENT]).
4. Let the simulated user speak prompts; capture the agent’s audio/text responses.
5. Grade/assert responses using automated checks (exact match, regex, or semantic checks via an LLM grader).
6. Clean up room and stop components.
Minimal pytest example
• Adjust imports, start/stop routines, and endpoints to match your project's structure.
• This example assumes your agent can be started programmatically and exposes an API to join rooms and send/receive messages. Replace placeholder functions with your implementations.
import time
import re
import pytest
# Placeholder helpers — replace these with your concrete implementations
from myproject.livekit_helpers import (
create_test_room,
delete_room,
start_voice_agent, # starts agent process and joins room
stop_voice_agent,
start_eval_agent, # simulated user/evaluator that can send prompts & receive replies
stop_eval_agent,
send_eval_prompt,
receive_agent_transcript, # fetches transcripts/text from agent or room events
)
ROOM_TTL = 60 # seconds
@pytest.fixture(scope="module")
def test_room():
room = create_test_room(ttl=ROOM_TTL)
yield room
delete_room(room)
@pytest.fixture
def voice_agent(test_room):
agent = start_voice_agent(room=test_room)
yield agent
stop_voice_agent(agent)
@pytest.fixture
def eval_agent(test_room):
evala = start_eval_agent(room=test_room, allow_agent_input=True)
yield evala
stop_eval_agent(evala)
def test_order_flow_e2e(voice_agent, eval_agent):
"""
End-to-end scenario:
- Simulated user places an order via evaluation agent prompts
- Voice agent should confirm order and provide an order number
"""
# 1) Send initial prompt from simulated user
send_eval_prompt(eval_agent, "Hi, I'd like to order a large pepperoni pizza, please.")
time.sleep(2) # allow processing / STT / TTS round-trip
# 2) Capture agent response transcript (text)
resp = receive_agent_transcript(voice_agent, timeout=10)
assert resp is not None, "Agent did not respond"
# 3) Basic assertions: contains confirmation and an order number pattern
assert "confirm" in resp.lower() or "order" in resp.lower()
assert re.search(r"\b(order|confirmation)\b.*\d{3,}", resp.lower()) or re.search(r"\b\d{3,}\b", resp)
# 4) Optionally continue flow
send_eval_prompt(eval_agent, "Can I add extra cheese?")
time.sleep(1.5)
resp2 = receive_agent_transcript(voice_agent, timeout=8)
assert "extra cheese" in resp2.lower() or "sure" in resp2.lower()
Key implementation notes and options
• How to simulate speech:
◦ If your evaluation agent supports text-to-speech injection into the LiveKit room, use that so the voice agent goes through STT/TTS as in production.
◦ Alternatively, send text prompts directly if your agent supports text-mode inputs for tests.
• Evaluation agent grading:
◦ For semantic checks, run a lightweight LLM grader or simple pattern checks as shown.
◦ The LiveKit evaluation pattern supports LLM-based graders and the @function_tool pattern for automated scoring.
• Timing and flakiness:
◦ Use reasonable timeouts and retry loops for transient STT/LLM delays.
◦ Consider increasing sleeps for CI or using event-based waits tied to room events instead of fixed sleeps.
• Cleanup:
◦ Ensure you stop agents and delete test rooms in teardown to avoid resource leaks.
• CI considerations:
◦ If external STT/TTS/LLM services are rate-limited, mock them in unit tests and reserve end-to-end tests for nightly runs.
If you want, I can:
• Provide concrete helper implementations for creating rooms, starting agents, and reading transcripts (tell me how your agent is started and where it logs/outputs responses).
• Convert this test to use event-based waits (room events) instead of sleeps.
• Show an example using a specific STT/TTS provider mock or LLM grader.
Which follow-up would you like?