purple-barista-60143
11/14/2025, 7:44 AMtall-airline-16756
11/14/2025, 7:44 AMtall-airline-16756
11/14/2025, 7:46 AM@function_tool in Python or llm.tool() in TypeScript, and the system takes care of calling them when needed.
If you'd like to simulate a tool call yourself, you can use the generate_reply() method to create user input that naturally encourages the LLM to invoke the tool you're aiming for. Here’s how you can do it:
Python Example:
# Simulate user input to trigger a tool
await self.session.generate_reply(instructions="instructions:say goodbye to the user")
TypeScript Example:
// Simulate user input to trigger a tool
ctx.session.generateReply({
userInput: 'Tell user wait a moment for about 10 seconds'
});
Please feel free to reach out if you'd like me to walk you through this further or provide more examples—I'm here to help!
Sources: docs/index.yaml | examples/src/comprehensive_test.ts | livekit-agents/livekit/agents/voice/agent_activity.pypurple-barista-60143
11/14/2025, 7:48 AMtall-airline-16756
11/14/2025, 7:49 AMAgentTask are triggered by the LLM based on the chat context and tool descriptions. While you can't directly trigger a tool call programmatically from the llm_node, you do have some great ways to gently guide the LLM’s behavior conditionally. Here are a few helpful approaches:
1. Modify Chat Context: You can add dynamic context to the chat_ctx to nudge the LLM towards invoking a specific tool. For example:
async def llm_node(self, chat_ctx, tools, model_settings):
if some_runtime_condition():
chat_ctx.add_message(
role="system",
content="The user has requested data lookup; use the lookup_weather tool."
)
async for chunk in super().llm_node(chat_ctx, tools, model_settings):
yield chunk
1. Control Tool Usage: You can tweak the tool_choice parameter in model_settings to encourage tool usage when certain conditions are met. For example:
if should_force_lookup():
model_settings = model_settings.copy(update={"tool_choice": "required"})
1. Encapsulate Logic in Tools: Another handy way is to build conditional checks right inside the tool function itself, so it only runs when it really should.
@function_tool()
async def conditional_action(self, ctx: RunContext):
if not is_condition_met():
return "Condition not satisfied; no action taken."
return do_something()
If any of this feels unclear or if you have a particular scenario you’d like to walk through together, please don’t hesitate to reach out—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/generation.py | External data and RAG | LiveKit Docs | Tool definition and use | LiveKit docs | Pipeline nodes and hooks | LiveKit docs | Together AI LLM plugin guide | LiveKit Docspurple-barista-60143
11/14/2025, 7:54 AMtall-airline-16756
11/14/2025, 7:55 AM_pipeline_reply_task.
2. LLM-Driven Tool Calls: The tool is triggered only when the LLM generates a function call in its response. So, simply adding a developer message won’t create that output.
3. Explicit Workflow Progression: To encourage the agent to consider using a tool after adding a message, you’ll want to explicitly call a reply-generation method such as generate_reply(), or make sure a previous tool execution has set replyRequired = true.
For your situation, a good approach is to call generate_reply() right after adding your developer message. This will prompt the LLM to process the updated context and decide if tool usage is needed. If you’d like, I’m here to guide you through this step or answer any other questions you have!
Sources: External data and RAG | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | agents/src/voice/agent_activity.tspurple-barista-60143
11/14/2025, 7:56 AMtall-airline-16756
11/14/2025, 7:56 AMgenerate_reply inside the llm_node in LiveKit. The llm_node handles inference and response generation, and generate_reply is built to create dynamic responses based on instructions or user input. Since generate_reply is supported in tool execution, which is part of the LLM inference flow, it fits perfectly within or alongside the llm_node logic.
If you'd like, I’m here to help with any further clarification or examples you might need!
Sources: Pipeline nodes and hooks | LiveKit docs | Agent speech and audio | LiveKit docs | Tool definition and use | LiveKit docs | livekit-agents/livekit/agents/voice/generation.pypurple-barista-60143
11/14/2025, 8:03 AMtool_choice parameter in model_settings to encourage tool usage when certain conditions are met. For example:
``````
how does this work? how is the tool call guarenteedtall-airline-16756
11/14/2025, 8:05 AMtool_choice parameter in model_settings a bit better! When you set it to "required", it really encourages the LLM to prioritize using tools by making sure the output follows the tool call format, rather than just plain text. That said, it’s important to know that this doesn’t always guarantee a tool will be called every single time. Here’s a little breakdown to clarify:
1. Tool Usage Enforcement: Setting tool_choice to "required" helps the system steer the model away from non-tool responses, so tools get the spotlight.
2. Conditions for Tool Calls: Tools need to be available, and the user’s request should logically call for their use. If there aren’t any registered tools or the request doesn’t really need them, the model might not use tools.
3. Provider-Specific Implementation: Different LLM providers, like AWS Bedrock and Google Gemini, handle this setting in their own way, mapping "required" to configurations that encourage tool calls.
I hope this helps clear things up! If you want me to walk you through some examples or have any other questions, just let me know—I’m here to help!
Sources: Azure OpenAI LLM plugin guide | LiveKit docs | xAI LLM plugin guide | LiveKit Docs | Perplexity LLM plugin guide | LiveKit Docs | Telnyx LLM plugin guide | LiveKit Docs | common/chat.cpppurple-barista-60143
11/14/2025, 8:08 AMtall-airline-16756
11/14/2025, 8:08 AMchat() stream to catch tool calls as they happen. Here’s a simple example:
async for chunk in llm.chat(chat_ctx=chat_ctx, tools=tools):
if chunk.delta and chunk.delta.tool_calls:
for tool_call in chunk.delta.tool_calls:
print(f"Tool call detected: {tool_call.name} with args: {tool_call.arguments}")
1. Override `llm_node`: Another approach is to customize the llm_node method so you can spot and respond to tool calls during inference:
async def llm_node(self, chat_ctx, tools, model_settings):
async for chunk in super().llm_node(chat_ctx, tools, model_settings):
if chunk.delta and chunk.delta.tool_calls:
print("Tool call detected")
yield chunk
1. Inspect Execution Events: After running your session, you can check the RunResult events to find any tool calls made:
result = await session.run(user_input="What's the weather in Tokyo?")
fnc_call = result.expect.next_event().is_function_call(name="lookup_weather", arguments={"location": "Tokyo"})
If you’d like me to walk you through any of these steps or provide more examples, just let me know—I’m here to help!
Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | agent.py | agents/src/inference/llm.ts