Project 4: The Executive Calendar Optimizer (NLP to Action)
Project 4: The Executive Calendar Optimizer (NLP to Action)
Build an assistant that converts natural language scheduling requests into safe, auditable Google Calendar operations using function calling and guardrails.
Quick Reference
| Attribute | Value |
|---|---|
| Difficulty | Level 3: Advanced |
| Time Estimate | 20โ30 hours |
| Language | Python (Alternatives: TypeScript, Swift) |
| Prerequisites | OAuth, REST APIs, JSON schema, basic concurrency, good prompt discipline |
| Key Topics | tool/function calling, idempotency, safety confirmations, planning, constraint solving |
1. Learning Objectives
By completing this project, you will:
- Implement function calling to bridge LLM โthinkingโ to API โdoingโ.
- Build safe calendar tools (list/create/update/delete) with audit logs.
- Design a planning loop (ReAct-style) that asks clarifying questions and confirms destructive actions.
- Encode scheduling constraints (working hours, travel buffers, focus blocks) and resolve conflicts.
- Make operations deterministic and reversible (dry-run + diff preview).
2. Theoretical Foundation
2.1 Core Concepts
- Function calling / tools: The model selects a tool and produces structured args; your code executes the call and returns an observation.
- Agent loop (Reason โ Act โ Observe): Multi-step tasks require iterative planning, not single-shot completion.
- Safety in agents:
- โRead-only by defaultโ
- โExplicit confirmation before mutationโ
- โLeast privilege toolsโ
- โAudit log for every actionโ
- Idempotency: Calendar updates must not duplicate or repeatedly move events if a retry happens.
- Constraint reasoning: Scheduling is a constrained optimization problem (availability, conflicts, priorities, time zones).
2.2 Why This Matters
This is the transition from โchatbotโ to โassistantโ. If the system can safely modify your calendar, it can safely modify many other systems (tickets, tasks, files) with the same patterns.
2.3 Common Misconceptions
- โThe model should directly call update_event.โ It should plan first, and ask clarifying questions when ambiguous.
- โIf tools exist, the model will always use them correctly.โ Tool schemas and guardrails determine reliability.
- โCalendar operations are easy.โ Time zones, recurring events, and partial updates create subtle bugs.
3. Project Specification
3.1 What You Will Build
A conversational interface (CLI or web) where users can say:
- โIโm too busy on Tuesday, move all my morning meetings to the afternoon.โ
- โFind a 45-minute slot for the gym this week, but not after 6pm.โ
- โBlock two hours of focus time every weekday morning.โ
The assistant:
- Fetches relevant events
- Proposes a plan
- Shows a before/after diff
- Requests confirmation
- Applies changes with tool calls
3.2 Functional Requirements
- Tools:
list_events,create_event,update_event,delete_event,check_availability. - Clarifications: ask when the request is underspecified (which Tuesday? which calendar?).
- Dry-run: support a mode that only proposes changes.
- Diff preview: show what will change (event IDs, titles, start/end).
- Confirmation gates: required for delete and large batch moves.
- Safety policies: donโt move meetings with VIP attendees unless confirmed; never delete without explicit user โyesโ.
3.3 Non-Functional Requirements
- Correctness: no accidental duplication; respect recurring event rules.
- Security: OAuth tokens stored securely; least privileges.
- Auditability: log each tool call + result (without sensitive tokens).
- Latency: minimize API calls; cache list_events results during a turn.
3.4 Example Usage / Output
User: Move my 10 AM yoga to 3 PM on Thursday.
Assistant: I found โYoga Classโ on Thu 10:00โ11:00. 15:00โ16:00 is free.
Assistant: Proposed change:
- Update evt_abc123: Thu 10:00โ11:00 โ Thu 15:00โ16:00
Confirm? (yes/no)
4. Solution Architecture
4.1 High-Level Design
โโโโโโโโโโโโโโโโ user msg โโโโโโโโโโโโโโโโโโ tool call โโโโโโโโโโโโโโโโ
โ Chat UI โโโโโโโโโโโโโโถโ Agent Orchestr. โโโโโโโโโโโโโโโถโ Calendar Toolsโ
โโโโโโโโโโโโโโโโ โ (plan+policy) โโโโโโโโโโโโโโโโ (API wrapper) โ
โโโโโโโโโฌโโโโโโโโโ result โโโโโโโโโฌโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Diff + Confirm โ โ Audit Log โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
4.2 Key Components
| Component | Responsibility | Key Decisions |
|---|---|---|
| Calendar client | Google Calendar API wrapper | strict types, idempotent updates |
| Tool schemas | JSON schemas + descriptions | clarity beats cleverness |
| Policy engine | safety constraints | explicit confirmations, VIP rules |
| Planner | interpret intent, sequence tools | ReAct loop with max steps |
| Diff engine | compute before/after | make changes reviewable |
4.3 Data Structures
from dataclasses import dataclass
@dataclass(frozen=True)
class CalendarEvent:
id: str
title: str
start_iso: str
end_iso: str
attendees: list[str]
calendar_id: str
@dataclass(frozen=True)
class ProposedChange:
kind: str # "update" | "create" | "delete"
event_id: str | None
before: CalendarEvent | None
after: CalendarEvent | None
4.4 Algorithm Overview
Key Algorithm: safe scheduling
- Parse intent and extract constraints (date range, time window, duration).
- Retrieve candidate events and availability.
- Propose a plan and compute diffs.
- Ask for confirmation if needed.
- Apply changes with idempotent tool calls; record audit log.
Complexity Analysis:
- Time: O(number_of_API_calls) (dominant)
- Space: O(number_of_events_in_scope)
5. Implementation Guide
5.1 Development Environment Setup
python -m venv .venv
source .venv/bin/activate
pip install pydantic python-dotenv rich
5.2 Project Structure
calendar-optimizer/
โโโ src/
โ โโโ cli.py
โ โโโ agent.py
โ โโโ policy.py
โ โโโ diff.py
โ โโโ tools/
โ โ โโโ calendar_tools.py
โ โโโ storage/
โ โโโ audit_log.sqlite
โโโ README.md
5.3 Implementation Phases
Phase 1: Read-only assistant (5โ7h)
Goals:
- Authenticate and list events.
Tasks:
- Implement
list_eventsandcheck_availability. - Build a CLI that can answer โWhatโs on my calendar tomorrow?โ
Checkpoint: Read-only queries work reliably with correct time zones.
Phase 2: Write operations + confirmation gates (7โ10h)
Goals:
- Create/update/delete safely.
Tasks:
- Implement
create_event/update_event/delete_event. - Add diff preview and explicit confirmation.
- Add audit logging and idempotency keys for retries.
Checkpoint: You can move a single event with a clear diff and safe confirmation.
Phase 3: Planning + constraints (8โ13h)
Goals:
- Handle multi-step requests and conflicts.
Tasks:
- Implement a bounded agent loop (max steps, stop conditions).
- Encode user constraints (working hours, buffers, do-not-move tags).
- Add clarifying questions for ambiguity.
Checkpoint: Multi-event transformations (e.g., โmove morning meetingsโ) behave predictably.
5.4 Key Implementation Decisions
| Decision | Options | Recommendation | Rationale |
|---|---|---|---|
| Confirmation | per-event vs batch | batch + per-event override | safe but not annoying |
| Recurring events | expand instances vs series edits | start with instances | reduces accidental mass edits |
| Planner | single-shot vs loop | bounded loop | handles ambiguity and failures |
6. Testing Strategy
6.1 Test Categories
| Category | Purpose | Examples |
|---|---|---|
| Unit | policy/diff | VIP rules, diff formatting, time parsing |
| Integration | calendar tools | mock API responses, idempotency retries |
| Scenario | end-to-end | โmove meetingโ, โblock focusโ, โresolve conflictโ |
6.2 Critical Test Cases
- Time zone correctness: 10am local stays 10am local after update.
- Retry safety: repeating an update doesnโt create duplicates.
- Confirmation required: delete never happens without explicit โyesโ.
7. Common Pitfalls & Debugging
| Pitfall | Symptom | Solution |
|---|---|---|
| Time zone drift | events shift by hours | store time zone explicitly; test in multiple zones |
| Over-broad scope | assistant edits wrong day | always confirm date range; show scope summary |
| Recurrence surprises | series changes unexpectedly | avoid series edits initially; require confirmation |
| Tool misuse | model calls delete unnecessarily | tighten tool descriptions + policy blocks |
Debugging strategies:
- Log the agent plan, tool calls, and final diff.
- Implement a dry-run mode and use it by default while iterating.
8. Extensions & Challenges
8.1 Beginner Extensions
- Add โbusy summaryโ and weekly heatmap output.
- Add tagging rules (donโt move โmedicalโ, โ1:1โ by default).
8.2 Intermediate Extensions
- Add a simple optimizer (maximize contiguous focus blocks).
- Add โtravel time buffersโ between locations.
8.3 Advanced Extensions
- Integrate tasks (create TODOs for meetings).
- Add natural language recurring rules (โevery other Fridayโ).
9. Real-World Connections
9.1 Industry Applications
- Scheduling assistants and meeting coordinators.
- Operations automation (safe tool use patterns).
- Calendar analytics for productivity tooling.
9.3 Interview Relevance
- Function calling patterns, tool schemas, and safety guardrails.
- Idempotency and audit logs in automation systems.
10. Resources
10.1 Essential Reading
- Generative AI with LangChain (Ben Auffarth) โ tool use patterns (Ch. 4)
- AI Engineering (Chip Huyen) โ agentic workflows and safety (Ch. 6)
10.3 Tools & Documentation
- Google Calendar API docs (events.list, events.patch)
- OAuth best practices (token storage, scopes)
10.4 Related Projects in This Series
- Previous: Project 3 (email triage) โ structured outputs and policy
- Next: Project 6 (tool routing) โ generalized multi-tool assistants
11. Self-Assessment Checklist
- I can explain function calling and why schemas matter.
- I can prove an operation is safe (dry-run + diff + confirm).
- I can explain my idempotency strategy for retries.
- I can debug a misbehaving agent using tool-call logs.
12. Submission / Completion Criteria
Minimum Viable Completion:
- Read-only chat that can list events and check availability
- Move a single event safely with confirmation and diff
Full Completion:
- Multi-step planning with clarifying questions
- Batch edits with safety policies and audit logs
Excellence (Going Above & Beyond):
- Constraint-aware optimization (focus time, buffers) with measurable improvements
This guide was generated from project_based_ideas/AI_PERSONAL_ASSISTANTS_MASTERY.md. For the complete sprint overview, see project_based_ideas/AI_PERSONAL_ASSISTANTS_MASTERY/README.md.