witty-yak-62929
09/03/2025, 5:32 AMtall-airline-16756
09/03/2025, 5:32 AMtall-airline-16756
09/03/2025, 5:33 AMpytest and pytest-asyncio.
2. Use the @pytest.mark.asyncio decorator to handle async test functions smoothly.
3. Create an AgentSession with a RealtimeModel inside an async context manager — this keeps things neat and tidy.
4. Start the agent and run your test interactions using session.run(user_input=...).
5. Don’t forget to add assertions to check the agent’s behavior, like evaluating intent with .judge().
Here’s a quick example of how to initialize a realtime model for your tests:
rt_llm = openai.realtime.RealtimeModel(
modalities=["text"], # makes sure it works well with text-based testing
voice="alloy", # optional voice setting if you want it
temperature=0.7 # tweak this if you want to change the randomness
)
And here’s what the test setup might look like:
async with (
openai.LLM(model="gpt-4o-mini") as judge_llm, # this LLM helps judge responses
AgentSession(llm=rt_llm, userdata=userdata) as sess,
):
await sess.start(YourAgent(userdata=userdata))
result = await sess.run(user_input="...") # pop in your test input here
await result.expect.next_event().is_message(role="assistant").judge(
judge_llm,
intent="Expected agent behavior based on the prompt"
)
If you want me to walk you through anything else or provide some tailored examples, just let me know — I’m happy to help!
Sources: Testing and evaluation | LiveKit Docs | Using the Testing Framework with Realtime Models | Realtime model integrations | LiveKit Docs | Adjusting Model Parameters | LiveKit Docs | OpenAI Realtime API integration guide | LiveKit Docswitty-yak-62929
09/03/2025, 5:37 AMtall-airline-16756
09/03/2025, 5:37 AMTypeError: 'AgentSession' object does not support the asynchronous context manager protocol usually pops up if the AgentSession isn’t being used quite right or if the library version you have doesn’t support it yet.
Here’s a quick way to tackle it:
1. Double-check that you’re using the right version of the LiveKit library that actually supports asynchronous context management for AgentSession.
2. Make sure you’re importing and using AgentSession the right way. For example:
from livekit import AgentSession
1. See if your version of the library needs you to initialize AgentSession with some extra parameters or in a specific way.
If you’re still stuck, feel free to share the exact bit of code where you’re setting up and using AgentSession. I’d be happy to take a closer look and help you sort it out!