> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zavu.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# zavu functions

> Scaffold, deploy, invoke, inspect and roll back your code

`zavu functions` (alias `fn`) drives Zavu Functions — your TypeScript running on
every messaging event. The most-used subcommands are also available at the top
level: `zavu deploy` is `zavu fn deploy`.

## Scaffold

```bash theme={null}
zavu fn init --name order-bot --template blank
```

Writes `index.ts`, a `package.json` declaring `@zavudev/functions`, a
`tsconfig.json`, and `.zavu/config.json` holding the function's id. Run
`zavu fn init --help` for the current template list.

<Note>
  **Commit `.zavu/`.** It holds the `functionId`, and there is no command to look
  one up — a teammate who clones without it cannot deploy.
</Note>

To start from a working agent instead of a blank file, see
[`zavu agents pull`](/guides/cli/agents).

## Deploy

```bash theme={null}
zavu deploy
```

```
› Deploying Order Bot (order-bot)…
  deployment id: nx7v0h30epeh2s7ppxcn9mpan58b6yre
› status: active
ℹ Agents synced:
    + Bella
ℹ Tools synced:
    + lookup_order
✓ Deployed in 11.5s
```

The summary lists what the deploy did to your agents and tools. **Read the lines
above the ✓** — warnings print before the success line, and the command exits
non-zero when your declarations were not synced at all.

Warnings you may see, and what they mean:

| Warning                                                | What happened                                                                         |
| ------------------------------------------------------ | ------------------------------------------------------------------------------------- |
| `manifest probe threw: …`                              | Your code failed to load. Nothing was synced; fix and deploy again.                   |
| `tools are synced but will NOT be called on <channel>` | The text path does not offer tools to the model. Use voice, or a flow's `tool` step.  |
| `sender … now has N agents`                            | Only the first answers. The rest are unreachable — give this function its own sender. |

`zavu fn push` updates the draft **without** deploying. Useful to save work in
progress; nothing changes in production until `deploy`.

## Run it locally

```bash theme={null}
# Call one tool handler directly, with no deploy:
zavu fn invoke --tool lookup_order --args '{"orderId":"ORD-001"}'

# Or dispatch a synthetic event at your default export:
zavu fn invoke --event message.inbound \
  --data '{"from":"+14155551234","text":"hola"}'
```

| Flag                                                      |                                                                           |
| --------------------------------------------------------- | ------------------------------------------------------------------------- |
| `--tool <name>` / `--args <json>` / `--args-file <path>`  | Call one `defineTool` handler                                             |
| `--event <name>` / `--data <json>` / `--data-file <path>` | Dispatch an event                                                         |
| `--source <file>`                                         | Entry file. Defaults to `index.ts`.                                       |
| `--live`                                                  | Make real API calls. Off by default: outbound HTTP is stubbed and logged. |

<Note>
  `fn invoke` runs your code with [Bun](https://bun.sh). Every other command runs
  under plain Node.
</Note>

This is the cheapest feedback in the product: it exercises your handler exactly
as production will, in milliseconds, without deploying or spending anything.

## Logs

```bash theme={null}
zavu fn logs            # recent invocations
zavu fn logs --tail     # follow
```

Run it from the function's directory. Lambda's own noise is filtered out and
internal identifiers are redacted.

## Secrets

```bash theme={null}
zavu fn secrets list
zavu fn secrets set STRIPE_KEY sk_live_…
zavu fn secrets set STRIPE_KEY --from-file ./key.txt
zavu fn secrets unset STRIPE_KEY
```

Values are write-only: `list` shows the last four characters, never the secret.
Reach them in your handler with `process.env.STRIPE_KEY`.

<Warning>
  Secrets apply on the **next deploy**. Setting one does not change the running
  function until you run `zavu deploy`.
</Warning>

## Triggers

```bash theme={null}
zavu fn triggers list
zavu fn triggers events                    # what you can subscribe to
zavu fn triggers add --event message.inbound
zavu fn triggers toggle <triggerId> --active false
zavu fn triggers remove <triggerId>
```

A trigger subscribes the function to an event, optionally scoped to one sender.
A function that only declares an agent and its tools needs no triggers — the
agent path invokes it directly.

## Versions and rollback

```bash theme={null}
zavu fn versions list
zavu fn rollback <version>
```

Every deploy is a version with its own record. `rollback` republishes a previous
one's source and dependencies; it always asks for confirmation. Secrets are not
rolled back.

## Delete

```bash theme={null}
zavu fn delete            # in the function's directory
zavu fn delete <functionId>
```

Removes the function and everything it owns — its triggers, secrets, deployment
history, and the agents and tools it manages. It asks you to type the slug
first, because there is no undo.

## Where to go next

<CardGroup cols={2}>
  <Card title="How agents work" icon="diagram-project" href="/concepts/agent-architecture">
    What a deploy actually does, with diagrams.
  </Card>

  <Card title="zavu agents" icon="robot" href="/guides/cli/agents">
    Test, connect and inspect the agents your code declares.
  </Card>
</CardGroup>
