defineTool
defineTool declares an action the agent can take. The LLM reads the
description to decide when to call it, and the parameters schema to
decide with what arguments. Your handler runs in the function’s runtime
and returns the result.
How the agent decides
The agent’s LLM picks tools based on three signals:description— primary signal. Write it as the answer to “when should the model call this?”. Be specific about preconditions.parameters— JSON Schema. Each property’sdescriptionhelps the LLM fill in the right value.name— secondary signal. Usesnake_caseaction verbs:check_availability,create_reservation,cancel_reservation.
Required fields
Optional fields
Parameters schema
Use JSON Schema. The agent’s LLM is trained to fill in any standard schema — keep it simple.Primitive types
Enums
Nested objects
Free-form metadata
When you want to accept arbitrary key/value pairs:Handler signature
ctx properties
Return value
The handler’s return value goes back to the LLM as the tool result. The LLM includes it in the next message it composes for the customer.The LLM reads field names. Return semantically named fields (
confirmed,
summary, eta_minutes) rather than IDs and codes only. The natural-language
answer it generates is better when the structure is self-documenting.Error handling
Throwing from a handler returnssuccess: false to the LLM with the message
as the error. The LLM usually translates this into “Sorry, that didn’t work
because…” for the user.
Calling Zavu’s own API from a tool
Every function has aZAVUDEV_API_KEY env var injected automatically. Use it
to call your Zavu account:
messages:send, messages:read, contacts:read scopes.
For other operations, create a project-scoped API key in the dashboard and
inject it as a secret.
Calling external services
Standardfetch. Functions have unrestricted egress (today).
Adding npm dependencies
Editpackage.json:
npx zavudev deploy installs them server-side during the bundle step (no local
npm install required). Your function ships as a self-contained bundle with the deps.
Testing locally
defineFunction handler with a synthetic message event, no
cloud round-trip. Tool calls invoked by the LLM aren’t simulated in local
invoke — for that, use the deployed function and npx zavudev fn logs --tail.
Common patterns
Returning a list back to the LLM
Returning a list back to the LLM
Don’t return huge arrays — the LLM has limited context. Filter and trim
server-side:
Long-running tasks
Long-running tasks
Functions have a 30s budget by default (configurable up to 15min). For longer
work, return immediately with a job ID and let the LLM follow up:
Idempotency
Idempotency
Tools can be called multiple times (LLM retries, user repeats request).
Use the tool’s natural keys to dedupe:
Multi-step confirmations
Multi-step confirmations
For destructive operations, return a The LLM will summarize the cancellation and wait for the user to confirm
before calling again with
confirmRequired payload first:confirm: true.Next
Secrets
Inject DB credentials and API keys.
Restaurant example
Full booking agent walked through.
