# Function

URL: /business/nouns/function · Id: `noun:function`

> A Function is how a Verb executes, as code, a generative model, an Agent, or a Human, invisible to the caller.

A Function is how a [Verb](/business/nouns/verb) executes, as code, a generative model, an [Agent](/business/nouns/agent), or a [Human](/business/nouns/human), invisible to the caller.

## Properties
| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `kind` | `string` | Yes | One of `code`, `generative`, `agentic`, or `human`. |
| `version` | `string` | No | The Version an Action runs, kept with the Action. |
| `cascade` | `string[]` | No | Kinds tried in order when one declines, such as code, then a Human. |
| `instructions` | `text` | No | For a generative or agentic Function, what it does and how. |
| `model` | `string` | No | For a generative or agentic Function, the model it runs on. |
| `tools` | list of [Verb](/business/nouns/verb) | No | For an agentic Function, the Verbs it may call; Permissions and Limits apply to each. |
| `maxSteps` | `integer` | No | For an agentic Function, the most steps one Action may take. |
| `budget` | `money` | No | The most one Action may spend; the Mandate’s Limits apply as well. |
| `role` | [Role](/business/nouns/role) | No | For a human Function, the Role its Tasks go to. |
| `form` | `json` | No | For a human Function, the form; generated from the Verb’s inputs and outputs when absent. |
| `sla` | `string` | No | For a human Function, how long a Task may wait, as an ISO 8601 duration. |
| `escalateTo` | [Role](/business/nouns/role) | No | For a human Function, the Role a Task moves to when the service level passes. |

## Object
```json
{
  "$id": "https://api.sb/kilnbakery.com/functions/function_1",
  "$type": "Function",
  "kind": "code",
  "version": "Example version",
  "cascade": [
    "Example cascade"
  ],
  "instructions": "Example instructions",
  "model": "Example model",
  "tools": [
    "verb_1"
  ],
  "maxSteps": 1,
  "budget": {
    "amount": 9,
    "currency": "USD"
  },
  "role": "role_1",
  "form": {},
  "sla": "PT4H",
  "escalateTo": "role_1"
}
```

## Relationships
- <a id="rel-implements"></a>A Function **implements** one [Verb](/business/nouns/verb): a Function is how a [Verb](/business/nouns/verb) runs: code, a generative model, an [Agent](/business/nouns/agent) or a [Human](/business/nouns/human), and the caller never sees which. `implements`, inverse [`implementedBy`](/business/nouns/verb#rel-implemented-by).
- <a id="rel-uses"></a>A Function **uses** many [Secrets](/business/nouns/secret): a Function declares the [Secrets](/business/nouns/secret) it reads; deploying to `live` fails when one is missing there. `uses`, inverse [`usedBy`](/business/nouns/secret#rel-used-by).

## Verbs
| Verb | Description | Subject | Event | Class |
| --- | --- | --- | --- | --- |
| <a id="create"></a>[Function.create](/business/nouns/function/create) | Creates a Function. Inherited from [Noun](/business/nouns/noun). | None. | `Function.created` | Two-way: `try`, `send`, `do` |
| <a id="get"></a>[Function.get](/business/nouns/function/get) | Returns one Function by id. Inherited from [Noun](/business/nouns/noun). | None. | None. | Read: `try`, `do` |
| <a id="list"></a>[Function.list](/business/nouns/function/list) | Returns Functions, newest first, one page at a time. Inherited from [Noun](/business/nouns/noun). | None. | None. | Read: `try`, `do` |
| <a id="update"></a>[Function.update](/business/nouns/function/update) | Changes the given properties of a Function. Inherited from [Noun](/business/nouns/noun). | None. | `Function.updated` | Two-way: `try`, `send`, `do` |
| <a id="delete"></a>[Function.delete](/business/nouns/function/delete) | Deletes a Function; its history is kept. Inherited from [Noun](/business/nouns/noun). | None. | `Function.deleted` | One-way: `send`, `do` |

## Permissions
Which Access level may call each Verb. One-way Verbs wait their delay window.

| Operation | `owner` | `admin` | `member` | `viewer` |
| --- | --- | --- | --- | --- |
| `Function.create` | Yes | Yes | Yes | No |
| `Function.get` | Yes | Yes | Yes | Yes |
| `Function.list` | Yes | Yes | Yes | Yes |
| `Function.update` | Yes | Yes | Yes | No |
| `Function.delete` | Yes | Yes | Yes | No |

## Call it

**Ask**

```text
Add a function to PetPantry.
```

**API**

```bash
curl -X POST https://api.sb/petpantry.shop/functions \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind":"code"}'
```

```json
{
  "api": "https://api.sb/petpantry.shop",
  "function": {
    "$id": "https://api.sb/petpantry.shop/functions/function_1",
    "$type": "Function",
    "kind": "code"
  },
  "action": {
    "$id": "https://api.sb/petpantry.shop/actions/action_1",
    "operation": "Function.create",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/petpantry.shop/actions/action_1"
  }
}
```

**SDK**

```ts
import { $ } from 'startup-builder'

const result = await $.Function.create({ kind: 'code' })
```

**CLI**

```bash
npx startup-builder do Function.create --json '{"kind":"code"}'
```

**MCP**

```json
{
  "name": "do",
  "arguments": {
    "code": "return await $.Function.create({ kind: 'code' })"
  }
}
```

## Example
At a tax-preparation service, `Return.draft` runs as an [Agent](/business/nouns/agent), `Return.check` runs as code, and `Return.sign` runs as a credentialed [Human](/business/nouns/human). The caller invokes all three the same way.