able-airline-55422
12/15/2025, 5:08 AMtall-airline-16756
12/15/2025, 5:08 AMtall-airline-16756
12/15/2025, 5:09 AMparameters: z.object({
location: z.string().describe('The location to get weather for'),
unit: z.enum(['celsius','fahrenheit']).optional(), // optional parameter
})
1. Provide a default inside execute so your code has a fallback when the parameter is omitted:
execute: async ({ location, unit = 'celsius' }) => {
// unit will be 'celsius' if omitted
}
That’s all — the parameter can be omitted when invoking the tool, and your execute handler receives either the provided value or the default. Would you like an example for a different parameter type or validation rule?
Sources: Agents (Node.js) | livekit/livekit_composite | DeepWikiable-airline-55422
12/15/2025, 5:09 AMtall-airline-16756
12/15/2025, 5:10 AM@function_tool decorator will treat parameters with defaults as optional.
Example:
from livekit.agents import function_tool
@function_tool()
async def get_weather(
location: str, # required
unit: str = "celsius" # optional with default
) -> str:
return f"Weather in {location}: 20 degrees {unit}"
Do you want an example that validates allowed values for unit (e.g., only "celsius" or "fahrenheit") or one that uses Optional[...] typing?
Sources: Tool definition and use | LiveKit docs