← Back to Dashboard
Lab Exercise

Agent Calendar Integration

Give your AI agent "eyes" to see your schedule and automate daily briefings.

Objective: Connect a Python-based AI agent to your Google Calendar using a secure, read-only feed, and schedule it to run automatically.

Prerequisite: Google Account, VS Code, Python installed.


šŸ“… Mission 1: The Secret Door

To let an agent read your calendar without giving it full password access, we use the "Secret Address in iCal format." This is a read-only door to your schedule.

Step 1: Get the URL

  1. Open Google Calendar in your browser.
  2. In the left sidebar, find your calendar (e.g., "Work"). hover and click the three dots (ā‹®).
  3. Select Settings and sharing.
  4. Scroll down to the bottom to find the section Integrate calendar.
  5. Find the field Secret address in iCal format.
  6. Copy this URL (it ends in .ics).
Warning: Treat this URL like a password. Anyone who has it can see your private event details.

šŸ Mission 2: The Reader Agent

Now we will write a Python script that uses this URL to check your day.

Step 1: Install Libraries

Open your terminal and install the requests and icalendar libraries:

pip install requests icalendar pytz

Step 2: The Script

Create a file named check_calendar.py and paste the following code. replace YOUR_ICAL_URL_HERE with the URL you copied.

import requests
from icalendar import Calendar
from datetime import datetime, timedelta
import pytz

# CONFIGURATION
ICAL_URL = "YOUR_ICAL_URL_HERE"
MY_TIMEZONE = pytz.timezone('America/New_York') # Change to your timezone

def get_todays_events():
    print("ā³ Fetching calendar...")
    try:
        response = requests.get(ICAL_URL)
        response.raise_for_status()
        cal = Calendar.from_ical(response.content)
    except Exception as e:
        print(f"āŒ Error fetching calendar: {e}")
        return

    today = datetime.now(MY_TIMEZONE).date()
    print(f"\nšŸ“… Events for {today}:")
    
    found_event = False
    for component in cal.walk():
        if component.name == "VEVENT":
            start = component.get('dtstart')
            summary = component.get('summary')
            
            # Handle different date types (all-day vs specific time)
            if hasattr(start.dt, 'date'):
                event_date = start.dt.date()
            else:
                event_date = start.dt
                
            if event_date == today:
                found_event = True
                # Format time if valid
                if hasattr(start.dt, 'strftime'):
                    time_str = start.dt.astimezone(MY_TIMEZONE).strftime("%I:%M %p")
                else:
                    time_str = "All Day"
                    
                print(f" - [{time_str}] {summary}")

    if not found_event:
        print("āœ… No events found for today!")

if __name__ == "__main__":
    get_todays_events()

Run the script in your terminal:

python check_calendar.py

āš™ļø Mission 3: Automating the Agent

An agent isn't useful if you have to manually run it. Let's schedule it to run every morning automatically.

šŸ–„ļø Windows: Task Scheduler

Windows has a built-in tool called Task Scheduler.

  1. Press Win + S and search for Task Scheduler.
  2. In the right panel, click Create Basic Task...
  3. Name: "Morning Agent Brief".
  4. Trigger: Daily -> Recur every 1 day -> Set time (e.g., 8:00 AM).
  5. Action: Start a program.
  6. Program/script: Type python (or the full path to python.exe).
  7. Add arguments: Type the full path to your script (e.g., "C:\Users\You\check_calendar.py").
  8. Finish.

Pro Tip: To run this in the background, use "Create Task" instead and select "Run whether user is logged on or not".

šŸŽ Mac: Cron Automation

On macOS, the terminal tool cron is the standard for scheduling.

  1. Open Terminal.
  2. Type crontab -e (this opens the edit mode).
  3. Press i to insert text.
  4. Add this line to run at 8:00 AM daily:
0 8 * * * /usr/bin/python3 /Users/yourname/check_calendar.py >> /tmp/calendar.log 2>&1
  1. Press Esc, then type :wq and hit Enter to save.

This tells the system: "At minute 0 of hour 8, every day, run python3 on this file."