calm-eye-57311
09/29/2025, 12:56 PMtall-airline-16756
09/29/2025, 12:56 PMtall-airline-16756
09/29/2025, 12:56 PMrun_app or agent dispatch for unit testing? Sharing a bit more about your goals will really help me support you in the best way possible.calm-eye-57311
09/29/2025, 1:03 PMtall-airline-16756
09/29/2025, 1:04 PMcalm-eye-57311
09/29/2025, 1:05 PMtall-airline-16756
09/29/2025, 1:05 PMAgentSession class along with fake components like FakeLLM, FakeSTT, and FakeTTS. This setup helps simulate the agent’s environment without needing real-time audio processing, which makes testing much easier.
• Mock Tools: You can use the mock_tools context manager to swap out real tools for mocked versions. This is really handy when you want to simulate both normal behaviors and error scenarios.
• Test Multi-Turn Conversations: By calling session.run() multiple times, you can mimic a conversation where the agent naturally keeps track of context across turns.
• Assert Events: The RunResult object is your friend here—it lets you verify event sequences like function calls, messages, and final states, ensuring everything happens as expected.
• Use Fixtures: Consider creating reusable test setups with @pytest_asyncio.fixture. This helps keep your tests clean and easy to maintain.
Here’s a quick example of how you might mock a tool to simulate a failure scenario:
def failing_print():
raise RuntimeError("Console unavailable")
with mock_tools(FunctionAgent, {"print_to_console": failing_print}):
result = await session.run(user_input="Print to console")
result.expect.next_event().is_function_call(name="print_to_console")
result.expect.next_event().is_function_call_output()
If you’d like to dive deeper, the LiveKit Testing Documentation is a fantastic resource to explore. Please feel free to reach out if you have any questions or need further guidance—I’m here to help!
Sources: livekit-agents/livekit/agents/ipc/mock_room.py | complex-agents/drive-thru/test_agent.py | Testing and evaluation | LiveKit Docscalm-eye-57311
09/29/2025, 1:08 PMtall-airline-16756
09/29/2025, 1:09 PM