> ## 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

> Deploy serverless code that powers your agents — no infra to manage, just `zavu deploy`.

## Zavu Functions

Zavu Functions let you run TypeScript in our cloud and wire it directly to your
WhatsApp/SMS/Email senders. You write the code locally, run `zavu deploy`, and
seconds later your agent is live with tools backed by real business logic.

```ts theme={null}
import { defineAgent, defineTool } from "@zavu/functions"

defineAgent({
  senderId: process.env.SENDER_ID!,
  name: "Bella",
  provider: "zavu",
  model: "openai/gpt-4o-mini",
  prompt: "Eres Bella, anfitriona de la Pizzeria. Sé breve.",
  channels: ["whatsapp"],
})

defineTool({
  name: "check_availability",
  description: "Get free reservation slots for a date and party size.",
  parameters: {
    type: "object",
    properties: {
      date: { type: "string" },
      partySize: { type: "number" },
    },
    required: ["date", "partySize"],
  },
  handler: async ({ date, partySize }) => {
    // your real booking logic — DB, POS, external API, whatever
    return { available: true, slots: ["19:00", "21:00"] }
  },
})
```

That's the entire integration. One file. `zavu deploy`. Done.

## When to use Functions

<CardGroup cols={2}>
  <Card title="AI agent with real actions" icon="robot">
    Customer asks something, the LLM decides which tool to call, your code runs,
    real data goes back as the answer.
  </Card>

  <Card title="Custom webhooks" icon="webhook">
    Receive inbound from Stripe, GitHub, your own systems, then forward as a
    WhatsApp message.
  </Card>

  <Card title="Scheduled jobs" icon="clock">
    Daily report digests, reminder broadcasts, cleanup tasks.
  </Card>

  <Card title="Event-driven automation" icon="bolt">
    React to `message.inbound`, `broadcast.completed`, etc. with custom logic
    without managing webhook receivers yourself.
  </Card>
</CardGroup>

## How it relates to AI Agents

Zavu has two complementary ways to build agents:

| You want                                             | Use                                                               |
| ---------------------------------------------------- | ----------------------------------------------------------------- |
| A no-code agent configured from the dashboard        | [AI Agents](/guides/ai-agents/overview)                           |
| An agent with custom business logic in your own code | **Zavu Functions** (this guide)                                   |
| Both — start no-code, evolve to code                 | Start with AI Agents, migrate when you need tools or custom flows |

Functions can *fully manage* an AI Agent: the `defineAgent` call creates and
keeps the agent config in sync with your code. Once your function declares
`defineAgent`, the agent is "managed by the function" — the dashboard surfaces
this and disables manual edits to prevent drift.

## Mental model

```
+----------------+        +--------------------+        +-----------+
| WhatsApp user  | -----> | Zavu sender (WABA) | -----> | AI Agent  |
+----------------+        +--------------------+        +-----------+
                                                              |
                                                       (tool call)
                                                              v
                                            +-------------------------------+
                                            | Your Zavu Function            |
                                            |  defineTool(handler)          |
                                            +-------------------------------+
                                                              |
                                                       (return result)
                                                              v
                                                       Agent answers user
```

* **Fully managed runtime.** Each function runs in Zavu's serverless cloud. No
  consoles to log into — `zavu deploy` handles bundling, dependencies, and
  publishing.
* **Internal invocation.** When the agent calls a tool, we use signed
  internal invocations — your function is **not** publicly exposed. No HTTP,
  no HMAC secrets to rotate, no DDoS surface.
* **Native event binding.** Functions can also subscribe to Zavu events
  (`message.inbound`, `broadcast.completed`, etc) via triggers.
* **Auto-provisioned credentials.** Every function gets a scoped `ZAVU_API_KEY`
  in its environment so it can call our SDK without you handling key
  distribution.

## Quick tour

<Tip>
  Want your AI coding agent (Claude Code, Cursor, Copilot…) to write the
  function for you? Install [Zavu's Coding Agent Skills](/tools/coding-agent-skills) —
  the `functions` skill teaches it `defineAgent`, `defineTool`, `zavu deploy`,
  and the full debug flow.

  ```sh theme={null}
  npx skills add zavudev/zavu-skills
  ```
</Tip>

<Steps>
  <Step title="Install the CLI">
    ```sh theme={null}
    brew install zavudev/tools/zavu
    # or grab a standalone binary from
    # https://github.com/zavudev/zavu-cli/releases
    ```
  </Step>

  <Step title="Login (one time)">
    ```sh theme={null}
    zavu login
    ```

    Opens your browser, lets you pick a project. The API key is saved to
    `~/.zavu/credentials.json` and used by every later command.
  </Step>

  <Step title="Scaffold a function">
    ```sh theme={null}
    zavu fn init --template restaurant-booking -y
    cd reservations
    ```

    Creates `index.ts` with `defineAgent` + `defineTool` boilerplate.
  </Step>

  <Step title="Set secrets">
    ```sh theme={null}
    zavu fn secrets set SENDER_ID jn76vnxet8g5nq661by3v06y1581bmmn
    ```

    The agent will run on this WhatsApp sender. Get the ID from
    `zavu senders list`.
  </Step>

  <Step title="Deploy">
    ```sh theme={null}
    zavu deploy
    ```

    Bundle, upload, agent + tools synced to your sender.
  </Step>

  <Step title="Try it">
    Send a WhatsApp to the sender's number. The agent answers, calls your
    tool handlers, returns real data.
  </Step>
</Steps>

## Continue

<CardGroup cols={2}>
  <Card title="Quickstart" icon="rocket" href="/guides/functions/quickstart">
    Full step-by-step from zero to live agent in 10 minutes.
  </Card>

  <Card title="CLI reference" icon="terminal" href="/guides/functions/cli">
    Every `zavu` command, flag by flag.
  </Card>

  <Card title="Define an agent" icon="brain" href="/guides/functions/defining-agents">
    `defineAgent` API, providers, prompts, models.
  </Card>

  <Card title="Define tools" icon="wrench" href="/guides/functions/defining-tools">
    `defineTool` API, schemas, handlers, error handling.
  </Card>

  <Card title="Secrets" icon="key" href="/guides/functions/secrets">
    Environment variables encrypted at rest.
  </Card>

  <Card title="Triggers" icon="bolt" href="/guides/functions/triggers">
    Listen to Zavu events from your function.
  </Card>

  <Card title="Runtime versions" icon="layers" href="/guides/functions/runtime">
    How pinning works, when to upgrade.
  </Card>

  <Card title="Examples" icon="code" href="/guides/functions/examples/restaurant">
    Complete restaurant booking agent, walked through.
  </Card>
</CardGroup>
