FunctionDeclaration defines the OpenAPI-style schema for a tool’s parameters. It tells the LLM what arguments the tool accepts, their types, descriptions, and which are required.This structure is based on the Google Generative AI SDK and is compatible with multiple LLM providers.
The name of the function/tool. Must match the tool’s name property.Should contain only alphanumeric characters and underscores.Example: http_request, calculate_sum, search_database
A clear description of what the function does. This helps the LLM understand when and how to use the tool.Should be descriptive and explain the tool’s purpose and behavior.Example: Makes HTTP requests to external APIs and returns the response
import { buildFunctionDeclaration } from '@iqai/adk';/** * Calculates the sum of two numbers * @param a First number * @param b Second number * @returns The sum of a and b */function add(a: number, b: number): number { return a + b;}const declaration = buildFunctionDeclaration(add, { name: 'add', description: 'Adds two numbers together'});// Result:// {// name: 'add',// description: 'Adds two numbers together',// parameters: {// type: Type.OBJECT,// properties: {// a: { type: 'number', description: 'First number' },// b: { type: 'number', description: 'Second number' }// },// required: ['a', 'b']// }// }
import { createTool } from '@iqai/adk';import { z } from 'zod';const calculatorTool = createTool({ name: 'calculator', description: 'Performs arithmetic operations', schema: z.object({ operation: z.enum(['add', 'subtract', 'multiply', 'divide']) .describe('The arithmetic operation to perform'), a: z.number().describe('First operand'), b: z.number().describe('Second operand') }), fn: ({ operation, a, b }) => { switch (operation) { case 'add': return { result: a + b }; case 'subtract': return { result: a - b }; case 'multiply': return { result: a * b }; case 'divide': return { result: a / b }; } }});// Function declaration is generated automatically from Zod schemaconst declaration = calculatorTool.getDeclaration();