Badminton Court Booking Agent

Agentic AI Workflow with Code-as-Action Pattern - LLM generates and executes Python code

Python 3.8+ FastAPI Google Gemini 2.5 Flash TinyDB M5 Agentic Workflow Production Ready

Project Overview & Problem Statement

Challenge: Traditional booking systems require extensive development for business logic, validation rules, and edge cases. They're rigid, difficult to modify, and can't adapt to natural language requests or complex business rules without significant coding effort.

Solution: This project implements an agentic AI workflow where the LLM (Google Gemini 2.5 Flash) generates and executes Python code dynamically. Instead of hard-coded business logic, the AI agent interprets user requests, writes the necessary code, and executes it to perform bookings, cancellations, and queries - all while enforcing complex pricing rules and conflict detection.

Key Benefits

AI Capabilities & Technical Innovation

Agentic AI Workflow

Implements the M5 Agentic Workflow pattern where the LLM generates executable Python code as actions. Each user request triggers code generation, validation, and execution in a secure sandbox environment.

24/7 Autonomous Operations

Operates independently without human oversight, handling bookings, cancellations, availability checks, and complex queries through natural language understanding and code generation.

Dynamic Time-Based Pricing

Implements four pricing tiers based on time of day and day of week: Daytime (6am-6pm), Nighttime (6pm-6am), Weekday, Weekend - all managed through AI-generated code logic.

Automatic Conflict Detection

AI-generated validation code checks for booking conflicts across 12 courts, validates Malaysian IC numbers (format: YYMMDD-PB-###G), and enforces business rules automatically.

AI Processing Pipeline (M5 Agentic Workflow)

Technical Architecture & Implementation

Backend Architecture

Python 3.8+ FastAPI Framework Google Gemini 2.5 Flash TinyDB (JSON Database) Async/Await

AI & Agentic Technologies

M5 Agentic Workflow Code-as-Action Pattern Dynamic Code Generation Natural Language Processing Context-Aware AI

Deployment & Infrastructure

Google Cloud Run Docker Containers CI/CD Pipelines Auto Scaling Persistent Storage

System Architecture

Agentic AI Workflow:

Dynamic Pricing System

Time Period Weekday Rate (RM/hour) Weekend Rate (RM/hour)
Daytime (6:00 AM - 6:00 PM) RM 80 RM 90
Nighttime (6:00 PM - 6:00 AM) RM 100 RM 120

Malaysian Context Features

API Endpoints & Usage Examples

Core API Endpoints

POST /book - Books a badminton court with automatic conflict detection - Calculates pricing based on time and day - Validates Malaysian IC numbers POST /cancel - Cancels existing booking by IC number and court - Refund processing and availability update GET /availability - Checks court availability for specific date/time - Returns available courts and pricing GET /bookings - Lists all bookings with filters (date, court, IC) - Supports pagination and sorting

Example Natural Language Requests

"Book court 5 for tomorrow at 7 PM for 2 hours. IC: 850715-08-1234" "Cancel my booking for court 3 on 2024-12-25" "What courts are available this Saturday evening?" "Show me all bookings for IC number 920315-10-5678" "I want to book court 1 from 8am to 10am on Monday"

Code-as-Action Example

When a user says "Book court 5 tomorrow at 7 PM", the LLM generates code like:

from datetime import datetime, timedelta from tinydb import TinyDB, Query # Calculate booking details booking_date = (datetime.now() + timedelta(days=1)).date() start_time = datetime.combine(booking_date, datetime.strptime("19:00", "%H:%M").time()) end_time = start_time + timedelta(hours=2) # Determine pricing is_weekend = booking_date.weekday() >= 5 is_nighttime = start_time.hour >= 18 or start_time.hour < 6 rate = 120 if (is_weekend and is_nighttime) else 100 if is_nighttime else 90 if is_weekend else 80 # Check conflicts and create booking # ... (conflict detection code) # ... (insert into database)

Development Setup & Installation Guide

Prerequisites

Quick Start Installation

# Clone the repository git clone https://github.com/lyven81/ai-project.git cd ai-project/projects/badminton-booking-agent # Create virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt # Set up environment variables cp .env.example .env # Add your Gemini API key to .env # Run the application uvicorn main:app --reload --port 8000

Environment Configuration

# Required API Configuration GEMINI_API_KEY=your_gemini_api_key_here # Application Settings PORT=8000 DATABASE_PATH=./data/bookings.json MAX_COURTS=12 DEBUG_MODE=false

Development Workflow

Deployment Options & Production Configuration

Google Cloud Run Deployment (Recommended)

# Build and deploy using Cloud Build gcloud builds submit --config cloudbuild.yaml # Direct deployment gcloud run deploy badminton-booking-agent \ --image gcr.io/PROJECT-ID/badminton-booking-agent \ --platform managed \ --region us-west1 \ --set-env-vars GEMINI_API_KEY=your_api_key \ --allow-unauthenticated

Alternative Deployment Methods

Production Optimizations

Performance Metrics & Business Impact

2-4s
Average Response Time
12
Courts Managed
24/7
Autonomous Operation
100%
Conflict Detection

Business Value Demonstration

Technical Performance

Key Innovations & Learning Outcomes

M5 Agentic Workflow Pattern

Technical Challenges Solved