Skip to main content

ToolFunction

Types for defining tools, functions, and their execution configurations.

Overview

Tool types define how LLMs can call external functions, including schemas, parameters, HTTP configurations, and retry logic.

ToolFunction

Tool function definition with schema and optional HTTP request configuration.
interface ToolFunction {
  type: 'function';
  definition: ToolFunctionDefinition;
  request?: FunctionRequestHttp | null;
}
Example:
const tool: ToolFunction = {
  type: 'function',
  definition: {
    schema: {
      name: 'get_weather',
      description: 'Get current weather',
      parameters: {
        type: 'object',
        properties: {
          city: { type: 'string' }
        },
        required: ['city']
      }
    }
  }
};

ToolFunctionDefinition

See the dedicated ToolFunctionDefinition page for full documentation. Wrapper for a function schema within a tool definition.
interface ToolFunctionDefinition {
  schema: FunctionSchema;
}
Example:
const definition: ToolFunctionDefinition = {
  schema: {
    name: 'search_database',
    description: 'Search internal database',
    parameters: {
      type: 'object',
      properties: {
        query: { type: 'string', description: 'Search query' },
        limit: { type: 'number', default: 10 }
      },
      required: ['query']
    }
  }
};

FunctionSchema

See the dedicated FunctionSchema page for full documentation. Function/tool schema definition for LLM function calling.
interface FunctionSchema {
  name: string;                    // pattern: ^[a-zA-Z0-9_]{1,64}$
  description: string;             // max 4096 chars
  parameters: any;                 // JSON schema
  strict?: boolean | null;
}
Example:
const weatherFunction: FunctionSchema = {
  name: 'get_weather',
  description: 'Get current weather for a city',
  parameters: {
    type: 'object',
    properties: {
      city: {
        type: 'string',
        description: 'City name'
      },
      units: {
        type: 'string',
        enum: ['celsius', 'fahrenheit'],
        default: 'celsius',
        description: 'Temperature units'
      }
    },
    required: ['city']
  },
  strict: true
};
JSON:
{
  "name": "get_weather",
  "description": "Get weather for a city",
  "parameters": {
    "type": "object",
    "properties": {
      "city": { "type": "string" }
    },
    "required": ["city"]
  }
}

FunctionRequestHttp

HTTP request configuration for executing functions via REST API.
interface FunctionRequestHttp {
  type: 'http';
  method: 'get' | 'post';
  url: string;
  headers?: Record<string, string> | null;
  query?: Record<string, string> | null;
  body?: Record<string, any> | null;
  proxyUrl?: string | null;
  proxyHeaders?: Record<string, string> | null;
  retry?: FunctionRequestRetry | null;
}
Example:
const httpRequest: FunctionRequestHttp = {
  type: 'http',
  method: 'post',
  url: 'https://api.weather.com/v1/current',
  headers: {
    'Authorization': 'Bearer {{API_KEY}}',
    'Content-Type': 'application/json'
  },
  query: {
    'units': 'metric'
  },
  body: {
    location: '{{city}}'
  },
  retry: {
    maxAttempts: 3,
    initialDelay: 1000,
    exponentialFactor: 2
  }
};
JSON:
{
  "type": "http",
  "method": "post",
  "url": "https://api.example.com/function",
  "headers": {
    "Authorization": "Bearer token"
  },
  "retry": {
    "maxAttempts": 3,
    "initialDelay": 1000,
    "exponentialFactor": 2
  }
}

FunctionRequestRetry

Retry configuration with exponential backoff.
interface FunctionRequestRetry {
  maxAttempts: number;             // minimum: 1
  initialDelay: number;            // minimum: 1 (milliseconds)
  exponentialFactor: number;       // minimum: 1
}
Example:
const retryConfig: FunctionRequestRetry = {
  maxAttempts: 3,
  initialDelay: 1000,              // Start with 1 second
  exponentialFactor: 2             // Double each retry: 1s, 2s, 4s
};

// More aggressive
const aggressiveRetry: FunctionRequestRetry = {
  maxAttempts: 5,
  initialDelay: 500,
  exponentialFactor: 3             // 0.5s, 1.5s, 4.5s, 13.5s, 40.5s
};

Complete Example

import type {
  ToolFunction,
  ToolFunctionDefinition,
  FunctionSchema,
  FunctionRequestHttp,
  FunctionRequestRetry
} from '@adaline/api';

// Define retry configuration
const retry: FunctionRequestRetry = {
  maxAttempts: 3,
  initialDelay: 1000,
  exponentialFactor: 2
};

// Define HTTP request
const request: FunctionRequestHttp = {
  type: 'http',
  method: 'post',
  url: 'https://api.weather.com/current',
  headers: {
    'Authorization': 'Bearer sk_abc123',
    'Content-Type': 'application/json'
  },
  body: {
    city: '{{city}}',
    units: '{{units}}'
  },
  retry
};

// Define function schema
const schema: FunctionSchema = {
  name: 'get_weather',
  description: 'Get current weather for a city',
  parameters: {
    type: 'object',
    properties: {
      city: {
        type: 'string',
        description: 'City name'
      },
      units: {
        type: 'string',
        enum: ['celsius', 'fahrenheit'],
        default: 'celsius'
      }
    },
    required: ['city']
  }
};

// Complete tool definition
const tool: ToolFunction = {
  type: 'function',
  definition: { schema },
  request
};

// Use in deployment
const deployment = await adaline.getLatestDeployment({
  promptId: 'prompt_with_tools',
  deploymentEnvironmentId: 'production'
});

console.log(`Tools available: ${deployment.prompt.tools.length}`);
deployment.prompt.tools.forEach(t => {
  const fn = t.definition.schema;
  console.log(`  - ${fn.name}: ${fn.description}`);
});