wooden-smartphone-55787
09/22/2025, 10:59 AMtall-airline-16756
09/22/2025, 10:59 AMtall-airline-16756
09/22/2025, 11:00 AMon_enter lifecycle hook in LiveKit! You can do this by using the self.session.generate_reply() method. This method lets you provide clear instructions that guide the LLM to pick and run a specific tool based on its reasoning.
Here's a simple example:
async def on_enter(self):
self.session.generate_reply(instructions="Check the weather in Tokyo")
So, if your agent has a tool like get_weather registered, the LLM will understand the instruction and create a tool call for it, which the system will then carry out.
This way, tool calls are made through the LLM’s decision-making process, keeping everything consistent with how the framework is designed. If you have any questions or want to explore this further, feel free to ask—I’m here to help!
Sources: Docs::Agents | livekit-agents/livekit/agents/voice/agent.py | flows/simple_flow.py | Pipeline nodes and hooks | LiveKit Docswooden-smartphone-55787
09/22/2025, 11:05 AMtall-airline-16756
09/22/2025, 11:06 AMon_enter, here are some friendly steps you can follow:
1. Prevent Instructions from Being Added to Chat Context:
• When you provide instructions using generate_reply(instructions=...), they won’t be added to the chat history. Only the final agent response is saved, so this method keeps things clean by design.
• If you’re using update_instructions() to add system-level instructions, you can easily remove them with remove_instructions(chat_ctx) to make sure they don’t stick around.
2. Prevent Replies During `on_enter`:
• If you don’t want a reply during on_enter, simply avoid calling self.session.generate_reply() or self.session.say().
• If you need to run a tool quietly, just make sure the tool doesn’t return a value—tools without return values won’t trigger any replies.
• Another neat way is to use the function_tools_executed event and call ev.cancel_tool_reply() to stop replies after tool execution, like this:
@session.on("function_tools_executed")
def on_function_tools_executed(ev):
ev.cancel_tool_reply()
Following these tips will help your tool calls run smoothly without adding extra context or generating replies you don’t want. If you have any questions or need more help, feel free to ask—I’m here for you!
Sources: Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.pywooden-smartphone-55787
09/22/2025, 11:09 AMtall-airline-16756
09/22/2025, 11:10 AMev.cancel_tool_reply() in the function_tools_executed event, it stops the LLM from generating a reply right after the tool finishes its job. This is great because it lets the agent keep going smoothly without needing you to jump in, as long as your code has the right steps to handle what comes next.
Once the reply is suppressed, the agent can:
• Take another action, like starting a new tool call or task.
• Stay idle and wait patiently for your next input.
• Or even trigger another response on its own using session.generate_reply() or session.say().
This way, the agent stays active and ready, allowing the conversation to flow naturally without always needing you to step in—just make sure your code includes the logic to guide those next steps.
Sources: Tool definition and use | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | Tool definition and use | LiveKit Docs | Events and error handling | LiveKit Docswooden-smartphone-55787
09/22/2025, 11:11 AMtall-airline-16756
09/22/2025, 11:12 AMev.cancel_tool_reply().
If you’d like the LLM to follow specific instructions right after a tool call without needing any extra input from you, you’ll want to set that up in your code. For instance, you can use session.generate_reply() or other logic to smoothly guide what happens next after the tool runs. I hope this helps you move forward! Feel free to ask if you need more guidance.
Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | plugins/test/src/llm.tswooden-smartphone-55787
09/22/2025, 11:25 AMtall-airline-16756
09/22/2025, 11:26 AMgenerate_reply? Are you wondering how to guide the LLM to pick a specific tool, or are you looking to pass parameters to a tool while it’s running? I’m here to help you through this!wooden-smartphone-55787
09/22/2025, 11:26 AMtall-airline-16756
09/22/2025, 11:27 AMtool_choice parameter in generate_reply. This parameter lets you decide how tools are used when generating responses. Here’s a friendly breakdown of your options:
• 'auto': The model will thoughtfully decide when to use tools based on the context (this is the default setting).
• 'required': This option makes sure a tool is always used, no matter the context.
• 'none': If you prefer, you can turn off all tool usage completely.
• Specific tool: You can also specify a particular tool by name that you want to be used.
Here’s a simple example in Python to illustrate:
# Forcing the use of a specific tool
handle = agent_session.generate_reply(
user_input="What's the weather in Paris?",
tool_choice=llm.ToolChoice(type="function", name="get_weather")
)
# Disabling all tool usage
handle = agent_session.generate_reply(
user_input="Tell me about Paris",
tool_choice="none"
)
This parameter is really handy because it gives you the flexibility to control how tools are used, whether for a single call or across an entire session. If you have any questions or want to explore this further, I’m here to help!
Sources: Azure OpenAI LLM integration guide | LiveKit Docs | Groq LLM integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py | agents/src/voice/agent_activity.tswooden-smartphone-55787
09/22/2025, 11:27 AMtall-airline-16756
09/22/2025, 11:28 AMtool_choice parameter of generate_reply, here’s a simple way to do it:
Example:
# Force usage of a specific tool
handle = agent_session.generate_reply(
user_input="What's the weather in Paris?",
tool_choice=llm.ToolChoice(type="function", name="get_weather")
)
In this example, llm.ToolChoice lets you specify the type as function and the name of the tool you want to use. Just make sure the tool is registered and available in the agent’s tool list so it works smoothly.
If anything isn’t clear or you have more questions, please don’t hesitate to ask—I’m here to help!
Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...wooden-smartphone-55787
09/22/2025, 11:30 AMtall-airline-16756
09/22/2025, 11:31 AMgenerate_reply function can indeed invoke a tool without creating a reply. Let me walk you through two friendly ways to make this happen:
• Silent Tool Execution: If your tool doesn’t return any value (like None or simply has no return statement), it will run quietly without sending back a reply.
• Suppress Reply Programmatically: If your tool does return something but you’d prefer not to generate a reply, you can use the function_tools_executed event handler and call ev.cancel_tool_reply() like this:
@session.on("function_tools_executed")
def on_function_tools_executed(ev):
tools = (fnc.name for fnc in ev.function_calls)
if "your_tool_name" in tools:
ev.cancel_tool_reply()
This way, your tool runs smoothly without triggering any spoken or written response. I hope this helps clarify things for you!
Sources: livekit-agents/livekit/agents/voice/agent_activity.py