# Functions

URL: /code/platform/functions · Id: `page:code/platform/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](/business/nouns/function) runs a [Verb](/business/nouns/verb) as code, a model call, an [Agent](/business/nouns/agent) or a [Human](/business/nouns/human) [Task](/business/nouns/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](/business/nouns/noun). Code renews within the manager's increase cap and declines the rest to a person:

```ts
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, ctx)` |
| `generative` | One model call that writes, extracts or classifies | `instructions`, `model` |
| `agentic` | An agent that plans and calls [Tools](/business/nouns/tool) over many steps | `instructions`, `tools`, `model`, `maxSteps`, `budget` |
| `human` | A person working a Task in an [App](/business/nouns/app) or [Mailbox](/business/nouns/mailbox) | `role`, `sla`, `escalateTo`, `form` |

## The context
| Member | Does |
| --- | --- |
| `ctx.$` | The client, acting as this Function's [Worker](/business/nouns/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](/business/nouns/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](/business/nouns/mandate)'s [Limits](/business/nouns/limit) |

## An agentic Function
```ts
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](/business/nouns/action) that keeps the input, the output, the cost and the Function [Version](/business/nouns/version). `tools` are Verbs, so [Permissions](/business/nouns/permission) and Limits apply to each call. The cases in [Verb tests](/code/file-conventions/verb-tests) pass before any [Change](/business/nouns/change) to the Function merges.