This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Mohammed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I can help, but I need a bit more detail to give the right instructions. Which kind of test do you mean? • Unit test for LiveKit SDK code (which language: JavaScript, TypeScript, Python, Go, etc.) • Integration or end-to-end test for rooms/participants (automated join/leave, media, signaling) • Testing a LiveKit voice agent using another agent (simulated user + evaluation agent) • A different kind of test (please describe) Also tell me: • The repo or SDK you're using and its language/runtime • Any existing test framework you prefer (jest, pytest, go test, etc.) • One example scenario you want to cover (e.g., “agent responds correctly to order flow” or “participant reconnects after network drop”) Give those details and I’ll provide a concise, step-by-step test example you can run. Sources: Agents (Python) | livekit/livekit_composite | DeepWiki | How to test your agent using another agent | examples/drive-thru | livekit/livekit_composite | DeepWiki
Thanks — I can help with Python tests. Quick clarifying questions so I give a targeted example: • Which kind of test do you want to write in Python? ◦ Unit test for agent functions (logic only) ◦ Integration / end-to-end test for a voice agent (room join, STT/TTS, conversation flow) ◦ Agent-to-agent testing using an evaluation agent (simulated user + grader) ◦ Other (please describe) • Which test framework do you prefer? (pytest, unittest, or none) • Do you want to run tests locally or in CI? Any mockable components needed (STT/TTS/LLM)? Give those details and I’ll provide a concise, runnable Python test example and setup steps. Sources: How to test your agent using another agent | MCP Agent | LiveKit docs | Using the Testing Framework with Realtime Models
Thanks — I’ll show a concise end-to-end test pattern for a LiveKit voice agent in Python. This uses an evaluation agent as a simulated user, runs a real room join, exercises the conversation flow, and asserts on agent replies. Ask for adjustments if you need mocks, CI tips, or different assertions. Prerequisites • Python project with your voice agent code. • LiveKit server running and accessible, and credentials for creating/joining rooms. • pytest installed:
pip 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.
Copy code
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?