fierce-jordan-44682
10/26/2025, 2:25 PMtall-airline-16756
10/26/2025, 2:26 PMtall-airline-16756
10/26/2025, 2:26 PMfunction_tool in LiveKit! You can achieve this by using the function_tool function (not as a decorator) and providing the description parameter dynamically at runtime. Here are some friendly ways to do this:
• Create Tools Dynamically: You can use function_tool() as a function to pass a description that’s generated on the fly. Here’s a simple example:
function_tool(
self._set_profile_field_func_for("phone"),
name="set_phone_number",
description="Call this function when user has provided their phone number."
)
• Update Agent Tools at Runtime: If you want to modify the agent’s tools dynamically, you can use agent.update_tools(). Check out this example:
await agent.update_tools(
agent.tools + [
function_tool(
_random_number,
name="random_number",
description="Get a random number between 0 and 100"
)
]
)
• Modify Tools During LLM Node Execution: Another approach is to adjust the tools list dynamically inside the llm_node method. Here’s how you might do it:
async def llm_node(self, chat_ctx, tools, model_settings):
tools.append(
function_tool(
_get_weather,
name="get_weather",
description="Get the weather in a specific location"
)
)
return Agent.default.llm_node(self, chat_ctx, tools, model_settings)
If any part of this feels unclear or if you’d like me to walk you through it step-by-step, please don’t hesitate to ask. I’m here to help!
Sources: livekit-agents/livekit/agents/llm/tool_context.py | basics/say_in_voice.py | Docs::Agents | Tool definition and use | LiveKit Docsfierce-jordan-44682
10/26/2025, 2:27 PMtall-airline-16756
10/26/2025, 2:28 PM@function_tool decorator, it captures the function’s description from the __doc__ attribute right at the moment the decorator is applied. So, if you change the __doc__ attribute afterward, the tool’s description won’t update dynamically.
To help you achieve dynamic descriptions, here are a few friendly approaches you might find useful:
• Set __doc__ Before Decoration: You can set the __doc__ attribute programmatically before applying the decorator. This way, the description is ready when the decorator runs.
tool_impl.__doc__ = "Dynamic description here"
return function_tool()(tool_impl)
• Use `agent.update_tools()`: If you want to update descriptions at runtime, you can replace tools using this method.
await agent.update_tools(
agent.tools + [
function_tool(
_random_number,
name="random_number",
description="Updated description"
)
]
)
• Create Tools Programmatically: Another way is to use function_tool as a function, setting descriptions dynamically when creating the tool.
function_tool(
_get_weather,
name="get_weather",
description="Dynamic description"
)
If any part of this feels unclear or if you’d like a hand implementing these steps, please don’t hesitate to reach out—I’m here to help!
Sources: Tool definition and use | LiveKit Docs | Docs::Agents | examples/voice_agents/README.md | mcp_client/agent_tools.py | docs/index.yamlfierce-jordan-44682
10/26/2025, 2:29 PMfunction_tool(
_get_weather,
name="get_weather",
description="Dynamic description"
)
at? can I put it within init of agent?tall-airline-16756
10/26/2025, 2:30 PMfunction_tool within the __init__ method of an Agent to dynamically define tools. Here’s a friendly walkthrough:
• Programmatically Create Tools: You can use function_tool as a function to define tools on the fly and add them to your agent's toolset. Here's an example to illustrate:
from livekit.agents.llm import function_tool
class DynamicToolAgent(Agent):
def __init__(self) -> None:
super().__init__(instructions="You can perform dynamic actions.")
# Define a function dynamically
async def dynamic_action(location: str) -> str:
return f"Performing action in {location}"
# Decorate it as a tool
tool = function_tool(
name="dynamic_action",
description="Perform an action in a given location"
)(dynamic_action)
# Add to agent's tools
self._tools.append(tool)
• Automatic Registration: Another friendly tip: if you use @function_tool as a decorator on your class methods, they’ll be automatically registered as tools when your agent initializes. It’s a neat way to keep things organized!
If anything feels unclear or you’d like a bit more help with the implementation, please don’t hesitate to ask. I’m here to help you every step of the way!
Sources: Docs::Agents | examples/voice_agents/raw_function_description.py | mcp_client/agent_tools.pyfierce-jordan-44682
10/26/2025, 2:41 PMtall-airline-16756
10/26/2025, 2:41 PM@function_tool to make it accessible as a tool. Here’s a friendly example to guide you:
from livekit.agents import function_tool, Agent, RunContext
class MyAgent(Agent):
@function_tool()
async def lookup_weather(
self,
context: RunContext,
location: str,
) -> dict[str, Any]:
"""
Look up weather information for a given location.
Args:
location: The location to look up weather information for.
"""
return {"weather": "sunny", "temperature_f": 70}
In this example, the lookup_weather method is thoughtfully defined within the class and decorated with @function_tool. This means it will be automatically registered as a tool when your agent is initialized.
If you have any questions or need a bit more help, please don’t hesitate to ask—I’m here to support you!
Sources: Docs::Agents | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | Tool definition and use | LiveKit Docs