agreeable-dream-41746
10/15/2025, 11:41 PMtall-airline-16756
10/15/2025, 11:42 PMtall-airline-16756
10/15/2025, 11:43 PMasync def send_tool_result(self, call_id: str, result: str):
event = ClientToolResultEvent(
invocationId=call_id,
result=result,
agent_reaction="speaks",
)
self._send_client_event(event)
Now, about having the agent speak while the tool is still running—this isn't supported in the standard flow. But don't worry! You can use session.say() inside your tool to give immediate updates as it runs. Here's how you might do that:
@function_tool
async def long_running_task(ctx: RunContext):
await ctx.session.say("Starting your request...")
result = perform_complex_operation()
return result
This way, the agent can share progress updates during execution, and then the final response from the LLM will come once the tool finishes. I hope this helps clarify things! If you have any more questions or need further assistance, feel free to ask.
Sources: Tool definition and use | LiveKit Docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/...agreeable-dream-41746
10/16/2025, 12:03 AMtall-airline-16756
10/16/2025, 12:04 AMagreeable-dream-41746
10/16/2025, 12:05 AMtall-airline-16756
10/16/2025, 12:05 AMlookup_weather, with the parameter location="San Francisco".
3. Function Execution: The lookup_weather tool runs and returns a result, for example, "sunny with a temperature of 70 degrees."
4. LLM Generates a Response: Using that result, the LLM crafts a reply such as "The weather in San Francisco is sunny with a temperature of 70 degrees."
5. Agent Speaks the Response: Finally, the agent uses text-to-speech (TTS) to speak the generated reply.
Example Code:
@function_tool
def lookup_weather(location: str):
"""Fetches weather information for a given location."""
# Simulate a weather lookup
return f"sunny with a temperature of 70 degrees in {location}."
# User input triggers the following flow:
user_input = "What is the weather in San Francisco?"
# LLM decides to call the tool
result = lookup_weather(location="San Francisco")
# LLM generates a response based on the result
response = f"The weather in San Francisco is {result}"
# Agent speaks the response
print(response) # Output: "The weather in San Francisco is sunny with a temperature of 70 degrees."
I hope this helps clarify how the system works! If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!agreeable-dream-41746
10/16/2025, 12:45 AMtall-airline-16756
10/16/2025, 12:46 AMagreeable-dream-41746
10/16/2025, 12:49 AMtall-airline-16756
10/16/2025, 12:49 AM@function_tool
def lookup_weather(location: str):
"""Fetches weather information for a given location."""
# Simulate a weather lookup
return f"sunny with a temperature of 70 degrees in {location}."
# User input triggers the following flow:
user_input = "What is the weather in San Francisco?"
# LLM decides to call the tool
result = lookup_weather(location="San Francisco")
# LLM uses the tool result to generate a full reply
response = f"I checked the weather for you. The weather in San Francisco is {result}. It looks like a great day to go outside!"
# Agent speaks the response
print(response) # Output: "I checked the weather for you. The weather in San Francisco is sunny with a temperature of 70 degrees. It looks like a great day to go outside!"
So, in this flow, the LLM takes the tool’s result and weaves it into a full, friendly response. The agent then shares this complete reply with you. If you’d like, I’m here to help with more details or additional examples—just let me know!agreeable-dream-41746
10/16/2025, 12:53 AMtall-airline-16756
10/16/2025, 12:54 AMgenerate_reply() method to guide the LLM in crafting a complete and thoughtful response. Here's a simple example to walk you through it:
@function_tool()
def lookup_weather(location: str):
"""Fetches weather information for a given location."""
# Simulate a weather lookup
return f"sunny with a temperature of 70 degrees in {location}."
# User input triggers the following flow:
user_input = "What is the weather in San Francisco?"
# LLM decides to call the tool
result = lookup_weather(location="San Francisco")
# Generate a dynamic reply based on the tool result
session.generate_reply(
instructions=f"Generate a reply based on the weather: {result}"
)
In this example, the tool result (like "sunny with a temperature of 70 degrees in San Francisco") is passed along with clear instructions to the LLM, helping it create a full, relevant reply. The agent then shares this dynamically generated response with the user.
If you have any questions or want me to walk you through more examples, just let me know—I'm here to help!
Sources: Agent speech and audio | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | Tool definition and use | LiveKit Docs | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWikiagreeable-dream-41746
10/16/2025, 12:55 AMtall-airline-16756
10/16/2025, 12:55 AM@function_tool()
def lookup_weather(location: str):
"""Fetches weather information for a given location."""
# Simulate a weather lookup
return f"sunny with a temperature of 70 degrees in {location}."
# Initial speech
session.say("Let me check the weather for you.")
# Call the tool
result = lookup_weather(location="San Francisco")
# Generate follow-up speech based on the tool result
session.generate_reply(
instructions=f"Generate a reply based on the weather: {result}"
)
This way, the agent speaks first, then calls the tool, and continues the conversation based on what the tool returns. If you’d like me to walk you through this more or provide additional examples, just let me know—I’m here to help!
Sources: agents/src/voice/agent_activity.ts | examples/warm-transfer/warm_transfer.py | Tool definition and use | LiveKit Docsagreeable-dream-41746
10/16/2025, 2:01 AMtall-airline-16756
10/16/2025, 2:02 AMagreeable-dream-41746
10/16/2025, 2:05 AMtall-airline-16756
10/16/2025, 2:06 AM@function_tool()
def lookup_weather(location: str):
"""Fetches weather information for a given location."""
# Simulate a weather lookup
return f"sunny with a temperature of 70 degrees in {location}."
# Initial reply
session.generate_reply(
instructions="Let me check the weather for you."
)
# Call the tool
result = lookup_weather(location="San Francisco")
# Generate a follow-up reply based on the tool result
session.generate_reply(
instructions=f"The weather in San Francisco is {result}."
)
This way, the LLM gives an initial response before the tool runs, then uses the tool's result to provide a thoughtful follow-up. If you have any questions or want me to walk you through more examples, just let me know—I'm here to help!
Sources: Tool definition and use | LiveKit Docs | examples/voice_agents/multi_agent.pyagreeable-dream-41746
10/16/2025, 2:12 AMtall-airline-16756
10/16/2025, 2:12 AMgenerate_reply call before the previous one finishes without canceling the one that’s already running. If you do trigger a new generate_reply while the earlier one is still going, the first will be automatically canceled to make room for the new request.
But don’t worry! If you want to stop the current speech smoothly before starting a new one, you can use the SpeechHandle object that generate_reply returns. This lets you gracefully interrupt the ongoing utterance. If you'd like, I’m here to help you with how to set this up—just let me know!
Sources: plugins/google/src/beta/realtime/realtime_api.ts | tests/test_agent_session.py | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki