AI Tool Use - A Calender Assistant (Difficulty: 4)
-
Introduction
Welcome to this tutorial on building an AI-powered calendar assistant! This project is a great example of how AI tools can be extended with new abilities — allowing them to solve more complex, real-world problems.
🧠 What’s This All About?
Large language models (LLMs), cannot remember information across different sessions — they can only “remember” the messages within the current chat session. That’s a big limitation because most apps need to store and recall information over time. Think about a calendar app: it needs to store all your events so you can see them later!To work around this limitation, we’ll use Google Sheets to store data. Then we’ll teach the AI how to interact with that data to manage a user’s calendar.
By the end of this project, your app will look like this:
This tutorial is divided into two main parts:
- Part 1: Set up a basic AI chat app
- Part 2: Teach the AI how to manage the user’s calendar using Google Sheets
🧩 Part 1 - Setting up the chat app
Step 1 - Remix the Starter Project
Start by remixing this template, which gives you a basic chat app to build on. We’ll add new logic to it step by step.
play.creaticode.com/projects/682dad154dba4796824af2a6
Step 2 - Prepare the Google Sheet
We’ll use a Google Sheet to store all calendar events. This approach is free, easy to use, and simple to review.
Here’s what you need to do (or ask your teacher/guardian to help):
- Create a new Google Sheet
- Set its sharing settings so that “anyone with the link” can edit
- Copy the sheet’s link
If you can’t create your own Google Sheet, you can use this pre-made one:
https://docs.google.com/spreadsheets/d/1tH9J09laZNl94Qb1smO5LSmDwD_yzungb9d4lmkobxE/edit?usp=sharing
Then, in your app, store the sheet URL in a variable calledSheet URL
. You’ll use this later to tell the AI where the calendar lives.
Step 3 - Update the System Prompt
Next, we’ll give the AI a new role by updating its System Instruction.
This tells the AI what it’s supposed to do. For now, keep it simple and clear:
Step 4 - Customize the Welcome Message
Let’s make the welcome message match the AI’s new job.
Tip: You could make the AI generate a different welcome message every time, but that would slow things down.
Step 5 - Add a Tab for Each User
Because different users might use this app, we need a way to keep their data separate.
The solution: whenever a new user joins, we’ll create a new tab in the Google Sheet just for them. The tab name will be the user’s unique ID.
If the tab already exists, this block will do nothing — which is exactly what we want.
Step 6 - Get the Current Day of the Week
Here’s an important thing to remember: AI models do not know the current date or time on their own. You can test that like this:
That’s a problem when managing calendars! We’ll fix this by manually sending the current date and time to the AI.Let’s start with the day of the week:
-
First, create a new list “weekdays”:
-
Then, use the
current [day of week]
block to get today’s number, and use it to pick the correct item from your list:
For example, if today is Wednesday, the “current day of the week” block will return
4
, and item 4 in your list will be"Wednesday"
.
Step 7 - Get the Full Date and Time
We can also get the full date and time using the
current
block and combine them into a single string:
Step 8 - Send Time Info with Every User Message
Now we’ll attach the time information to each message we send to the AI model.
For example, if the user says “hi”, then what we actually send to the AI will be:hi (current time: Wednesday 05/21/2025 13:23:43 )
That way, the AI will know exactly when the message was sent!
You can now test it to make sure the AI sees the correct time:
🧩 Part 2 - Managing the Calendar with Google Sheets
Step 1 - Plan the Workflow for Adding a New Event
Our entire calendar lives in Google Sheets, yet the AI can’t touch that Sheet directly — it needs help from our helper code. Here’s a sample back‑and‑forth among the user, the AI, and the helper:
- User -> AI: I will have a haircut tomorrow at 4pm
- AI -> Helper: add a new event for [date] [time]
- Helper adds it to the Google Sheet
- Helper -> AI: event added successfully
- AI -> User: I have added the haircut to your calendar.
From the user’s perspective, the Sheet and helper code are invisible—the AI simply “gets it done.”Another way to think about it: the user speaks natural language, the helper speaks code, so the AI acts as the translator between them.
Step 2 - Define the “addEvent” Command
To teach the AI to use our helper, we need to define a new command “addEvent” in the system instruction:
You are an AI assistant that helps manage the user's calendar. ## Commands You can use the following tools to manage events through an external service: * To add a new event to the calendar, you can return this command, which will return its eventID: addEvent | [date] | [time] | [event description] ## Instructions * If you are using a command, then only return the one line of command and nothing else.
Notes:
-
We separated Commands and Instructions with
##
headers so the AI can “see” the sections clearly. -
The
addEvent
syntax uses pipes (|
) — easy for us to split into pieces later. -
The instruction forces the AI to output only the command line when needed — no extra chit‑chat.
Testing now shows the AI emitting
addEvent
lines automatically:
Step 3 - Standardize Date and Time Formats
The AI currently formats dates like 05/01/2025, which sorts poorly—
05/01/2025
appears “larger” than02/01/2026
. Times such as “3 p.m.” sort badly, too.Add two lines to the Instructions section to enforce sortable formats:
You are an AI assistant that helps manage the user's calendar. ## Commands You can use the following tools to manage events through an external service: * To add a new event to the calendar, you can return this command, which will return its eventID: addEvent | [date] | [time] | [event description] ## Instructions * If you are using a command, then only return the one line of command and nothing else. * Use yyyy.mm.dd date format, such as "2025.02.21" * Use hh:mm time format, such as "13:30"
Re‑run the app and confirm:
Step 4 - Intercept the “addEvent” command
Whenever we receive AI output, we’ll check if it begins with "addEvent " (note the trailing space). If so, we execute helper code in “handle add event”.
Step 5 - Extract the Parameters
The
addEvent
line has four parts separated by three pipes. Use the “part of” block to pick them apart and trim whitespace:
Step 6 - Read Data from Google Sheets
Our add‑event logic is:
- Read the user’s tab into a table called
events
. - Add the new event.
- Write the entire table back.
To start, we will read the sheet using a “read data” block:
In this block, we will use the “read from Google Sheet” block to read the first 10000 rows from this user’s tab, assuming there are less than 10000 events on the calendar:
Run this block and remove all the widgets (or save and reload the project), you will find the “events” table looks like this:
That’s because the new tab is still empty, so the column headers are missing. To fix that, we can define the columns whenever there are 0 rows in the table:
The first column “id” will be used to store the unique eventID.
Step 7 - Add the New Event
Generate a unique ID using row count + 1 (always unique) and prefix it with “E”. Then append a row:
Step 8 - Sort the Table
Since all the events have date and time, we should keep them sorted in the calendar. We will sort the rows by “time” first, then by “date”. This will ensure all events are sorted by date and then time:
Step 9 - Write Back to the Sheet
Overwrite the user’s tab with the updated table:
Step 10 - Report Success to the AI
Let the AI know the command succeeded and pass along the new
eventID
:
We clarify that this message is from addEvent, so the AI won’t mistake it for user input.Test by adding events:
…and confirm they appear in the Sheet:
Step 11 - Define the “removeEvent” Command
Next, let’s work on removing an evnet. We will still start with defining the command in the system instruction:
You are an AI assistant that helps manage the user's calendar. ## Commands You can use the following tools to manage events through an external service: * To add a new event to the calendar, you can return this command, which will return its eventID: addEvent | [date] | [time] | [event description] * To remove an existing event, after you have found its eventID, you can use this command: removeEvent | [eventID] ## Instructions * If you are using a command, then only return the one line of command and nothing else. * Use yyyy.mm.dd date format, such as "2025.02.21" * Use hh:mm time format, such as "13:30"
removeEvent
takes just one parameter — the event’s unique ID. If the AI doesn’t already know the ID, it must retrieve it using other commands first (those are defined later).
Step 12 - Intercept the “removeEvent” Command
Detect and handle it with a new block:
Step 13 - Extract the eventID
Pull the ID from the command string:
Step 14 - Find and Remove the Event
- Read the Sheet into
events
again. - Find the index of the row with the matching
eventID
. - Delete that row.
Step 15 - Clear and Rewrite the Sheet
Before we write the table back, we need to first clear the tab. The reason is that the table has one less row compared to the data in that tab, so if we simply write the table into that tab, there will be an extra duplicate row at the bottom.
Step 16 - Report Removal to the AI
Notify the AI so it can reply to the user:
Restart your program, add an event, then remove it. Double‑check the Sheet each time:
Step 17 - Define the “searchEvents” Command
Earlier, the AI already knew the eventID for the dentist appointment, so removing it was easy. But when an eventID is not in the chat context, the AI must search for the event first.
To keep things simple, we’ll let the AI specify one keyword. Our helper will search that word in the
description
column and return every matching event (with its eventID).Updated system instruction:
You are an AI assistant that helps manage the user's calendar. ## Commands You can use the following tools to manage events through an external service: * To add a new event to the calendar, you can return this command, which will return its eventID: addEvent | [date] | [time] | [event description] * To remove an existing event, after you have found its eventID, you can use this command: removeEvent | [eventID] * To search for existing events by a **single word**, use this command, which will return all events at that time with their eventIDs (use a generic word to get more likely matches): searchEvents | [keyword] ## Instructions * If you are using a command, then only return the one line of command and nothing else. * Use yyyy.mm.dd date format, such as "2025.02.21" * Use hh:mm time format, such as "13:30"
We instruct the AI to choose one broad word (e.g., “lunch” or “Jon”) so we’re more likely to find the right event—even if we return a few extras, the AI can sort them out.
Test it:
The AI should pick “lunch” or “Jon” as the word to search for.
Step 18 - Intercept the “searchEvents” Command
We will handle this new command using the block “handl search command”:
Step 19 - Extract the Search Word and Read the Data
Store the keyword in a variable called
search word
:
Step 20 - Iterate Through All Rows
Use a for‑loop to walk through each row in
events
, pulling out the description:
Step 21 - Build the Search Result
Create a variable called
search result
. Start it empty, and append every row whose description contains the keyword:
Step 22 - Send the Search Result to the AI
After the for-loop finishes, the “search result” will either be empty or filled with events. Either way, we will let the AI know the result, so it can generate the response to the user:
To test it, first add another lunch event to the Google Sheet with another person:Then, restart the app, and ask about the “lunch with Jon”:
Step 23 - Define the “findEvents” Command
Our final command,
findEvents
, grabs every event between two time points. Perfect for “Am I free next Wednesday morning?” or “What’s on my calendar this weekend?”Here is the updated system instruction with the “findEvents” command:
You are an AI assistant that helps manage the user's calendar. ## Commands You can use the following tools to manage events through an external service: * To add a new event to the calendar, you can return this command, which will return its eventID: addEvent | [date] | [time] | [event description] * To remove an existing event, after you have found its eventID, you can use this command: removeEvent | [eventID] * To search for existing events by a **single word**, use this command, which will return all events at that time with their eventIDs (use a generic word to get more likely matches): searchEvents | [keyword] * To find existing events inbetween 2 time points (they can be the same date or time), you can use this command, which will return all events within the given time interval: findEvents | [start date] | [start time] | [end date] | [end time] ## Instructions * If you are using a command, then only return the one line of command and nothing else. * Use yyyy.mm.dd date format, such as "2025.02.21" * Use hh:mm time format, such as "13:30"
Step 24 - Intercept the “findEvents” Command
We will handle this command using a new block called “handle find events”:
The “handle find events” block should be very similar to the “handle search events” block. Can you try to implement it before looking at the steps below?
Step 25 - Extract Parameters
We will first extract the 4 parameters:
Step 26 - Reading Events in a For-Loop
We will still use a for-loop, but this time, we will extract the
eventDate
andeventTime
from each row:
Step 27 - Skip Events Before the Start Date/Time
As we check out each row, if we find its date is earlier than the start date, or its time is earlier than the start time, then we will continue to the next row:
Step 28 - Stop After the End Date/Time
Because events are already sorted, once we reach a row after the end date/time, we can
break
the loop. Until then, add each valid row tosearch result
:
Step 29 - Send these events to the AI
After the for-loop completes, we will give the result list to the AI:
Now let’s test it. Suppose this is the calender:
The AI will be able to find all events for next week:
Step 30 - Refine the output
The reply above feels a little robotic. Let’s tweak the system prompt so the AI talks more like a human:
## Instructions * If you are responding to the user, then talk like a human * If you are sending a command, then only return the **single line** of command and nothing else. * Use yyyy.mm.dd date format in commands, such as "2025.02.21" * Use hh:mm time format in commands, such as "13:30"
Unfortunately, this sometimes makes the AI mix user responses with commands:
Fix: Apply the T.I.R.E. prompting method by adding an explicit Example to the end of the system instruction:## Example [User]: I need to go to Jon's birthday party this Saturday [You]: What time is the party? [User]: I think it is 2pm [You]: addEvent | 2025.05.31 | 14:00 | Jon's birthday party at 2 PM [Helper]: addEvent result: successfully added event with ID: E123 [You]: I have added Jon's birthday party to the calendar for May 30 at 2pm. [User]: So what's my schedule next week? [You]: findEvents | 2025.05.26 | 00:00 | 2025.06.01 | 23:59 [Helper]: findEvents result: E99|2025.05.28|18:00|gym class with friend at 6 PM E123|2025.05.31|14:00|Jon's birthday party at 2 PM [You]: Looks like you have a light schedule next week. You will be meeting with your friend for a gym class next Wednesday at 6, and you will also attend Jon's birthday party on Sunday at 2 o'clock.
Another problem that might appear in testing is that the AI sometimes think of “next week” as the “next 7 days”, rather than the next calendar week. This can be fixed by adding a new line in the “## Instructions” section:
* When the user refers to the next week, assume they mean the next calendar week, not the next 7 days.
Finally, we are getting a much more human-like response:
Here is a final demo:
Important Note:
When you release your app for other users, you shouldpublish
the project instead ofsharing
it. That is because if you share the project, any user can look inside it to acquire the URL of the Google Sheet, then they will be able to look at other users’ calendars.
Additional Challenges
For practice, here are some improvements you can make to this app:
- Multiple Commands:
- Users may combine requests (“My lunch with Jon is cancelled and schedule a dentist at 4 p.m. today”).
- Rescheduling should trigger a
removeEvent
followed by anaddEvent
.
- Multiple Search Keywords:
- Allow two or three keywords for
searchEvents
. - “Lunch with Jon” could search for “Jon” and “lunch.”
- Allow two or three keywords for
- Remove Past Events:
- When the app starts, delete events more than one month old to keep the Sheet tidy.
-
Recurring Events (advanced):
- Extend
addEvent
with a fifth parameter,interval
(e.g., “weekly,” “daily”). - Add an
interval
column to the Sheet. - When
interval
is present, auto‑add the event for the next six months. - On startup, scan for recurring events and extend them six months into the future.
- Extend
-
info-creaticode