How can I text the agent instead of spinning up a ...
# ask-ai
f
How can I text the agent instead of spinning up a call every time I want to test changes? Is there a way to just text it quickly to test locally?
t
Thanks for reaching out, Luke. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're exploring ways to test changes locally! You can use text-only testing with LiveKit's built-in testing helpers, which lets you send and receive text input/output without involving audio. This makes it a quick and cost-effective way to evaluate your agent's behavior. Here’s a simple way to get started: 1. Install Required Packages: First, make sure you have
pytest
and
pytest-asyncio
installed:
Copy code
pip install pytest pytest-asyncio
1. Configure Text-Only Mode: Next, set up the
AgentSession
to enable text input/output and disable audio:
Copy code
await session.start(
    agent=MyAgent(),
    room=ctx.room,
    room_input_options=RoomInputOptions(text_enabled=True, audio_enabled=False),
    room_output_options=RoomOutputOptions(transcription_enabled=True, audio_enabled=False),
)
1. Send Text Input: You can then use
generate_reply()
or a
TextStream
to send text input to your agent:
Copy code
result = await session.run(user_input="Hello")
1. Receive Agent Responses: To capture responses, listen to the
conversation_item_added
event like this:
Copy code
@session.on("conversation_item_added")
def on_conversation_item_added(event):
    print(f"Agent response: {event.item.text}")
1. Write and Run Tests: Finally, use
pytest
to structure and validate your test cases. This method is perfect for focusing on your agent's logic without the need to set up voice or telephony infrastructure. If you have any questions or need a hand with anything, please don’t hesitate to ask—I’m here to help! Sources: Testing and evaluation | LiveKit Docs | Docs::Agents | examples/other/text_only.py | README.md | livekit/tests/data_stream_test.rs