ambitious-dusk-46857
08/01/2025, 10:23 AMtall-airline-16756
08/01/2025, 10:23 AMtall-airline-16756
08/01/2025, 10:23 AMclass MyAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="You are a helpful assistant.",
)
2. Configure the Agent Session for Text-Only Interaction:
async def entrypoint(ctx: JobContext):
session = AgentSession(
llm=openai.LLM(model="gpt-4o-mini"),
)
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),
)
3. Handle Text Input and Output:
Use session.generate_reply() to send messages to users and listen for incoming messages using session.on() events.
Here is the complete example code:
import logging
from dotenv import load_dotenv
from livekit.agents import (
Agent,
AgentSession,
JobContext,
RoomInputOptions,
RoomOutputOptions,
WorkerOptions,
cli,
)
from livekit.plugins import openai
logger = logging.getLogger("text-only")
logger.setLevel(<http://logging.INFO|logging.INFO>)
load_dotenv()
class MyAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="You are a helpful assistant.",
)
async def entrypoint(ctx: JobContext):
session = AgentSession(
llm=openai.LLM(model="gpt-4o-mini"),
)
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),
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
For more details, you can refer to the Text-Only Agent Example in the LiveKit repository.ambitious-dusk-46857
08/01/2025, 10:28 AMtall-airline-16756
08/01/2025, 10:29 AMAgentSession(
llm=openai.LLM(model="gpt-4o-mini"),
room=ctx.room,
room_input_options=RoomInputOptions(text_enabled=True, audio_enabled=False),
room_output_options=RoomOutputOptions(transcription_enabled=True, audio_enabled=False),
)
4. Handle Conversation Events:
You can also listen for events like conversation_item_added to catch new messages and respond accordingly:
session.on("conversation_item_added", callback_function)
Following these steps will have you chatting with your agent in the console in no time. If you have any questions along the way, I’m here to help!
Sources: livekit-agents/livekit/agents/voice/chat_cli.py | Text and transcriptions | LiveKit Docs