Skip to content

Teacher's Aide: A GenAI-powered application to help teachers built with Auth0 and LlamaIndex

License

Notifications You must be signed in to change notification settings

auth0-samples/auth0-teachersaide

Repository files navigation

Auth0 Teacher's Aide

A teacher assistant application powered by LlamaIndex and secured with Auth0 for AI Agents. This application demonstrates how to implement secure third-party tool calling with LLMs, allowing teachers to interact with student data and send emails on their behalf.

Overview

The Teacher's Aide application serves as an AI-powered assistant for educators. It provides a chat-like interface where teachers can:

  • List and analyze teaching classes
  • View student details and performance
  • Check student grades and progress
  • Send motivational or warning emails to students (via third-party Gmail integration)
  • Get insights about student performance and recommendations for improvement

The application showcases two types of tool calling:

  • System-level tool calling: The application accesses internal student data using its own credentials
  • User-level tool calling: The application sends emails on behalf of the authenticated teacher using OAuth 2.0 and Auth0's Token Vault

Features

  • ๐Ÿ” Secure Authentication: Auth0 integration with Google OAuth for seamless login
  • ๐Ÿ“Š Student Analytics: View and analyze student performance data
  • ๐Ÿ“ง Email Integration: Send emails to students via Gmail API using Token Vault
  • ๐Ÿค– AI-Powered Insights: LlamaIndex-powered agent for intelligent student analysis
  • ๐Ÿ›ก๏ธ Token Security: Secure token management with Auth0 Token Vault
  • ๐Ÿ’ฌ Chat Interface: Interactive web-based chat interface

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/auth0/auth0-teachersaide cd auth0-teachersaide
  2. Install dependencies using Poetry

    poetry install
  3. Set up environment variables

    Copy the sample environment file:

    cp .env.sample .env

    Fill in the required values in .env:

    # Auth0 Configuration AUTH0_DOMAIN="YOUR_AUTH0_DOMAIN" AUTH0_CLIENT_ID="YOUR_AUTH0_CLIENT_ID" AUTH0_CLIENT_SECRET="YOUR_AUTH0_CLIENT_SECRET" APP_SECRET_KEY="YOUR_32_BYTE_SECRET_KEY"# OpenAI Configuration OPENAI_API_KEY="YOUR_OPENAI_API_KEY"

    Generate a secure app secret key:

    openssl rand -hex 32

Auth0 Setup

1. Create Auth0 Application

  1. Go to your Auth0 Dashboard
  2. Create a new Regular Web Application named "Teacher Assistant"
  3. Configure the application settings:
    • Allowed Callback URLs: http://localhost:8000/auth/callback
    • Grant Types: Enable "Token Exchange (Federated Connection)" in Advanced Settings

2. Configure Google Social Connection

  1. Set up Google OAuth integration following this documentation
  2. Enable the following Google permissions:
    • Offline Access
    • Gmail.Send
  3. Enable Token Vault for the google-oauth2 connection in Authentication โ†’ Social

3. Connect Application to Google

  1. In your application settings, go to the Connections tab
  2. Enable the google-oauth2 connection
  3. Disable any other connections

Running the Application

  1. Start the development server

    poetry run uvicorn teacher_assistant.main:app --reload
  2. Access the application

    Open your browser and navigate to http://localhost:8000

  3. Login and test

    You'll be redirected to Auth0's Universal Login. Sign in with your Google account to access the teacher interface.

Usage

Basic Interactions

Once logged in, you can interact with the AI assistant using natural language. Try these example prompts:

  • "How are my students doing this semester?"
  • "Show me details about student [name]"
  • "List all my teaching classes"
  • "Which students might need extra help?"

Email Features

The application can send emails to students on your behalf:

  • "Send a motivational email to [student name]"
  • "Email all students who are struggling with their grades"

Note: For testing purposes, you may want to modify the student email addresses in teacher_assistant/grades/data.py to use your own email address.

Project Structure

auth0-teachersaide/ โ”œโ”€โ”€ teacher_assistant/ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”œโ”€โ”€ main.py # FastAPI application and routes โ”‚ โ”œโ”€โ”€ auth.py # Auth0 authentication configuration โ”‚ โ”œโ”€โ”€ context.py # Context variables for agent state management โ”‚ โ”œโ”€โ”€ grades/ โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ data.py # Sample student and class data โ”‚ โ”‚ โ””โ”€โ”€ model.py # Data models โ”‚ โ””โ”€โ”€ llm/ โ”‚ โ”œโ”€โ”€ __init__.py โ”‚ โ”œโ”€โ”€ llamaindex_agent.py # LlamaIndex agent configuration โ”‚ โ””โ”€โ”€ send_email.py # Gmail integration with Auth0 Token Vault โ”œโ”€โ”€ static/ โ”‚ โ”œโ”€โ”€ index.html # Frontend chat interface โ”‚ โ””โ”€โ”€ app.js # Frontend JavaScript โ”œโ”€โ”€ poetry.lock โ”œโ”€โ”€ .env.sample # Environment variables template โ””โ”€โ”€ README.md 

Key Components

  • FastAPI Backend: Handles authentication, API routes, and LLM interactions
  • LlamaIndex Agent: Processes natural language queries and orchestrates tool calls
  • Auth0 Integration: Manages user authentication and token exchange
  • Token Vault: Securely stores and manages third-party OAuth tokens
  • Gmail API Integration: Enables email sending on behalf of authenticated users via send_email.py
  • Context Management: Uses Python's contextvars to share user tokens across tool calls
  • Auth0 AI LlamaIndex Library: Simplifies federated connection integration with third-party APIs

Security Features

  • Token Vault: Auth0 securely stores refresh tokens and issues short-lived access tokens
  • Scoped Access: Gmail integration uses minimal required scopes (gmail.send)
  • User-level Actions: Emails are sent from the teacher's account, maintaining proper attribution
  • Session Management: Secure session handling with encrypted cookies

Auth0 Logo

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

About

Teacher's Aide: A GenAI-powered application to help teachers built with Auth0 and LlamaIndex

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published