elegant-noon-41140
09/15/2025, 6:03 PMtall-airline-16756
09/15/2025, 6:03 PMtall-airline-16756
09/15/2025, 6:04 PMelegant-noon-41140
09/15/2025, 6:13 PMtall-airline-16756
09/15/2025, 6:15 PMimport logging
from dataclasses import dataclass, field
from typing import Dict, List
from livekit.agents import JobContext, WorkerOptions, cli
from livekit.agents.llm import function_tool
from livekit.agents.voice import Agent, AgentSession
@dataclass
class AgentData:
user_name: str = ""
responses: Dict[str, str] = field(default_factory=dict)
class SmallTalkAgent(Agent):
def __init__(self, job_context: JobContext):
super().__init__(instructions="Start with smalltalk and gather user info.")
async def on_enter(self):
await self.session.say("Hello! What's your name?")
@function_tool
async def gather_user_info(self, name: str):
self.session.userdata.user_name = name
return QuizAgent(self.session.job_context)
class QuizAgent(Agent):
def __init__(self, job_context: JobContext):
super().__init__(instructions="Create and display a quiz.")
async def on_enter(self):
await self.session.say("Let's start a quiz!")
@function_tool
async def quiz_completed(self):
return StoryAgent(self.session.job_context, self.session.userdata.user_name)
class StoryAgent(Agent):
def __init__(self, job_context: JobContext, user_name: str):
super().__init__(instructions=f"Tell a story for {user_name}.")
async def on_enter(self):
await self.session.say(f"Once upon a time, {user_name}...")
async def entrypoint(ctx: JobContext):
session = AgentSession()
session.userdata = AgentData()
await session.start(agent=SmallTalkAgent(ctx))
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
This example warmly walks you through:
• Smalltalk Stage: A friendly way to gather some info about you.
• Quiz Stage: Engages you with a quiz and smoothly moves to the next part.
• Storytelling Stage: Crafts a personalized story just for you using the info you shared.
To make everything work beautifully, you'll want to integrate RPCs for handling the quiz and set up the frontend to show quizzes and stories. If you need any help with that, I'm here for you!
Sources: avatars/hedra/education_avatar/education-frontend/components/quiz-container... | examples/voice_agents/multi_agent.pyelegant-noon-41140
09/15/2025, 6:19 PMtall-airline-16756
09/15/2025, 6:20 PMoutput.audio_enabled is set to True.
3. Check Logs: Take a look at the logs to see if the agent is entering the "speaking" state. If it is, but you still don’t hear audio, the issue might be related to network or playback settings.
4. Realtime Model Settings: If you’re using a RealtimeModel, double-check that allow_interruptions is enabled and that turn detection is configured correctly.
5. Network Issues: Lastly, if you’re using telephony integrations, please verify your SIP trunk credentials and ensure there aren’t any connectivity problems.
If you’d like, let me know which of these you’ve already looked into, and I’ll be happy to guide you through the next steps. We’ll get this working together!
Sources: SIP troubleshooting guide | LiveKit Docs | How to Enable Agent-to-Agent Speech Detection in LiveKit | Events and error handling | LiveKit Docs | Knowledge Management System | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/agent_activity.pyelegant-noon-41140
09/15/2025, 6:23 PMtall-airline-16756
09/15/2025, 6:24 PMbefore_tts_cb callback to gently clean up or adjust the text before it’s spoken. Here’s a simple example:
Sources: chain-of-thought-tts/README.mdoc | Modifying LLM output before TTS | LiveKit Docs