adorable-petabyte-73906
11/10/2025, 8:19 AMtall-airline-16756
11/10/2025, 8:19 AMtall-airline-16756
11/10/2025, 8:19 AMadorable-petabyte-73906
11/10/2025, 8:22 AMtall-airline-16756
11/10/2025, 8:23 AMagent.updateTools() to adjust the tools available while the conversation is happening. This flexibility helps your agent respond better as the dialogue evolves.
3. Use Agent Handoffs:
• For more complex scenarios, consider passing control between specialized agents through handoffs. Each agent can have its own unique tools and instructions, which helps maintain precise control over different parts of the conversation.
4. Update Instructions and Context:
• Keep your agent’s system prompt fresh by dynamically updating it with update_instructions(), or inject new context using updateChatCtx(). This ensures your agent always works with the latest information.
5. Create Tools Programmatically:
• Feel free to generate tools on the fly during runtime to manage personalized or conditional workflows. This adds a wonderful layer of flexibility to your conversation design.
By combining these approaches, you can craft adaptive agents that evolve their prompts and tools in real time, leading to natural and effective conversational control. If you'd like, I’m here to help with more details or examples to make this easier for you!
Sources: examples/src/basic_tool_call_agent.ts | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Tool definition and use | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docsadorable-petabyte-73906
11/10/2025, 10:25 AMtall-airline-16756
11/10/2025, 10:25 AMupdate_tools() to Modify Tools:
• If you want to replace all current tools with a new set, simply use await agent.update_tools(new_tools).
• If you'd like to keep your existing tools and just add new ones, you can append them like this: await agent.update_tools(agent.tools + [new_tool]).
• To remove a specific tool, you can filter it out using: await agent.update_tools([tool for tool in agent.tools if tool.name != "tool_to_remove"]).
2. Create Tools Dynamically:
• Feel free to generate tools on the fly using function_tool, especially if you need personalized or conditional workflows. For example, you might create tools tailored to specific user fields or tasks as needed.
3. Control Prompt Updates:
• While update_tools() changes the available functions and thus affects prompts indirectly, you can also update the system prompt directly with agent.update_instructions(), like so: await agent.update_instructions("You are now in troubleshooting mode.").
4. Best Practices:
• Remember to always include agent.tools when updating tools to keep your existing ones intact.
• Try to minimize tool changes if you’re using RealtimeModel agents, as frequent updates might cause session restarts.
• Make sure to validate any dynamically created tools to confirm they meet the required schema.
By combining these approaches, you can flexibly adapt your agent’s behavior during live sessions. If you'd like, I’m here to help with more examples or any questions you have!
Sources: Tool definition and use | LiveKit docs | Tool definition and use | LiveKit docs | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/agent_activity.py | docs/index.yamladorable-petabyte-73906
11/10/2025, 10:27 AMtall-airline-16756
11/10/2025, 10:27 AMupdate_tools() method to control which tools are available during runtime. Let’s walk through some helpful ways to do this:
1. Replace Tools Dynamically:
• You can replace all tools with a restricted subset by using: await agent.update_tools([allowed_tool_1, allowed_tool_2]).
• If you want to keep the existing tools and just add new ones, try: await agent.update_tools(agent.tools + [new_tool]).
• To remove specific tools, you might do: await agent.update_tools([tool for tool in agent.tools if tool.name != "forbidden_tool"]).
2. Context-Based Restrictions:
• You can enable or disable tools based on things like user roles or session state. For instance, allowing only safe tools for guest users while giving admins full access is a great approach.
3. Global Tool Disabling:
• If you ever need to disable all tools globally, you can use the tool_choice parameter like this: llm = openai.LLM(model="gpt-4o-mini", tool_choice="none").
Best Practices:
• Remember to always include agent.tools when updating tools to keep the existing ones intact.
• Make sure to validate any dynamically created tools so they meet the schema requirements.
• Combining update_tools() with runtime logic is a smart way to keep tool access secure and context-aware.
If you’d like, I’m here to provide more examples or help you with implementation—just let me know!
Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real... | Tool definition and use | LiveKit docs | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Azure OpenAI LLM plugin guide | LiveKit docs | Anthropic Claude LLM plugin guide | LiveKit docsadorable-petabyte-73906
11/10/2025, 12:33 PMtall-airline-16756
11/10/2025, 12:34 PMupdate_instructions() and update_tools() methods. Here's a simple way to implement it:
1. Update the System Prompt:
• You can use update_instructions() to change the agent's system prompt on the fly, like this: await agent.update_instructions("New system prompt").
2. Update Tools Dynamically:
• To add or replace tools dynamically, update_tools() is your friend. For example, to add a new tool while keeping the existing ones intact, you can do: await agent.update_tools(agent.tools + [new_tool]).
3. Combine Both in a Single Tool:
from livekit.agents import function_tool
class DynamicAgent(Agent):
@function_tool()
async def update_agent_config(self, new_instructions: str, add_tool: bool = False):
# Update system instructions
await self._activity.update_instructions(new_instructions)
if add_tool:
async def _new_behavior():
return "This is a dynamically added tool."
new_tool = function_tool(
_new_behavior,
name="dynamic_action",
description="A tool added at runtime"
)
await self.update_tools(self.tools + [new_tool])
return "Agent configuration updated."
Best Practices:
• Remember to always include agent.tools when updating tools to keep the existing ones.
• It's a good idea to validate any dynamically created tools to make sure they meet schema requirements.
• Also, be mindful that updating tools or prompts might sometimes trigger session restarts, so handling those gracefully is important.
This method lets you build agents that can adapt and evolve while they're running. If you'd like, I'm here to help with more examples or any questions you have!
Sources: Tool definition and use | LiveKit docs | Tool definition and use | LiveKit docs | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/agent_activity.py