.do
Execution

functions

Serverless function execution with automatic scaling and deployment

functions

The foundational primitive for all executable code - serverless functions with 4 types (Code, Generative, Agentic, Human) that form the basis of workflows, agents, and business logic.

Overview

The functions primitive is the foundation of all executable code in the .do platform. Every operation—from simple HTTP handlers to complex AI-powered workflows—is ultimately a function. Functions are defined using semantic patterns based on parts of speech and GraphDL, enabling intuitive, self-documenting code.

Key Insight: A Workflow IS a CodeFunction with durable execution and triggers (every for time-based, on for event-based).

The 4 Function Types

Functions in .do follow 4 fundamental types based on their execution model:

1. Code Functions (Traditional Serverless)

Pure code execution - the traditional serverless function model.

import { fn } from 'sdk.do'

// Code function - pure code execution
const processOrder = fn('process-order', async ({ orderId }) => {
  const order = await db.get('orders', orderId)
  await validateOrder(order)
  await chargePayment(order)
  return { success: true }
})

2. Generative Functions (AI-Powered)

Functions that use AI models to generate outputs. Maps to the ai SDK object (one of 8 core).

import { ai } from 'sdk.do'

// Generative function - AI generates output
const generateStrategy = async ({ company, market }) => {
  return await ai.generate({
    model: 'gpt-5',
    prompt: `Generate a market strategy for ${company} in ${market}`,
  })
}

// AI helper functions (also generative)
const items = await ai.list('Generate a list of competitive advantages')
const isValid = await ai.is('this is a valid business model', businessPlan)
const areValid = await ai.are('these are valid markets', markets)

3. Agentic Functions (Autonomous Agents)

Functions that exhibit agency - autonomous decision-making and multi-step execution. See agents.

import { agent } from 'sdk.do'

// Agentic function - autonomous agent
const qualifyLead = await agent.create({
  name: 'lead-qualifier',
  role: 'Sales Development Representative',
  task: async ({ lead }) => {
    // Agent autonomously researches, scores, and qualifies
    const research = await agent.research(lead.company)
    const score = await agent.score(lead, research)
    const decision = await agent.decide('qualify', { lead, score })
    return decision
  },
})

4. Human Functions (Human-in-the-Loop)

Functions executed by humans - approval flows, reviews, decisions. Maps to the user SDK object (one of 8 core).

import { user } from 'sdk.do'

// Human function - requires human execution
const approveContract = async ({ contractId }) => {
  // Route to appropriate human
  const approver = await user.getApprover('contracts')

  // Wait for human decision
  const approval = await user.requestApproval({
    userId: approver.id,
    type: 'contract-approval',
    data: { contractId },
    timeout: { hours: 48 },
  })

  return approval
}

Semantic Patterns: Parts of Speech

Functions in .do use GraphDL semantic patterns based on parts of speech, making code self-documenting and intuitive:

Noun Pattern - Entities ($.Subject)

// Nouns represent entities
const order = await $.Order.get('order-123')
const user = await $.User.get('user-456')
const product = await $.Product.get('prod-789')

Verb Pattern - Actions ($.Subject.predicate)

// Verbs represent actions on entities
await $.Order.create({ items, total })
await $.User.update.profile({ userId, name })
await $.Payment.process({ orderId, amount })

View Pattern - Queries ($.Subject.predicate.Object)

// Views represent relationships and queries
const orders = await $.User.has.Orders({ userId })
const items = await $.Order.contains.Items({ orderId })
const reviews = await $.Product.has.Reviews({ productId })

Agent Pattern - Autonomous Functions ($.Agent.verb.Object)

// Agents perform autonomous actions
await $.Agent.qualify.Lead({ leadId })
await $.Agent.generate.Report({ reportType })
await $.Agent.analyze.Market({ marketId })

Semantic Triple: $.Subject.predicate.Object

Functions use RDF-style semantic triples with optional prepositional phrases:

// Basic triple: $.Subject.predicate.Object
await $.User.assign.Role({ userId, roleId })
await $.Order.fulfill.Payment({ orderId })
await $.Team.add.Member({ teamId, userId })

// With prepositional phrases: $.Subject.predicate.Object.in.Thing
await $.User.assign.Role.in.Organization({ userId, roleId, orgId })
await $.Task.assign.User.in.Project({ taskId, userId, projectId })
await $.Product.add.Category.in.Catalog({ productId, categoryId, catalogId })

// Chained relationships
const managers = await $.Organization.has.Teams.with.Members.where.role.equals('manager')

SDK Object Mapping

Functions integrate with all 8 core SDK objects depending on their type:

import { fn, ai, user, db, on, send, every, api, decide } from 'sdk.do'

// Code function - pure execution
const process = fn('process', async (data) => {
  /* ... */
})

// AI function - ai SDK object (1 of 8 core)
const generate = async (prompt) => await ai.generate({ model: 'gpt-5', prompt })

// Human function - user SDK object (1 of 8 core)
const approve = async (item) => await user.requestApproval({ item })

// Database function - db SDK object (1 of 8 core)
const fetch = async (id) => await db.get('items', id)

// Event function - on SDK object (1 of 8 core)
on('item.created', async ({ item }) => {
  /* handle event */
})

// Analytics function - send SDK object (1 of 8 core)
const track = async (event) => await send('analytics.track', event)

// Scheduled function - every SDK object (1 of 8 core)
every('daily at 9am', async () => {
  /* run daily */
})

// Integration function - api SDK object (1 of 8 core)
const integrate = async (action) => await api.action('github.create_issue', action)

// Experiment function - decide SDK object (1 of 8 core)
const test = async (user) => await decide.get('button-color-test', { userId: user.id })

Workflows as Functions

A Workflow IS a CodeFunction with two key additions:

  1. Triggers - every (time-based) or on (event-based)
  2. Durable Execution - Automatic state persistence and retry logic
import { workflow, every, on } from 'sdk.do'

// Workflow = Code Function + Triggers + Durable Execution
workflow('process-order', async ({ order }) => {
  // This is a code function with durable execution
  await validateOrder(order)
  await chargePayment(order)
  await createShipment(order)
})

// Time-based trigger (every)
every('daily at 9am', async () => {
  await workflow('daily-report', async () => {
    // Durable execution with automatic retries
    const data = await gatherData()
    await generateReport(data)
  })
})

// Event-based trigger (on)
on('order.created', async ({ order }) => {
  await workflow('fulfill-order', async () => {
    // State persisted automatically
    await processOrder(order)
  })
})

Quick Example

import { fn, $, ai, user } from 'sdk.do'

// Example combining all 4 function types

// 1. Code function
const validateOrder = fn('validate', async ({ order }) => {
  if (order.total < 0) throw new Error('Invalid total')
  return { valid: true }
})

// 2. Generative function (AI)
const generateDescription = async ({ product }) => {
  return await ai.generate({
    model: 'gpt-5',
    prompt: `Write a compelling product description for ${product.name}`,
  })
}

// 3. Agentic function (Agent)
const qualifyLead = async ({ lead }) => {
  return await $.Agent.qualify.Lead({
    leadId: lead.id,
    autonomousResearch: true,
  })
}

// 4. Human function (Human-in-Loop)
const reviewContract = async ({ contract }) => {
  const approver = await user.getApprover('legal')
  return await user.requestApproval({
    userId: approver.id,
    type: 'contract-review',
    data: { contractId: contract.id },
  })
}

// Use semantic triples
await $.Order.validate({ orderId: 'order-123' })
await $.Product.generate.Description({ productId: 'prod-456' })
await $.Agent.qualify.Lead({ leadId: 'lead-789' })
await $.Contract.request.Approval({ contractId: 'contract-999' })

Core Capabilities

  • 4 Function Types - Code, Generative (AI), Agentic, Human
  • Semantic Patterns - GraphDL-based $.Subject.predicate.Object syntax
  • All 8 SDK Objects - Integrates with ai, api, db, decide, every, on, send, user
  • Workflow Foundation - Workflows ARE code functions with triggers
  • Auto-Scaling - Scale automatically based on demand
  • Type-Safe - Full TypeScript support with semantic validation
  • Durable Execution - State persistence for workflows
  • Edge Execution - Run close to users globally

Access Methods

SDK

TypeScript/JavaScript library for defining and invoking functions

const result = await fn('process-order', async ({ orderId }) => {
  /* ... */
})({ orderId: '123' })

SDK Documentation

CLI

Command-line tool for function deployment

do fn deploy process-order --file ./functions/process-order.ts --timeout 300

CLI Documentation

API

REST/RPC endpoints for function execution

curl -X POST https://api.do/v1/functions/process-order/invoke -d '{"orderId":"123"}'

API Documentation

MCP

Model Context Protocol for AI assistant integration

Deploy function "process-order" from file ./functions/process-order.ts

MCP Documentation

Function Types

  • workflows - Code functions with triggers and durable execution
  • agents - Agentic functions with autonomous decision-making
  • llm - Generative functions powered by AI

SDK Object Mappings

  • ai - Generative functions (SDK object - 1 of 8 core)
  • user - Human functions (SDK object - 1 of 8 core)
  • db - Database functions (SDK object - 1 of 8 core)
  • on - Event functions (SDK object - 1 of 8 core)
  • send - Analytics functions (SDK object - 1 of 8 core)
  • every - Scheduled functions (SDK object - 1 of 8 core)
  • api - Integration functions (SDK object - 1 of 8 core)
  • decide - Experiment functions (SDK object - 1 of 8 core)