Skip to content

Demonstration of Glean Agent for Google Calendar

Notifications You must be signed in to change notification settings

synedra/glean-demo

Repository files navigation

Glean Calendar Event Creator - Complete Implementation

This project demonstrates an end-to-end integration of Glean Agents with Google Calendar API, showcasing how to build custom actions, agents, and integrate them via a CLI tool.

🎯 Project Overview

What this does:

  • Takes natural language input from command line (e.g., "Schedule a meeting tomorrow at 2pm")
  • Calls Glean Agent API to process the request
  • Agent triggers custom Google Calendar action
  • Creates actual calendar event in Google Calendar
  • Returns confirmation to user

πŸ“ Project Structure

.
β”œβ”€β”€ README.md                           # This file
β”œβ”€β”€ IMPLEMENTATION_GUIDE.md             # Detailed step-by-step guide
β”œβ”€β”€ requirements.txt                    # Python dependencies
β”œβ”€β”€ calendar-action-spec.yaml           # OpenAPI spec for the custom action
β”œβ”€β”€ middleware_server.py                # Bridge between Glean and Google Calendar
└── glean_calendar_cli.py              # CLI client for invoking the agent

πŸš€ Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Set Up Google Calendar API

  1. Go to Google Cloud Console
  2. Create a project and enable Google Calendar API
  3. Create OAuth 2.0 credentials
  4. Download credentials as credentials.json

3. Configure Glean

  1. Log in to Glean: https://glean-sandbox.cloud.glean.com
    • User: pmmi@glean-sandbox.com
  2. Create the custom action (Admin Console > Platform > Actions)
  3. Create the agent (Admin Console > Platform > Agents)
  4. Get your API key (Admin Console > Platform > API Keys)

4. Run the Middleware (Optional)

python3 middleware_server.py

Then expose it with ngrok:

ngrok http 5000

5. Configure and Run CLI

Edit glean_calendar_cli.py and add your credentials:

GLEAN_API_KEY = "your-api-key"
AGENT_ID = "your-agent-id"

Run:

python3 glean_calendar_cli.py "Schedule a team meeting tomorrow at 2pm"

πŸ“– Documentation

For detailed implementation instructions, see IMPLEMENTATION_GUIDE.md

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   User Input    β”‚
β”‚  (CLI Command)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Glean Agents    β”‚
β”‚     API         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Glean Agent     β”‚
β”‚ (NL Processing) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Custom Action   β”‚
β”‚  (Middleware)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Google Calendar β”‚
β”‚      API        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Event Created βœ“ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎯 Key Components

1. OpenAPI Specification (calendar-action-spec.yaml)

Defines the interface for the custom action that Glean will call.

Key features:

  • Simple, flat parameter structure (no nested objects)
  • All fields are primitives (string, number, boolean)
  • Required vs. optional fields clearly marked
  • ISO 8601 datetime format for dates

2. Middleware Server (middleware_server.py)

Flask server that translates between Glean's simple format and Google Calendar's complex API.

Why middleware?

  • Handles format translation
  • Manages OAuth tokens
  • Provides better error handling
  • Easier to debug and log

3. CLI Client (glean_calendar_cli.py)

Python script that invokes the Glean Agent via API and displays results.

Features:

  • Command-line argument support
  • Interactive mode
  • Formatted output
  • Error handling

πŸ”§ Configuration

Environment Variables (Optional)

export GLEAN_API_KEY="your-api-key"
export GLEAN_AGENT_ID="your-agent-id"
export GOOGLE_OAUTH_TOKEN="your-google-token"

Glean Action Configuration

Trigger Conditions:

Creates calendar events in Google Calendar. Use when user wants to:
- Schedule a meeting
- Create a calendar event  
- Book time on calendar
- Add an appointment

Example Queries:

  • "Schedule a team meeting tomorrow at 2pm"
  • "Create a calendar event for project review next Tuesday"
  • "Book 30 minutes on my calendar for Friday at 10am"

πŸ§ͺ Testing

Test the Middleware

# Start server
python3 middleware_server.py

# Test health endpoint
curl http://localhost:5000/health

Test the CLI

# With inline message
python3 glean_calendar_cli.py "Schedule a meeting tomorrow at 2pm"

# Interactive mode
python3 glean_calendar_cli.py

Verify in Google Calendar

  1. Go to https://calendar.google.com
  2. Log in with pmmi@glean-sandbox.com
  3. Check for the created event

πŸ“ Example Usage

$ python3 glean_calendar_cli.py "Create a calendar event called 'Product Demo' tomorrow at 3pm for 45 minutes"

============================================================
πŸ“… Glean Calendar Agent CLI
============================================================

πŸ€– Sending request to Glean Agent...
πŸ“ Message: Create a calendar event called 'Product Demo' tomorrow at 3pm for 45 minutes

βœ… Agent Response:
I've created the calendar event "Product Demo" for tomorrow at 3:00 PM, 
lasting 45 minutes. The event has been added to your calendar successfully.

============================================================

πŸ› Troubleshooting

Common Issues

"Missing or invalid Authorization header"

  • Check your Google OAuth token is valid
  • Tokens expire after 1 hour by default

"Agent not found"

  • Verify AGENT_ID in CLI script
  • Ensure agent is deployed for API access

"Action not triggered"

  • Review trigger conditions
  • Use more explicit queries like "Create a calendar event..."

"Middleware not reachable"

  • Check ngrok is running
  • Verify server URL in OpenAPI spec

See IMPLEMENTATION_GUIDE.md for more details.

πŸŽ“ Key Concepts Demonstrated

  1. Custom Action Creation: Building actions with OpenAPI specs
  2. Agent Configuration: Setting up agents with proper triggers
  3. Third-Party Integration: Using Glean Agents API from external code
  4. OAuth Authentication: Handling Google OAuth flow
  5. Natural Language Processing: Converting user intent to structured data
  6. API Design: Creating clean, simple API interfaces

πŸš€ Next Steps

Enhancements

  • Add support for recurring events
  • Handle event updates and deletions
  • Add location and attendees support
  • Implement retry logic
  • Add comprehensive logging

Production Ready

  • Move secrets to environment variables
  • Add rate limiting
  • Implement error recovery
  • Add unit and integration tests
  • Deploy middleware to cloud platform

πŸ“š Resources

πŸ‘€ Author

Created for Glean Solutions Architect interview assignment.

Contact: pmmi@glean-sandbox.com

πŸ“„ License

This project is for demonstration purposes as part of the Glean interview process.


Need help? See the detailed IMPLEMENTATION_GUIDE.md or reach out with questions.

About

Demonstration of Glean Agent for Google Calendar

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages