Is there a way to annotate a function tool at runt...
# ask-ai
p
Is there a way to annotate a function tool at runtime? As in, I'd like to set its description based on state
t
Thanks for reaching out, Mario. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you asked! In LiveKit, function tools can indeed have their descriptions updated dynamically at runtime based on the current state. This is done by recreating or replacing the tools with updated descriptions instead of changing an existing tool's description directly. Here are some helpful ways to achieve this: • Create Tools Dynamically: You can use
function_tool()
as a function to generate tools whose descriptions depend on the state, like user roles or session information. • Update Tools at Runtime: The
agent.update_tools()
method allows you to swap out the active tools for new ones that reflect real-time changes in their descriptions. • Add Temporary Tools: By modifying the
tools
list dynamically inside the
llm_node()
method, you can add tools with context-specific descriptions just for a single LLM call. If you'd like to see these ideas in action, I highly recommend checking out the dynamic_tool_creation.py example. It walks through these patterns in detail and can be a great resource. Sources: Tool definition and use | LiveKit Docs | Tool definition and use | LiveKit Docs | livekit-agents/livekit/agents/llm/utils.py | Tool definition and use | LiveKit Docs | livekit-agents/livekit/agents/llm/utils.py