Productivity Coaching with Gemini and Google Calendar
Source notebook
Repo path:
gemini/use-cases/productivity/productivity_coaching_with_google_calendar.ipynb· Open on GitHub · intermediate
Uses Gemini 2.5 Flash with Google Calendar data to provide productivity coaching and schedule recommendations.
Summary
This notebook teaches how to use Gemini as a productivity coach with the Google Gen AI SDK on Vertex AI. It first analyzes sample calendar screenshots from Cloud Storage, then registers a Python function backed by the Google Calendar API as a Gemini tool. The end-to-end workflow covers authentication, client setup, system instructions, multimodal image analysis, function calling, and personalized calendar-based coaching.
Key code patterns
Create Vertex AI GenAI client
client = genai.Client(
vertexai=True,
project=PROJECT_ID,
location=LOCATION,
)Initializes the Google Gen AI SDK client for Vertex AI using project and region settings.
Load image from Cloud Storage
calendar_image_part = Part.from_uri(
file_uri=image_file_uri,
mime_type="image/png",
)Shows how to pass a Cloud Storage image URI into Gemini for multimodal schedule analysis.
Use system instructions
config=GenerateContentConfig(
system_instruction=system_instruction,
)Constrains Gemini to act as a productivity coach with explicit analysis criteria.
Register Calendar API function as tool
response = client.models.generate_content(
model=MODEL_ID,
contents=prompt,
config=GenerateContentConfig(
system_instruction=system_instruction,
temperature=0.9,
tools=[get_next_n_calendar_events],
),
)Lets Gemini call a Python function that retrieves live Google Calendar events.
Retrieve upcoming calendar events
service = build("calendar", "v3")
events_result = service.events().list(
calendarId="primary",
timeMin=now,
maxResults=num_of_events,
singleEvents=True,
orderBy="startTime",
).execute()Uses the Google API Python client to fetch ordered upcoming events from the primary calendar.
Models & APIs used
- Models: gemini-2.5-flash
- APIs / services: Vertex AI, Google Calendar API, Cloud Storage
- SDKs / libraries:
google-genai,google-api-python-client
When to use this
Use this pattern when building a Gemini assistant that combines multimodal schedule analysis with live Google Workspace data through function calling.
Gotchas & caveats
- Requires an existing Google Cloud project with the Vertex AI API enabled.
- Google Calendar API must be enabled separately.
- Colab requires explicit user authentication.
- Calendar access uses ADC with cloud-platform and calendar.events.readonly scopes.
- Calendar credentials are stored in memory for the current session and require re-authorization after runtime termination.
- Google Workspace APIs have quotas, and specifying the project applies the correct quotas.
- get_next_n_calendar_events only accepts values from 1 to 250.
Best practices
- Use system instructions to define Gemini’s coaching role and analysis criteria.
- Start with sample calendar screenshots before connecting live user data.
- Request only readonly Calendar API access for event analysis.
- Validate tool input bounds before calling the Calendar API.
- Return a concise subset of event fields: summary, start, end, and status.
- Handle Calendar API HttpError and return an empty list on failure.
Related
- Concepts: Function Calling & Tools · Vision · Applied Use Cases
- Entities: Vertex AI · Google GenAI SDK · Cloud Storage · Function Calling · Gemini
- Area: Gemini Notebooks
- Best practices: Function Calling & Tools - Best Practices · Vision - Best Practices · Applied Use Cases - Best Practices