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.
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
- ๐ 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
- Python 3.11 or later
- Poetry for dependency management
- An Auth0 for AI Agents account (Create one)
- An OpenAI account and API key (Create one)
- A Google account for Gmail integration
Clone the repository
git clone https://github.com/auth0/auth0-teachersaide cd auth0-teachersaideInstall dependencies using Poetry
poetry install
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
- Go to your Auth0 Dashboard
- Create a new Regular Web Application named "Teacher Assistant"
- Configure the application settings:
- Allowed Callback URLs:
http://localhost:8000/auth/callback - Grant Types: Enable "Token Exchange (Federated Connection)" in Advanced Settings
- Allowed Callback URLs:
- Set up Google OAuth integration following this documentation
- Enable the following Google permissions:
Offline AccessGmail.Send
- Enable Token Vault for the
google-oauth2connection in Authentication โ Social
- In your application settings, go to the Connections tab
- Enable the
google-oauth2connection - Disable any other connections
Start the development server
poetry run uvicorn teacher_assistant.main:app --reload
Access the application
Open your browser and navigate to
http://localhost:8000Login and test
You'll be redirected to Auth0's Universal Login. Sign in with your Google account to access the teacher interface.
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?"
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.
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 - 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
contextvarsto share user tokens across tool calls - Auth0 AI LlamaIndex Library: Simplifies federated connection integration with third-party APIs
- 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 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
