Primitives.org.ai

Verb

Actions and operations in your domain

Verb

Verbs represent actions and operations that can be performed on Things in your domain.

Context Defines Meaning

Every Verb exists within a Domain namespace - and that namespace IS the $context. The verb "approve" means something different at a bank vs. a publishing company:

// In bank.do namespace/context
const Approve = Verb('approve', {
  object: 'LoanApplication',
  effect: (app) => ({ ...app, status: 'funded' }),
})

// In publisher.do namespace/context
const Approve = Verb('approve', {
  object: 'Manuscript',
  effect: (doc) => ({ ...doc, status: 'ready-for-print' }),
})

The namespace provides context for AI to understand not just WHAT action to take, but HOW it should behave in YOUR domain.

Overview

A Verb defines an operation with its parameters, preconditions, and effects. Verbs create Actions when applied to specific things, and emit Events when executed.

import { Verb } from 'ai-database'

// Define a verb
const Approve = Verb('approve', {
  subject: 'User',
  object: 'Document',
  preconditions: (user, doc) => doc.status === 'pending',
  effect: (user, doc) => ({ ...doc, status: 'approved', approvedBy: user.id }),
})

// Use the verb
await Approve(currentUser, document)

Defining Verbs

Verbs capture the semantics of domain operations:

import { Verb } from 'ai-database'

const Ship = Verb('ship', {
  subject: 'Warehouse',
  object: 'Order',
  preconditions: (warehouse, order) =>
    order.status === 'paid' && warehouse.hasInventory(order.items),
  effect: (warehouse, order) => ({
    ...order,
    status: 'shipped',
    shippedFrom: warehouse.id,
    shippedAt: new Date(),
  }),
})

Verb Conjugation

Verbs automatically conjugate for different contexts:

const verb = Verb('create')

verb.infinitive  // "create"
verb.pastTense   // "created"
verb.present     // "creates"
verb.gerund      // "creating"

Events from Verbs

When a verb executes, it emits an event:

// Executing a verb
const result = await Ship(warehouse, order)

// Emits event:
// {
//   type: 'Order.shipped',
//   subject: warehouse,
//   object: order,
//   timestamp: Date,
//   result: { ...updatedOrder }
// }

Built-in Verbs

Common CRUD verbs are built-in:

import { create, read, update, delete as remove, list } from 'ai-database'

await create(Customer, { name: 'Acme' })
await read(Customer, 'cust_123')
await update(Customer, 'cust_123', { tier: 'pro' })
await remove(Customer, 'cust_123')
await list(Customer, { tier: 'pro' })

See Also

  • Domain - The namespace that IS the context
  • Noun - Types that verbs operate on
  • Thing - Instances that verbs act upon
  • Action - Bound verb invocations
  • Event - Records of verb execution
Was this page helpful?

On this page