Primitives.org.ai

define

The foundation for creating AI functions

The foundation of ai-functions. Every function is built on define.

Import

import { define } from 'ai-functions'

Syntax

define(name: string, schema: Schema)
define(name: string, options: DefineOptions)

Basic Definition

const planTrip = define('planTrip', {
  destination: 'Travel destination',
  budget: 'Budget in USD (number)',
})

await planTrip({ destination: 'Tokyo', budget: 5000 })

With Output Schema

const planTrip = define('planTrip', {
  args: {
    destination: 'Travel destination',
    budget: 'Budget in USD (number)',
  },
  returns: {
    itinerary: [{
      day: 'Day number (number)',
      activities: ['List of activities'],
      estimatedCost: 'Cost for the day (number)',
    }],
    totalCost: 'Total trip cost (number)',
    tips: ['Travel tips'],
  },
})

With Options

const analyze = define('analyzeCompetitors', {
  args: { company: 'Company name', market: 'Market segment' },
  returns: { strengths: ['...'], weaknesses: ['...'] },
  model: 'claude-opus-4-5',
  temperature: 0.7,
  system: 'You are a business analyst.',
})

Built-in Functions

The built-in functions are all created with define:

// Conceptually:
is = define('is', { returns: 'boolean' })
list = define('list', { returns: ['items'] })
code = define('code', { returns: 'code string' })
Was this page helpful?

On this page