Skip to content

Auro-rium/acali

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 Acali β€” Agentic Telegram Google Calendar Assistant

Python FastAPI LangGraph Vertex AI License: MIT


🧠 Overview

Acali is a lightweight agentic orchestration system that connects a Telegram bot to Google Calendar, powered by LangGraph, Vertex AI (Gemini), and FastAPI.
It enables natural-language scheduling, conflict resolution, and persistent user memory β€” forming a foundation for extendable Google Workspace automation.


✨ Key Features

  • πŸ—“οΈ Natural-language event creation (Gemini / Vertex AI)
  • βš™οΈ Agentic orchestration with LangGraph
  • ⚑ Conflict detection & auto-rescheduling (agent_flow/features_conflict.py)
  • πŸ” Secure Google OAuth2 with encrypted tokens (oauth_flow/agent.py)
  • 🧠 Per-user contextual memory (memory/manager.py)
  • 🌐 FastAPI webhook integration with Telegram
  • 🧩 Modular design β€” extendable to Gmail, Docs, Sheets, Drive

πŸ—‚οΈ Architecture Overview

Telegram Bot  <──>  FastAPI  <──>  LangGraph Agent  <──>  Vertex AI (Gemini)
       β”‚                     β”‚
       β”‚                     └── OAuth Flow + Storage
       β”‚                           β”œβ”€β”€ oauth_flow/agent.py
       β”‚                           β”œβ”€β”€ oauth_flow/routes.py
       β”‚                           β”œβ”€β”€ oauth_flow/storage.py
       β”‚                           └── oauth_flow/db.py
       β”‚
       └───> Telegram UX Layer
               β”œβ”€β”€ telegram_ux/ui.py
               └── telegram_ux/handlers.py

Memory Manager (persistent JSON)
 └── memory/manager.py, memory/store.py, memory/schema.py

Scheduling & Conflict Logic
 └── agent_flow/features_schedule.py, agent_flow/features_conflict.py

πŸ“ Project Structure

acali/
β”œβ”€β”€ main.py                          # Entry point - FastAPI + Telegram bot
β”œβ”€β”€ requirements.txt                 # Python dependencies
β”œβ”€β”€ readme.md                        # This file
β”‚
β”œβ”€β”€ web/                             # FastAPI web layer
β”‚   └── api.py                       # FastAPI app factory + webhook endpoints
β”‚
β”œβ”€β”€ telegram_ux/                     # Telegram bot interface
β”‚   β”œβ”€β”€ handlers.py                  # Command and message handlers
β”‚   └── ui.py                        # UI helpers and OAuth callback HTML
β”‚
β”œβ”€β”€ oauth_flow/                      # Google OAuth & Calendar integration
β”‚   β”œβ”€β”€ agent.py                     # OAuth agent (authorize, callback, revoke)
β”‚   β”œβ”€β”€ db.py                        # Sync SQLite token storage (encrypted)
β”‚   β”œβ”€β”€ storage.py                   # Async SQLAlchemy storage (optional)
β”‚   β”œβ”€β”€ google_calendar.py           # Calendar API CRUD operations
β”‚   β”œβ”€β”€ models.py                    # SQLAlchemy models
β”‚   β”œβ”€β”€ routes.py                    # OAuth routes (if using FastAPI router)
β”‚   β”œβ”€β”€ service.py                   # OAuth service helpers
β”‚   └── utils.py                     # Utility functions
β”‚
β”œβ”€β”€ agent_flow/                      # LangGraph agent orchestration
β”‚   β”œβ”€β”€ core.py                      # LLM setup (Vertex AI/Gemini)
β”‚   β”œβ”€β”€ calendar_agent.py            # Main calendar agent
β”‚   β”œβ”€β”€ calendar_chat_agent.py       # Context-aware chat agent
β”‚   β”œβ”€β”€ chat_agent.py                # General chat + routing
β”‚   β”œβ”€β”€ calendar_graph.py            # LangGraph workflow (if using)
β”‚   β”œβ”€β”€ intent.py                    # Intent classification
β”‚   β”œβ”€β”€ features_schedule.py         # Event scheduling logic
β”‚   β”œβ”€β”€ features_conflict.py         # Conflict detection & resolution
β”‚   β”œβ”€β”€ features_memory.py           # Event memory management
β”‚   └── features_utils.py            # Shared utilities
β”‚
└── memory/                          # Persistent user memory
    β”œβ”€β”€ manager.py                   # High-level memory API
    β”œβ”€β”€ store.py                     # JSON file storage
    └── schema.py                    # Pydantic models

🧩 Core Modules

Module Purpose
main.py Entry point β€” runs FastAPI and Telegram bot
web/api.py FastAPI + Telegram integration (create_fastapi_app)
oauth_flow/agent.py OAuth orchestration and token logic
oauth_flow/storage.py Async SQLAlchemy + Fernet encrypted storage
oauth_flow/db.py Sync SQLite token storage with encryption
telegram_ux/handlers.py Telegram bot commands (register)
telegram_ux/ui.py Telegram UI helpers and OAuth callback HTML
agent_flow/calendar_agent.py Main calendar agent with LLM-driven scheduling
agent_flow/calendar_chat_agent.py Context-aware calendar chat agent
agent_flow/chat_agent.py General chat agent and routing orchestrator
agent_flow/features_schedule.py Event scheduling and creation logic
agent_flow/features_conflict.py Conflict detection and alternative time finding
agent_flow/features_memory.py Event memory management for deletions
agent_flow/core.py Core LLM setup (Vertex AI/Gemini) and state definitions
agent_flow/intent.py Intent classification and timezone helpers
memory/manager.py Per-user memory management
memory/store.py JSON-based persistent storage
memory/schema.py Pydantic models for memory structure
oauth_flow/google_calendar.py Calendar API adapter (CRUD operations)

βš™οΈ Installation

git clone <repo-url> acali
cd acali

python -m venv venv
# On Windows:
venv\Scripts\activate
# On Linux/Mac:
source venv/bin/activate

pip install -r requirements.txt

πŸ”§ Configuration β€” .env

Variable Description
BOT_TOKEN Telegram bot token (required)
WEBHOOK_URL Public HTTPS URL for Telegram webhook (optional, for webhook mode)
FERNET_KEY / ENCRYPTION_KEY Symmetric key for encrypted tokens (required)
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET Google OAuth credentials (required)
GOOGLE_REDIRECT_BASE Redirect base URL (default: http://localhost:8000)
DB_PATH SQLite file path for OAuth tokens (default: .data/tokens.db)
DATABASE_URL Async SQLAlchemy database URL (default: sqlite+aiosqlite:///./oauth_flow.db)
GCP_PROJECT_ID Google Cloud Project ID for Vertex AI (required)
LOCATION Vertex AI location (default: us-central1)
GEMINI_MODEL Gemini model name (default: gemini-2.5-flash)
GEMINI_TEMPERATURE LLM temperature (default: 0.3)
DEFAULT_TIMEZONE Default user timezone (default: Asia/Kolkata)

🧱 Database Setup

  • Sync SQLite (oauth_flow/db.py) initializes automatically on import via ensure_connection().
  • Async SQLAlchemy (oauth_flow/storage.py) requires explicit initialization in main.py startup event (already configured).

The application uses two database systems:

  1. SQLite (oauth_flow/db.py) - For encrypted OAuth token storage (sync)
  2. Async SQLAlchemy (oauth_flow/storage.py) - For OAuth session management (optional, if using PKCE flow)

πŸš€ Running Locally

python main.py
  • Runs FastAPI and Telegram Bot.
  • If using webhooks, set WEBHOOK_URL and expose via ngrok for testing.

πŸ”‘ OAuth Flow

  • /connect command triggers Google OAuth authorization.
  • Redirect + token storage handled by:
  • Tokens are encrypted and stored securely.

🧠 LangGraph + Vertex AI

Acali uses LangGraph to orchestrate the agent’s reasoning chain β€” managing natural-language interpretation, conflict resolution, and contextual scheduling.

  • LangGraph: Controls multi-step reasoning and dialogue flow.
  • Vertex AI: Executes semantic tasks (intent detection, date extraction, conflict explanation).
  • Memory Layer: Stores user context persistently to refine scheduling over time.

πŸ”„ Extendability β€” Google Workspace Integration

Acali’s modular design allows effortless extension to other Google tools:

Extension Example Use
Docs Generate meeting summaries
Sheets Visualize schedule metrics
Gmail Send confirmation emails
Drive Store contextual data or logs

Each extension can plug into the LangGraph workflow as a reasoning node.


πŸ›‘οΈ Development Notes

  • Keep .env and encryption keys private.
  • For local testing, stub LLM responses to reduce latency.
  • Each subsystem (OAuth, Telegram, FastAPI, Memory) is self-contained and testable.

πŸ”§ Troubleshooting

Common Issues

  1. "ENCRYPTION_KEY not set" error

    • Generate a key: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
    • Add to .env: ENCRYPTION_KEY=<generated_key>
  2. "GCP_PROJECT_ID not set" error

    • Ensure you have a Google Cloud Project with Vertex AI enabled
    • Add to .env: GCP_PROJECT_ID=your-project-id
  3. OAuth callback fails

    • Verify GOOGLE_REDIRECT_BASE matches your server URL
    • Ensure redirect URI is configured in Google Cloud Console
    • Check that WEBHOOK_URL (if using webhooks) is publicly accessible
  4. Database initialization errors

    • Ensure DB_PATH directory exists or is writable
    • Check that DATABASE_URL is correct for async SQLAlchemy
    • Verify FERNET_KEY is set correctly
  5. Import errors

    • Ensure all dependencies are installed: pip install -r requirements.txt
    • Check that virtual environment is activated
    • Verify Python version is 3.9+
  6. Telegram bot not responding

    • Verify BOT_TOKEN is correct
    • Check if using webhook mode, ensure WEBHOOK_URL is set
    • Check logs for connection errors
  7. LLM/Vertex AI errors

    • Verify Google Cloud credentials are set up
    • Check that Vertex AI API is enabled in your GCP project
    • Ensure billing is enabled for the project
    • Verify model name (GEMINI_MODEL) is valid

🀝 Contributing

MIT-licensed.
Contributions via issues or pull requests are welcome!


πŸ“œ License

MIT License
Copyright (c) 2025

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...

[Full license included in LICENSE file.]


🧭 Future Vision

Acali can evolve into a unified personal agentic framework β€”
bridging conversational interfaces (Telegram, WhatsApp, web) with
Google Workspace and Vertex AI reasoning, forming the base for
next-generation productivity agents

About

Agentic Telegram Bot system that lets students manage Google Calendar through LLM seamlessly.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages