confirm: true) ·
confirmLines with prices from your code ·
dedupe of repeated side effects ·
enum validation of arguments ·
Yes/No buttons ·
audit events
Prerequisites
- Node.js 22.12 or newer.
- An Anthropic API key in the
ANTHROPIC_API_KEYenvironment variable (or another model with tool calling, see below).
The bot
How it works
- Tools are plain functions. Each entry of
toolshas adescriptionthe model reads, an optional JSONschemaand ahandler. The plugin runs the tool loop: it calls the model, runs the tools it asks for and sends the results back until the model writes the answer (maxStepsbounds it). - Confirmation before side effects.
confirm: truemakes the plugin ask the customer and run the tool only after a clear “yes”. The question is asked inside a conversation, so the chat is never blocked while waiting. On channels with buttons (Telegram, WhatsApp Cloud API, the simulator) it shows Yes/No buttons; on WhatsApp through Baileys it asks for a typed yes/no. - Your code owns the numbers.
confirmLinesprints the service and the price fromSERVICES, and the handler returns them too, so the model repeats them instead of calculating. - No double bookings.
dedupe: 'args'skips a call with the same arguments as a booking made in the last 10 minutes; the model is told it was already done. A handler that returns{ error }did nothing and is not remembered. - Every create has its list and cancel. Without
my_appointmentsandcancel_appointmenta model “fixes” a booking by making another one. - Audit. Each step of the loop is an
'ai.tool'event; the example logs the runs.
Try it
packages/ai/tests/docs-examples-ai.test.ts); the
confirmations, buttons and tool results are the real ones. In the simulator you
can also answer a confirmation with :click 1. In the fourth message the model
asks for the same booking again: dedupe skips it without asking, and the
declined cancellation leaves the appointment as it was.
Other model providers
Switch to OpenAI, Gemini or a local Ollama model
Switch to OpenAI, Gemini or a local Ollama model
Tool calling works on every provider; on Ollama pick a model tagged tools.OpenAI (Gemini (Ollama on your machine (no package, no key; run
npm install openai, key in OPENAI_API_KEY):npm install @google/genai, key in GEMINI_API_KEY):ollama pull qwen3 first):Run it on WhatsApp or Telegram
node bot.js prints a QR code: scan it with WhatsApp (Linked devices).
For Telegram, install @botmesh/telegram and start the factory with
new TelegramProvider({ token: process.env.TELEGRAM_TOKEN ?? '' }): the
confirmation then uses inline Yes/No buttons, which are removed once answered.
Next steps
- Bakery AI assistant: the same ideas for food orders (quotes, update and cancel, orders kept per user), runnable on WhatsApp through Baileys or Twilio
- AI tool calling guide: schemas, the loop, confirmations and best practices
- AI with human escalation: a tool that hands the chat to a person
- Examples overview