How to define integer value arguments in @function...
# ask-ai
l
How to define integer value arguments in @function_tools and get the integer value from AI.
t
Thanks for reaching out, Rajadurai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to define integer arguments in @function_tool and receive integer values from the AI. Do you want the Python or Node.js example? If Python, use a typed parameter (
int
) in the function signature:
Copy code
from livekit.agents import function_tool

@function_tool()
async def set_timer(self, duration_seconds: int):
    """Set a timer for a specified number of seconds."""
    print(f"Timer set for {duration_seconds} seconds")
    return f"Timer set for {duration_seconds} seconds"
If Node.js, use Zod to declare an integer parameter:
Copy code
import { llm } from '@livekit/agents';
import { z } from 'zod';

const setTimer = llm.tool({
  description: 'Set a timer for a specified number of seconds.',
  parameters: z.object({
    durationSeconds: z.number().int().describe('The number of seconds for the timer'),
  }),
  execute: async ({ durationSeconds }) => {
    console.log(`Timer set for ${durationSeconds} seconds`);
    return `Timer set for ${durationSeconds} seconds`;
  },
});
The LLM extracts and converts the integer from user input automatically and passes it to your function. Do you need examples showing validation (min/max) or handling non-integer user input? Sources: Tool definition and use | LiveKit docs