Skip to content

Build an AI agent that books meetings

Booking a meeting comes down to three steps: know when you’re free, pick a time, and write it down without clashing with anything else. In this tutorial your agent does all three with Chronary. Then it creates a booking link, so people can pick a time without a back-and-forth.

You will:

  1. Limit the calendar to working hours, with a gap between meetings.
  2. Ask Chronary for free times and book the first one.
  3. Handle the case where someone takes the slot first.
  4. Create a booking page that people can use to book themselves.

Everything here works on the Free plan.

You need an agent with a calendar, the SDK installed and CHRONARY_API_KEY set. If you don’t have those yet, do Give your AI agent a calendar first. It takes about five minutes. Create the calendar with prevent_overlaps: true, so it can’t be double-booked.

The examples use these two IDs:

import { Chronary } from '@chronary/sdk';
const chronary = new Chronary();
const agentId = 'agt_your_agent_id';
const calendarId = 'cal_your_calendar_id';

Without rules, any empty minute counts as free, including 3am on a Sunday. Set working hours and a 10-minute buffer before and after each meeting. Chronary then only offers times inside those hours, with space around existing events.

const nineToFive = { start: '09:00', end: '17:00' };
await chronary.calendars.setAvailabilityRules(calendarId, {
timezone: 'America/New_York',
buffer_before_minutes: 10,
buffer_after_minutes: 10,
working_hours: {
mon: nineToFive,
tue: nineToFive,
wed: nineToFive,
thu: nineToFive,
fri: nineToFive,
},
});

You only do this once per calendar. Days you leave out (here Saturday and Sunday) count as busy.

Say the agent got this request: “Find 30 minutes with me sometime this week.” Ask Chronary for the agent’s free time over the next seven days, in slots of at least 30 minutes:

const now = new Date();
const weekAhead = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
const availability = await chronary.availability.forAgent(agentId, {
start: now.toISOString(),
end: weekAhead.toISOString(),
duration: '30m',
});
if (availability.availability_state !== 'complete') {
throw new Error('Availability is incomplete; try again shortly');
}
console.log(availability.slots.slice(0, 3));
// [{ start: '…T13:00:00Z', end: '…T16:20:00Z' }, …]

Two things to know about the answer:

  • Each slot is a free stretch of at least 30 minutes, not exactly 30. A slot can run for hours, so book from its start for the length you want.
  • Only book from a complete answer. If the agent’s person connected their Google or Outlook calendar and it hasn’t synced recently, Chronary returns no slots and a warning, so it never offers a time it can’t vouch for.

Take the first slot, book 30 minutes from its start, and handle the case where someone else got there first. Because the calendar has prevent_overlaps on, a clashing write is refused with 409 and the code event_conflict. Nothing is written, so the agent can move on to the next slot.

import { ChronaryError } from '@chronary/sdk';
const MEETING_MS = 30 * 60 * 1000;
async function bookFirstFreeSlot(title: string) {
for (const slot of availability.slots) {
const start = new Date(slot.start);
const end = new Date(start.getTime() + MEETING_MS);
try {
return await chronary.events.create(calendarId, {
title,
start_time: start.toISOString(),
end_time: end.toISOString(),
});
} catch (err) {
if (err instanceof ChronaryError && err.code === 'event_conflict') {
continue; // taken in the meantime: try the next slot
}
throw err;
}
}
return null; // no free time this week
}
const event = await bookFirstFreeSlot('Intro call with Sam');
console.log(event ? `Booked ${event.startTime}` : 'No free time this week');

This is safe even when many agents book at once: Chronary lets exactly one write win each slot. You don’t need locks or a check-then-write loop of your own. The double-booking guide explains what’s guaranteed.

Often the easiest move is to send a link. A booking page is a public page for one calendar. People see the open times, pick one, and the meeting lands on the agent’s calendar. It never offers a time that’s already taken on the calendar. A booking page has its own working hours, so set them here too.

const page = await chronary.bookingPages.create({
calendar_id: calendarId,
title: 'Intro call',
description: '30 minutes to see if we can help.',
duration_minutes: 30,
buffer_minutes: 10,
min_notice_minutes: 120,
window_days: 14,
timezone: 'America/New_York',
availability_constraints: {
mon: nineToFive,
tue: nineToFive,
wed: nineToFive,
thu: nineToFive,
fri: nineToFive,
},
});
console.log(page.booking_url); // send this to people

The page reuses the weekday hours from step 1. min_notice_minutes: 120 stops anyone booking less than two hours ahead, and window_days: 14 shows the next two weeks. The booking pages guide covers the other options.

When someone books through the page, Chronary sends an event.created webhook with a booking_page_id, so your agent can react right away: send a confirmation, prepare notes, or add the call to its plan. The same webhook also fires for the events your agent creates itself.

Your agent can now find free time, book it without clashes, and hand out a link so people can book themselves. Next: