early-afternoon-97327
08/12/2025, 6:40 PMtall-airline-16756
08/12/2025, 6:40 PMtall-airline-16756
08/12/2025, 6:40 PMBackgroundAudioPlayer
class is perfect for playing ambient and thinking sounds during your session. Here’s a quick example of how you might set it up:
background_audio = BackgroundAudioPlayer(
ambient_sound=AudioConfig(BuiltinAudioClip.OFFICE_AMBIENCE, volume=0.8),
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
],
)
await background_audio.start(room=ctx.room, agent_session=session)
This setup usually won’t increase latency, but it’s a good idea to keep an eye on your system’s performance just to be safe. If you do notice any lag, you might want to try:
• Turning down the volume of your background sounds
• Using simpler audio files
• Making sure your system has enough resources available
If you want me to help you tweak anything or have more questions, just let me know—I’m here for you!
Sources: examples/voice_agents/zapier_mcp_integration.py | Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docsearly-afternoon-97327
08/12/2025, 6:43 PMtall-airline-16756
08/12/2025, 6:43 PMBackgroundAudioPlayer
to do just that. It kicks in specifically when the agent enters the "thinking" state, which happens during those extended processing times. Here’s a quick example to get you started:
from livekit.agents import BackgroundAudioPlayer, AudioConfig, BuiltinAudioClip
background_audio = BackgroundAudioPlayer(
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
],
)
async def entrypoint(ctx: JobContext):
session = AgentSession(
# Initialize your agent session with required components
)
await session.start(room=ctx.room, agent=agent)
await background_audio.start(
room=ctx.room,
agent_session=session
)
The BackgroundAudioPlayer
will automatically notice when the agent is "thinking" and play those sounds you set up. If you have any questions or want to tweak it further, just let me know—I’m here to help!early-afternoon-97327
08/12/2025, 6:49 PMtall-airline-16756
08/12/2025, 6:50 PMBackgroundAudioPlayer
to kick in specifically when the agent is in the "thinking" state while executing tools. Here's a little example to get you started:
from livekit.agents import BackgroundAudioPlayer, AudioConfig, BuiltinAudioClip
# Setting up the BackgroundAudioPlayer with some thinking sounds
background_audio = BackgroundAudioPlayer(
thinking_sound=[
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING, volume=0.8),
AudioConfig(BuiltinAudioClip.KEYBOARD_TYPING2, volume=0.7),
],
)
async def entrypoint(ctx: JobContext):
session = AgentSession(
# Just initialize your agent session with whatever you need
)
await session.start(room=ctx.room, agent=agent)
# Now, start the BackgroundAudioPlayer
await background_audio.start(
room=ctx.room,
agent_session=session
)
This way, the background sound will only play when the agent’s in the "thinking" state — like during those tool calls. If you want to tweak it more or have any questions, just let me know. I’m here to help!early-afternoon-97327
08/12/2025, 6:57 PMtall-airline-16756
08/12/2025, 6:58 PMFunctionToolsExecutedEvent
. Here’s a simple way to set it up:
# Add an event listener to capture tool call events
session.on("function_tools_executed", function_tools_executed_event_handler)
# Implement the event handler
def function_tools_executed_event_handler(event: FunctionToolsExecutedEvent):
# Access tool call details
for function_call in event.function_calls:
print(f"Tool Name: {function_call.name}")
print(f"Arguments: {function_call.arguments}")
print(f"Call ID: {function_call.call_id}")
# Access tool call outputs
for function_call_output in event.function_call_outputs:
if function_call_output:
print(f"Output: {function_call_output.output}")
The FunctionToolsExecutedEvent
gives you all the info about tool executions—like the tool name, arguments, call ID, and outputs. It’s automatically fired during the agent’s tool execution, so you don’t have to do anything extra.
Also, if you’re trying to recreate something from "agent version 0," could you share a bit more about what you’re aiming for? That way, I can help you better and make sure you get exactly what you need.
Sources: livekit-agents/livekit/agents/voice/run_result.pyearly-afternoon-97327
08/12/2025, 7:01 PMtall-airline-16756
08/12/2025, 7:02 PMfunction_tools_executed
event to keep an eye on when a tool starts executing. This event kicks in right as the tool execution begins and gives you info like the tool’s name, its arguments, and the call ID.
Here’s a quick example:
# Listen for the function_tools_executed event
session.on("function_tools_executed", callback_function)
# Access function call details in the callback
def callback_function(event: FunctionToolsExecutedEvent):
for call in event.function_calls:
print(f"Tool Name: {call.name}")
print(f"Arguments: {call.arguments}")
If you want to grab details before the tool actually starts, you might need to add some custom logic in your app to log or handle those details beforehand. Just give me a shout if you want a hand setting that up!early-afternoon-97327
08/12/2025, 7:05 PMtall-airline-16756
08/12/2025, 7:06 PMfunction_tools_executed
event in LiveKit, you'll want to import these:
from livekit.agents import AgentSession
from livekit.agents.voice.events import FunctionToolsExecutedEvent
Here’s a simple example of how to set up the event listener:
# Set up event listener
@session.on("function_tools_executed")
def on_function_tools_executed(event: FunctionToolsExecutedEvent):
# Handle the event here
print("Function tools executed:")
for call, output in event.zipped():
print(f" - {call.name}: {output}")
If you have any questions or want me to walk you through anything else, just let me know!
Sources: livekit-agents/livekit/agents/voice/generation.py | Events and error handling | LiveKit Docs