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.
defineAgent
defineAgent declares the AI agent that will run on a specific WhatsApp / SMS
sender. Calling it inside your function source binds the agent to that sender
on every zavu deploy.
zavu deploy:
- The agent is created (or updated) under that sender.
- Tagged as managed by this function — the dashboard disables manual edits to prevent drift.
- Marked
enabled: trueautomatically.
Required fields
| Field | Type | Notes |
|---|---|---|
senderId | string | The _id of an existing sender in your project. Usually process.env.SENDER_ID. |
name | string | Display name. Shown in zavu agents executions and the dashboard. |
provider | zavu | openai | anthropic | google | mistral | LLM provider. |
model | string | Model id (depends on provider — see below). |
prompt | string | System prompt. Multi-line OK (use backticks). |
Optional fields
| Field | Default | Description |
|---|---|---|
channels | ["*"] | Which channels trigger the agent: whatsapp, sms, telegram, email, *. |
messageTypes | ["text"] | Message types: text, image, audio, … |
apiKey | — | Required when provider !== "zavu" (or pre-create a secret in the dashboard). |
contextWindowMessages | 10 | How many previous messages to include in each LLM call. |
temperature | provider default | 0–2. |
maxTokens | unbounded | Cap on response length. |
sessionTimeoutMinutes | 60 | After this idle gap, the agent starts a new conversation. |
includeContactMetadata | true | If true, contact name / metadata is included as context. |
enabled | true | Set to false to deploy the agent but keep it inactive. |
Providers
zavu — managed gateway (recommended for getting started)
No API key needed. LLM costs are billed directly from your Zavu balance at
pass-through rates.
model | Backend | Best for |
|---|---|---|
openai/gpt-4o-mini | OpenAI GPT-4o mini | Cheapest, fastest |
openai/gpt-4o | OpenAI GPT-4o | High-quality reasoning |
anthropic/claude-3-5-haiku-20241022 | Anthropic Haiku | Fast, good tool-use |
anthropic/claude-3-5-sonnet-20241022 | Anthropic Sonnet | Best multi-step reasoning |
google/gemini-1.5-flash | Google Flash | Cheap multilingual |
google/gemini-1.5-pro | Google Pro | Long context windows |
Bring your own key (BYOK)
Passprovider matching the vendor and apiKey (or pre-create a secret in
the dashboard and rely on it being already stored).
gpt-4o-mini, claude-3-5-sonnet-20241022,
gemini-1.5-flash, etc) — no provider/ prefix when using BYOK.
Prompts
Theprompt field is the system message every conversation starts with. It’s
where you set the persona, rules, and guardrails.
Patterns that work
Anti-patterns
Triggers (which messages reach the agent)
By default the agent fires on every inbound message to its sender. Restrict withchannels and messageTypes:
message.inbound), use explicit triggers
in addition.
One agent per file
defineAgent is allowed multiple times only when each call has a different
(senderId, name) pair, in which case each tool must explicitly bind to one:
SENDER_ID secret.
Updates and ownership
Everyzavu deploy reconciles the live agent to match what’s in the code.
| State | Reconcile behavior |
|---|---|
| No agent exists yet | Create it, mark as managed by this function. |
Manually-created agent with same (senderId, name) | Takes ownership. Future edits are blocked in the dashboard. |
| Agent managed by THIS function | Update fields to match the manifest. |
| Agent managed by a DIFFERENT function | Skipped with a warning. Rename in code or delete the other function first. |
defineAgent from your code and redeploy, the managed agent
is deleted (along with its managed tools). Manual agents are never
touched.
Disabling without deleting
To pause an agent without removing the code:Common patterns
Multi-language agent
Multi-language agent
Don’t hard-code a language. Tell the prompt to match the user:The LLM handles language detection per turn — no need for routing logic.
Escalation to human
Escalation to human
Add a tool that signals escalation (e.g., creates a ticket in your CRM
or notifies an operator on Slack). Tell the prompt when to use it:
Different agent per sender (multi-tenant)
Different agent per sender (multi-tenant)
Same code, different
SENDER_ID secret in each function. The prompt can
even include process.env.BRAND_NAME to customize per tenant:Reading contact metadata
Reading contact metadata
With
includeContactMetadata: true (default), the LLM sees:- Contact’s display name (if known).
- Custom metadata fields on the contact.
- Channel they wrote from.
client.contacts.update(contactId, { metadata: {...} }).
Useful for “Hello $name” style personalization without a tool call.Next
defineTool
Give the agent actions to execute.
Secrets
Store SENDER_ID, API keys, and other env vars.
