adorable-engine-68435
06/05/2025, 1:14 PMtall-airline-16756
06/05/2025, 1:14 PMtall-airline-16756
06/05/2025, 1:15 PMparameters property in the Tool interface. This property allows you to define the structure of your inputs, including nested properties for complex parameters. Here's an example:
parameters: {
properties: {
paramName1: {
type: "string", // or any other type
description: "Description of parameter"
},
complexParam: {
type: "object",
properties: {
nestedParam1: {
type: "string",
description: "Description of nested parameter"
},
nestedParam2: {
type: "number",
description: "Another nested parameter"
}
}
}
},
required: ["paramName1"], // List required parameters
type: "object"
}
Each parameter in the properties object can have its own set of properties to define its structure and validation rules. Ensure that the JSON schema is correctly formatted to avoid errors.
Sources: Tool | LiveKit Agentsadorable-engine-68435
06/05/2025, 1:19 PMtall-airline-16756
06/05/2025, 1:19 PMfrom enum import Enum
from typing import Annotated, Literal
from pydantic import Field
from livekit.agents import Agent, function_tool, RunContext
class RoomName(str, Enum):
BEDROOM = "bedroom"
LIVING_ROOM = "living room"
KITCHEN = "kitchen"
BATHROOM = "bathroom"
OFFICE = "office"
GARAGE = "garage"
class MyAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="You are a helpful assistant.",
)
@function_tool()
async def get_weather(self, context: RunContext, location: str) -> str:
"""Look up weather information for a given location.
Args:
location: The location to get the weather for
"""
# You could make an API call here
return f"The weather in {location} is sunny today."
@function_tool()
async def toggle_light(self, context: RunContext, room: RoomName, switch_to: Literal["on", "off"]) -> str:
"""Called when the user asks to turn on or off the light.
Args:
room: The room to turn the light in
switch_to: The state to turn the light to
"""
return f"The light in the {room.value} is now {switch_to}."
This example demonstrates:
• Using the @function_tool() decorator to define tools
• Including the special context: RunContext parameter for accessing session data
• Using Enum types for structured parameter options (RoomName)
• Using Literal types to restrict parameter values
• Providing detailed docstrings that describe the tool and its parameters
• Returning structured data from the tool function Sources: Tool definition and use | LiveKit Docs | Tree View: | dse-workbenchadorable-engine-68435
06/05/2025, 1:22 PMtall-airline-16756
06/05/2025, 1:22 PM