proud-lawyer-39815
09/18/2025, 10:12 PMtall-airline-16756
09/18/2025, 10:12 PMtall-airline-16756
09/18/2025, 10:13 PMfunction_tool. You’ll define a callable function and provide it with a name, description, and, if needed, a raw schema for more complex parameter setups. Here’s a simple step-by-step guide to help you along:
1. First, define the function you'd like to use as the tool handler. For example:
async def my_function(raw_arguments: dict[str, object], context: RunContext):
# Your function logic here
return "Function executed successfully!"
1. Next, wrap your function with function_tool, and don't forget to add some metadata like the name and description to keep things clear:
tool = function_tool(my_function, name="my_tool", description="This is a sample tool.")
1. If you want to create dynamic tools, you can define an inner function and make use of raw_schema for extra flexibility. Here's an example:
def create_dynamic_tool(tool_name: str):
schema = {
"type": "function",
"name": tool_name,
"description": f"Dynamic tool: {tool_name}",
"parameters": {
"type": "object",
"properties": {
"param": {"type": "string", "description": "A parameter"}
},
"required": ["param"]
}
}
async def handler(raw_arguments: dict[str, object], context: RunContext):
param = raw_arguments["param"]
return f"Handled parameter: {param}"
return function_tool(handler, raw_schema=schema)
You can add these tools when initializing your agent, or update them dynamically anytime using agent.update_tools().
If anything feels unclear or you’d like more examples, please don’t hesitate to ask—I’m here to help!
Sources: Tool definition and use | LiveKit Docs | Tool definition and use | LiveKit Docs | README.md | rpc/rpc_agent.pyproud-lawyer-39815
09/18/2025, 10:14 PMproud-lawyer-39815
09/18/2025, 10:14 PMtall-airline-16756
09/18/2025, 10:15 PM