How to force agent to say something based on a too...
# ask-ai
c
How to force agent to say something based on a tool call and then wait for user reply
t
Thanks for reaching out, Simon. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for reaching out. Could you please provide more details about the issue you are experiencing? This will help us assist you better. Sources: agent.py | Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py
c
need to force agent to say something based on a tool call and then wait for user reply
t
• Use
session.say()
with `SpeechHandle`:
Hey there! Let me walk you through a super helpful way to make your agent sound more natural. This method is like giving your agent a friendly voice that pauses to make sure the user is listening. Check out this cool example:
Copy code
handle = session.say("Let me check that for you.")
await handle  # Wait for speech to complete
And if you want to be extra smooth, here's a quick shortcut:
await session.say("Goodbye for now.", allow_interruptions=False)
• Within tool functions: Oh, and here's another neat trick! You can have your agent speak directly inside tool functions. It's like having a helpful buddy who explains what they're doing. For instance:
Copy code
@function_tool
async def get_weather(self, location: str) -> str:
    await self.session.say("Let me check the weather for you.")
    weather_data = f"The weather in {location} is sunny today."
    return weather_data
These methods are like giving your agent a friendly, conversational touch. They'll speak and then wait to make sure you're following along. Got any questions? I'm here to help you out!