@zavudev/functions
v0.3.0
Published
Runtime helpers for Zavu Functions: defineAgent, defineTool, defineFunction, and the ctx.store / ctx.memory clients.
Readme
@zavudev/functions
Runtime helpers for Zavu Functions — your TypeScript, running on every messaging event.
npm add @zavudev/functionsYou do not need to install this to deploy. The Zavu runtime provides it in
production. Install it so your editor, tsc, and local runs resolve the same
module your deployed function will.
Declare an agent
import { defineAgent, defineTool } from "@zavudev/functions"
defineAgent({
senderId: process.env.SENDER_ID!,
name: "Bella",
provider: "zavu",
model: "openai/gpt-4o-mini",
channels: ["whatsapp", "sms"],
prompt: `You are the order desk for Tony's Pizza.
Answer in one or two short sentences.`,
})zavu deploy reads these declarations and reconciles them into a real agent.
The code is the source of truth: remove the defineAgent call and the next
deploy removes the agent.
Give it a skill
defineTool({
name: "check_order_status",
description: "Look up an order. Call this before answering about one.",
parameters: {
type: "object",
properties: { orderId: { type: "string" } },
required: ["orderId"],
},
handler: async ({ orderId }, ctx) => {
const res = await fetch(`https://api.example.com/orders/${orderId}`)
if (!res.ok) return { ok: false, reason: "not_found" }
return { ok: true, ...(await res.json()) }
},
})Run a handler locally without deploying:
npx zavudev fn invoke --tool check_order_status --args '{"orderId":"ORD-1"}'Never return a fake success. A handler that reports { booked: true } when
it did nothing makes the agent tell a real person their booking exists.
Tools are offered to the model on every channel — plain text, voice, and a flow's
toolstep — with up to 5 tool rounds per reply.
Answer phone calls
defineAgent({
// …
channels: ["voice"],
voice: {
enabled: true,
greeting: "Hi, thanks for calling Acme. How can I help?",
greetings: { es: "Hola, gracias por llamar a Acme." },
interruptible: true,
maxCallDurationMinutes: 12,
transferPhoneNumber: "+14155551234",
},
})Handle raw events
Optional — a file that only declares an agent and its tools works on its own.
import { defineFunction } from "@zavudev/functions"
export default defineFunction({
on: ["message.inbound"],
handler: async (event, ctx) => {
ctx.log("got", event.type)
},
})Docs
MIT
