Give your AI agent a calendar
An AI agent that schedules, follows up or runs long tasks needs somewhere to keep track of time. With Chronary, the agent gets a calendar of its own through an API. You don’t borrow a person’s Google account, and there’s no OAuth to set up.
In this tutorial you will:
- Create an agent and a calendar for it.
- Add an event and read the calendar back.
- Share the calendar with a person, so it shows up in their calendar app.
Everything here works on the Free plan.
Before you start
Section titled “Before you start”- A Chronary account and an API key (
chr_sk_…). Sign up and copy the key the console shows you. If you lost it, create a new one under API keys. - Node.js 18+ or Python 3.10+.
Install the SDK and put your key in an environment variable:
npm install @chronary/sdkexport CHRONARY_API_KEY=chr_sk_your_key_herepip install chronaryexport CHRONARY_API_KEY=chr_sk_your_key_hereBoth SDKs read CHRONARY_API_KEY from the environment, so the code below never contains the key.
Step 1: Create the agent and its calendar
Section titled “Step 1: Create the agent and its calendar”Every calendar belongs to an agent. Create the agent first, then a calendar in the time zone the agent works in.
Set prevent_overlaps to true. The calendar then refuses any event that would overlap one it already has, even when several requests arrive at once. Your agent can’t double-book itself.
import { Chronary } from '@chronary/sdk';
const chronary = new Chronary();
const agent = await chronary.agents.create({ name: 'Scheduling Assistant', type: 'ai', description: 'Books and tracks meetings',});
const calendar = await chronary.calendars.create({ agentId: agent.id, name: 'Work', timezone: 'America/New_York', prevent_overlaps: true,});
console.log(agent.id, calendar.id); // agt_… cal_…from chronary import Chronary
client = Chronary()
agent = client.agents.create( name="Scheduling Assistant", type="ai", description="Books and tracks meetings",)
calendar = client.agents.calendars.create( agent.id, name="Work", timezone="America/New_York", prevent_overlaps=True,)
print(agent.id, calendar.id) # agt_… cal_…Save both IDs. Your agent uses the calendar ID for everything that follows.
Step 2: Add an event
Section titled “Step 2: Add an event”Times are ISO 8601. Send them in UTC or with an offset. This adds a 30-minute call tomorrow at the current time of day:
const start = new Date(Date.now() + 24 * 60 * 60 * 1000);const end = new Date(start.getTime() + 30 * 60 * 1000);
const event = await chronary.events.create(calendar.id, { title: 'Intro call with Sam', description: 'Booked by the scheduling assistant', start_time: start.toISOString(), end_time: end.toISOString(), reminders: [15],});
console.log(event.id, event.status); // evt_… confirmedfrom datetime import datetime, timedelta, timezone
start = datetime.now(timezone.utc) + timedelta(days=1)end = start + timedelta(minutes=30)
event = client.events.create( calendar.id, title="Intro call with Sam", description="Booked by the scheduling assistant", start_time=start.isoformat(), end_time=end.isoformat(), reminders=[15],)
print(event.id, event.status) # evt_… confirmedreminders: [15] asks for a reminder 15 minutes before the start. If you add a webhook, your agent gets an event.reminder call at that moment, plus event.started and event.ended. The agent doesn’t have to poll the clock.
Step 3: Read the calendar
Section titled “Step 3: Read the calendar”Before the agent plans its day, it lists what’s coming up:
const weekAhead = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
for await (const e of chronary.events.list({ calendarId: calendar.id, start_after: new Date().toISOString(), start_before: weekAhead.toISOString(),})) { console.log(e.startTime, e.title);}now = datetime.now(timezone.utc)
for e in client.events.list( calendar.id, start_after=now.isoformat(), start_before=(now + timedelta(days=7)).isoformat(),): print(e.start_time, e.title)Step 4: Share the calendar with a person
Section titled “Step 4: Share the calendar with a person”Every calendar has a private iCal feed URL. Anyone with the URL can subscribe to it in Google Calendar, Outlook or Apple Calendar and see the agent’s events next to their own.
console.log(calendar.ical_url);print(calendar.ical_url)The iCal feeds guide shows how to subscribe in each calendar app.
What you built
Section titled “What you built”Your agent now has a calendar that it owns, that can’t be double-booked, and that people can see. From here: