purple-barista-60143
08/28/2025, 9:33 AMtall-airline-16756
08/28/2025, 9:33 AMtall-airline-16756
08/28/2025, 9:34 AMllm_node function in LiveKit. The LLM decides on its own when to call a tool, based on the input, chat context, and the tools available.
That said, you can still guide those tool calls by:
• Choosing which tools you pass into the llm_node function.
• Using the tool_choice parameter in ModelSettings to require or specify a particular tool.
• Setting up the agent's instructions or chat context in a way that encourages the LLM to pick the tool you want.
If you have a specific scenario in mind or want a hand figuring this out, just let me know—I’m here to help!
Sources: Pipeline nodes and hooks | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...purple-barista-60143
08/28/2025, 9:35 AMtall-airline-16756
08/28/2025, 9:36 AM@function_tool
async def end_session(self):
"""Ends the session with a goodbye note."""
await self.session.say("Goodbye!")
await self.session.aclose()
2. Generating a Goodbye Message:
@function_tool
async def close_session(self):
"""Ends the session with an LLM-generated goodbye."""
await self.session.generate_reply(instructions="say goodbye to the user")
await self.session.aclose()
Both ways make sure your session closes smoothly after sharing that warm farewell. If you want a hand setting this up or have any questions, just let me know—I’m here to help!
Sources: flows/multi_stage_flow.py | tests/test_agent_session.py | Agents telephony integration | LiveKit Docspurple-barista-60143
08/28/2025, 9:37 AMtall-airline-16756
08/28/2025, 9:38 AMllm_node implementation, you can simply yield a ChatChunk that contains the tool call. Here’s a quick example:
async def llm_node(self, chat_ctx: ChatContext, tools: list[FunctionTool], model_settings: ModelSettings):\n # Check for a specific condition to end the session\n if some_condition_to_end_session():\n yield ChatChunk(\n delta=llm.ChoiceDelta(\n tool_calls=[\n llm.ToolCall(\n call_id=\"end_session_call\",\n type=\"function\",\n name=\"end_session\",\n arguments={}\n )\n ]\n )\n )\n return # Skip further processing\n\n # Default behavior\n async for chunk in Agent.default.llm_node(self, chat_ctx, tools, model_settings):\n yield chunk
Just swap out some_condition_to_end_session() with whatever logic makes sense for when you want to end the session. This way, you’re making sure the tool call happens exactly when you want it to.
If you have any questions or want me to walk you through it, just let me know—I’m here to help!purple-barista-60143
08/28/2025, 9:40 AMtall-airline-16756
08/28/2025, 9:41 AMcall_id in a tool call as a special name tag that helps match your request with its result. It can be randomly created, but it does need to fit certain format rules depending on the AI model you’re working with. For example:
• Some models use alphanumeric strings of a set length (like 9 characters).
• Others might expect just integer strings.
LiveKit usually relies on handy generators like shortuuid to whip up random values that fit the bill. Just make sure your call_id is unique and follows the format your setup requires—this way, everything runs smoothly!
Sources: models/templates/CohereForAI-c4ai-command-r7b-12-2024-tool_use.jinja | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...