Skip to content

Functions

A Function runs a Verb as code, a model call, an agent or a person's Task, behind the Verb's own typed signature.

A Function runs a Verb as code, a model call, an Agent or a Human Task, behind the Verb's typed signature. The caller never sees which kind ran.

Write one

The file name binds the Function to its Verb: nouns/Lease.renew.ts runs Lease.renew. Leaseline declares a Lease Noun. Code renews within the manager's increase cap and declines the rest to a person:

TypeScript
import { fn } from 'startup-builder'

export default fn('Lease.renew', {
  cascade: ['code', 'human'],
  async code({ lease, increase = 0 }, ctx) {
    if (increase > 0.05) return ctx.decline('Over the increase the manager allows')
    const { rent } = await ctx.$.Lease.get({ id: lease })
    if (!rent) return ctx.decline('The lease has no rent to raise')
    return ctx.$.Lease.update({ id: lease, rent: { ...rent, amount: Math.round(rent.amount * (1 + increase)) } })
  },
  role: 'customer/success-manager',
  sla: 'PT4H',
})

The human kind needs no form: one generates from the Verb's input and output.

Kinds

KindRuns asDeclares
codeDeterministic codecode(input, ctx)
generativeOne model call that writes, extracts or classifiesinstructions, model
agenticAn agent that plans and calls Tools over many stepsinstructions, tools, model, maxSteps, budget
humanA person working a Task in an App or Mailboxrole, sla, escalateTo, form

The context

MemberDoes
ctx.$The client, acting as this Function's Worker
ctx.step, ctx.sleep, ctx.waitForEventDurable steps and waits that survive restarts
ctx.askAsks a question and waits for the answer
ctx.approveOpens an Approval and waits
ctx.declinePasses to the next kind in the cascade, with a reason
ctx.budgetSpend so far against budget and the Mandate's Limits

An agentic Function

TypeScript
import { fn } from 'startup-builder'

export default fn('Lease.notify', {
  kind: 'agentic',
  instructions: 'Write the renewal notice from the renewal-notice Template. State the end date and the new rent.',
  tools: ['Lease.get', 'Message.schedule'],
  model: 'write',
  maxSteps: 8,
  budget: { amount: 0.5, currency: 'USD' },
})

Guarantees

Every call is one Action that keeps the input, the output, the cost and the Function Version. tools are Verbs, so Permissions and Limits apply to each call. The cases in Verb tests pass before any Change to the Function merges.