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/ runs Lease.renew. Leaseline declares a Lease Noun. Code renews within the manager's increase cap and declines the rest to a person:
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
| Kind | Runs as | Declares |
|---|---|---|
code | Deterministic code | code(input, |
generative | One model call that writes, extracts or classifies | instructions, model |
agentic | An agent that plans and calls Tools over many steps | instructions, tools, model, maxSteps, budget |
human | A person working a Task in an App or Mailbox | role, sla, escalateTo, form |
The context
| Member | Does |
|---|---|
ctx.$ | The client, acting as this Function's Worker |
ctx.step, ctx.sleep, ctx.waitForEvent | Durable steps and waits that survive restarts |
ctx.ask | Asks a question and waits for the answer |
ctx.approve | Opens an Approval and waits |
ctx.decline | Passes to the next kind in the cascade, with a reason |
ctx.budget | Spend so far against budget and the Mandate's Limits |
An agentic Function
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.