Find a time that works for several agents and people
Finding a time for one calendar is easy. The hard part is a time that suits several agents and the people behind them, without anyone reading anyone else’s calendar. Chronary does this in one call: you name the agents, and it returns only the times when all of them are free.
In this tutorial you will:
- Ask for times when several agents, and a shared room, are all free.
- Let a person’s own Google or Outlook calendar block time too, without sharing its details.
- Book the chosen time on every calendar, safely.
- Hand the choice to the agents when they need to agree on a time.
Before you start
Section titled “Before you start”You need two or more agents, each with a calendar, the SDK installed and CHRONARY_API_KEY set. Give your AI agent a calendar shows how to create them. The examples use three agents and one shared calendar for a meeting room:
import { Chronary } from '@chronary/sdk';
const chronary = new Chronary();const agents = ['agt_sales', 'agt_support', 'agt_engineering'];const roomCalendarId = 'cal_meeting_room';from chronary import Chronary
client = Chronary()agents = ["agt_sales", "agt_support", "agt_engineering"]room_calendar_id = "cal_meeting_room"Step 1: Find times when everyone is free
Section titled “Step 1: Find times when everyone is free”Ask for one-hour slots over the next five days. Chronary checks every calendar of every agent you name, plus any extra calendars you list (here, the room), and returns only the times when all of them are free.
const now = new Date();const fiveDays = new Date(now.getTime() + 5 * 24 * 60 * 60 * 1000);
const result = await chronary.availability.check({ agents, calendars: [roomCalendarId], start: now.toISOString(), end: fiveDays.toISOString(), duration: '1h',});
console.log(result.availability_state, result.slots.slice(0, 3));from datetime import datetime, timedelta, timezone
now = datetime.now(timezone.utc)
result = client.availability.find_meeting_time( agents=agents, calendars=[room_calendar_id], start=now.isoformat(), end=(now + timedelta(days=5)).isoformat(), duration="1h",)
print(result.availability_state, result.slots[:3])Each slot is a stretch of at least an hour when everyone is free, and it can be longer. Each agent’s working hours count too: if you set availability rules on their calendars, time outside those hours is busy. So a slot here falls inside everyone’s working day.
Step 2: Include people’s own calendars
Section titled “Step 2: Include people’s own calendars”Agents usually act for people, and those people already have meetings in Google Calendar or Outlook. Connect a person’s calendar, and their real meetings block time for their agent automatically. The agent only ever sees “busy” or “free”. Chronary never shows it event titles, attendees or the account name.
The agent can’t sign in for the person, so it creates a setup link and sends it to them. The person opens it, signs in to Google or Microsoft, and picks which of their calendars count.
const link = await chronary.connectionLinks.create('cal_sales', { capabilities: ['availability'],});
// Send this to the person, for example by email or chat.console.log(link.setup_url);
// Later: check whether they finished.const status = await chronary.connectionLinks.get(link.id);console.log(status.status); // 'awaiting_human' … 'completed'link = client.connection_links.create("cal_sales", capabilities=["availability"])
# Send this to the person, for example by email or chat.print(link.setup_url)
# Later: check whether they finished.status = client.connection_links.get(link.id)print(status.status) # "awaiting_human" … "completed"Once it’s connected, the call in step 1 includes that person’s busy time with no change to your code.
Only book from a complete answer
Section titled “Only book from a complete answer”Chronary keeps a copy of each person’s busy times and refreshes it in the background. If a copy is out of date, Chronary doesn’t guess. availability_state is something other than complete, slots is empty and warnings says why. Wait and ask again rather than book a time that might be taken:
if (result.availability_state !== 'complete') { console.warn(result.warnings.map((w) => w.message).join('; ')); // Try again in a minute, or ask the person to reconnect.}if result.availability_state != "complete": print("; ".join(w.message for w in result.warnings)) # Try again in a minute, or ask the person to reconnect.Step 3: Book it on every calendar
Section titled “Step 3: Book it on every calendar”Pick a slot, then add the meeting to each agent’s calendar and the room. If those calendars have prevent_overlaps on, a booking that clashes with something added in the meantime is refused with 409 event_conflict, and you can pick the next slot. The booking tutorial shows that retry loop.
const slot = result.slots[0];const start = new Date(slot.start);const end = new Date(start.getTime() + 60 * 60 * 1000);
const calendarIds = ['cal_sales', 'cal_support', 'cal_engineering', roomCalendarId];
for (const calendarId of calendarIds) { await chronary.events.create(calendarId, { title: 'Quarterly planning', start_time: start.toISOString(), end_time: end.toISOString(), metadata: { meeting: 'quarterly-planning' }, });}slot = result.slots[0]start = datetime.fromisoformat(slot.start.replace("Z", "+00:00"))end = start + timedelta(hours=1)
calendar_ids = ["cal_sales", "cal_support", "cal_engineering", room_calendar_id]
for calendar_id in calendar_ids: client.events.create( calendar_id, title="Quarterly planning", start_time=start.isoformat(), end_time=end.isoformat(), metadata={"meeting": "quarterly-planning"}, )The shared metadata value lets you find all copies later, to move or cancel them together.
Step 4: Let the agents agree
Section titled “Step 4: Let the agents agree”Sometimes one agent shouldn’t decide for everyone. Each participant may have its own rules and priorities. A scheduling proposal lets one agent offer a few times, and each participant accepts, declines or suggests another. When everyone has answered, the organizer resolves it and Chronary books the agreed time.
const MEETING_MS = 60 * 60 * 1000;const options = result.slots.slice(0, 3).map((s) => ({ start_time: s.start, end_time: new Date(new Date(s.start).getTime() + MEETING_MS).toISOString(),}));
const proposal = await chronary.scheduling.create({ title: 'Quarterly planning', organizer_agent_id: 'agt_sales', participant_agent_ids: ['agt_support', 'agt_engineering'], calendar_id: 'cal_sales', slots: options,});options = []for s in result.slots[:3]: start = datetime.fromisoformat(s.start.replace("Z", "+00:00")) options.append({ "start_time": start.isoformat(), "end_time": (start + timedelta(hours=1)).isoformat(), })
proposal = client.scheduling.create( title="Quarterly planning", organizer_agent_id="agt_sales", participant_agent_ids=["agt_support", "agt_engineering"], calendar_id="cal_sales", slots=options,)The multi-agent scheduling guide walks through responding, counter-offers and resolving.
With MCP
Section titled “With MCP”Agents connected through the MCP server do the same with the find_meeting_time tool. In Claude, for example: “Find an hour this week when Sales, Support and Engineering are all free.”
What you built
Section titled “What you built”Your agents can now find a time that suits all of them and the people behind them, without anyone seeing anyone else’s calendar, and book it everywhere safely.