We're writing automated text-only behavioral tests...
# ask-ai
b
We're writing automated text-only behavioral tests for our │ │ LiveKit agent using AgentSession. For each scripted persona │ │ turn we currently call await session.run(user_input=...), then │ │ consume the resulting events via result.expect.... This │ │ works, but it requires one session.run per turn to keep the │ │ transcript updated. │ │ │ │ Is there a more concise or efficient pattern you recommend for │ │ multi-turn scripted conversations in tests? For example, can │ │ we supply a sequence of user utterances in one call, or is │ │ there an existing helper/fixture that better simulates │ │ multi-turn text chats without manually looping over │ │ session.run? If you have an official example or guidance, we'd │ │ appreciate it.
t
Thanks for reaching out, Sebastian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you have smoother and more efficient multi-turn scripted conversations in your tests using
AgentSession
, here are some friendly tips you might find useful: • Scripted User Inputs: You can use
FakeActions.add_user_speech()
to set up a sequence of user inputs with precise timing. This way, you don’t have to manually loop over
session.run
, making things a bit easier! • Simulate Responses: It’s great to predefine LLM replies and TTS playback durations using
actions.add_llm()
and
actions.add_tts()
. This helps you test specific conversational flows smoothly. • Event-Based Assertions: Try listening to session events like
conversation_item_added
and
agent_state_changed
. This lets you check message order, state changes, and tool executions, ensuring everything’s working as expected. • Speed Factor: The
speed_factor
parameter is your friend when you want to speed up test execution without messing up the event order. • Validate Chat Context: After your session ends, take a moment to verify the full conversation history in
agent.chat_ctx.items
. This ensures your context is building up just right. These approaches should really help streamline your testing and give you confidence in your multi-turn interactions. If you’d like, I’m here to provide more details or examples to guide you through! Sources: livekit-plugins/livekit-plugins-turn-detector/README.md | Testing and evaluation | LiveKit Docs | Testing and evaluation | LiveKit Docs
b
none of this makes sence this is for testing llm to llm no need for stt tts?
t
To help you test multi-turn scripted conversations without using STT or TTS, here are some friendly recommendations you might find useful: • Direct User Input: You can use
session.run(user_input=...)
to directly inject text for each user turn. This way, you can skip the audio input and focus purely on text-based interactions. • Predefined Context: Try using
ChatContext
to set up prior conversation history. For example, you can add user and assistant messages to simulate an ongoing dialogue before you start the session, which helps create a more realistic testing environment. • Validate Outputs: Don’t forget to use
RunResult.expect
to check for expected responses, whether that’s function calls, assistant messages, or intent accuracy. It’s a great way to make sure everything is working as it should. • Mock Tools: You can simulate tool behavior or even errors using
mock_tools
. This is really handy for testing edge cases and how tools execute within conversations. • Speed Scaling: If you want to speed things up, the
speed_factor
parameter lets you accelerate tests while keeping the timing relationships accurate. These approaches can really help streamline your text-only testing and give you confidence in the reliability of your multi-turn interactions. If you’d like, I’m here to walk you through any part of this or provide some examples—just let me know! Sources: examples/voice_agents/langgraph_agent.py | complex-agents/drive-thru/test_agent.py