Demo: https://markso.ng/demo/canvas
An OpenAI-powered ReAct Agent for Canvas LMS companion tailored for student accounts. The project ships with a conversational CLI, a secured WebSocket service for machine-to-machine integrations, and a bulk Canvas LMS file downloader that can populate OpenAI Vector Stores.
- Student-safe Canvas API coverage with 20+ tools for courses, assignments, files, discussions, grades, and calendar data.
- Rich-powered command line chat experience (
canvas_chat.py). - Bulk file synchronization (
file_index_downloader.py) with optional OpenAI Vector Store uploads. - WebSocket bridge (
ws_server.py) that exposes agent chat and download workflows with password + TOTP authentication. - Example clients (
ws_test.py, scripts inexamples/) demonstrating common workflows.
canvas_ai/
├── canvas_chat.py # Interactive console entry point
├── file_index_downloader.py # Bulk download + optional vector store upload
├── ws_server.py # Authenticated WebSocket bridge
├── ws_test.py # Example sync WebSocket client
├── configs/
│ └── canvas_agent_config.py
├── src/
│ ├── agent/ # Agent builders and prompts
│ ├── tools/ # Canvas tool implementations
│ ├── models/ # Model manager + providers
│ ├── logger/ # Rich-based logging utilities
│ └── ...
├── examples/ # Guided demos and tool exercises
├── requirements.txt
└── README.md
- Python 3.11+
- A Canvas LMS account with student-level API access
- An OpenAI API key (GPT-4o or compatible model)
- Optional: Assistants v2 Vector Store access if you plan to upload files
Create a .env file (see env_example.txt for a template):
# LLM provider
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-your-key
# Canvas API
CANVAS_URL=https://instituation.instructure.com/
CANVAS_ACCESS_TOKEN=your_canvas_access_token_here
# WebSocket Server Config
CANVAS_WS_SECRET=your_websocket_secret_here
CANVAS_WS_TOTP_SECRET=your_totp_secret_here
CANVAS_WS_TOTP_DISABLED=false
# WSS Config
WSS_ENABLED=true
WSS_CERTFILE=your_certfile_here
WSS_KEYFILE=your_keyfile_here
CANVAS_WS_URI=wss://your_domain.com:8765
# Max duration of a session in minutes
SESSION_DURATION=10Generating a Canvas access token
- Log in to Canvas → Account → Settings → Approved Integrations
- Click + New Access Token
- Add a description and (optionally) an expiration
- Generate and copy the token immediately
For TOTP secrets you can use any authenticator app or pyotp.random_base32().
pip install -r requirements.txtRecommended extras (optional but useful during development):
pip install black ruffpython canvas_chat.pySample interaction:
You: List every course I am enrolled in
Agent: Course 1 (ID 123), Course 2 (ID 456)
You: Show the upcoming assignments for Course 1
Agent: [Table of assignments with due dates and status]
Commands available inside the CLI: help, status, examples, clear, exit.
Run locally:
python file_index_downloader.py # Full download + optional vector upload
python file_index_downloader.py --upload-only # Skip downloads, upload existing filesFeatures:
- Downloads per-course directory trees under
file_index/ - Supports incremental runs (skips unchanged files)
- Optionally uploads supported formats to OpenAI Vector Stores (PDF, DOCX, PPTX, CSV, etc.)
- Produces a
download_report.jsonsummary andvector_stores_mapping.json
When driven via WebSocket automation the downloader skips interactive prompts and returns statistics in the response payload.
Start the server (after configuring .env):
python ws_server.pyAuthentication flow:
- Client opens a WebSocket connection to
ws://host:port - Client sends
{ "type": "auth", "password": "...", "totp": "123456" } - Server verifies the secret and replies
{ "status": "authenticated" } - Subsequent messages can be:
- Chat:
{ "type": "chat", "query": "List my courses" } - Download: staged workflow
- Request course list ->
{ "type": "download" } - Server responds with numbered courses
- Client selects ->
{ "type": "download", "course_indices": [1,3], "auto_confirm": true } - Server streams the final status and statistics
- Request course list ->
- Chat:
# Chat mode
python ws_test.py
# Download mode (make sure CANVAS_WS_TEST_* envs are set)
python ws_test.py downloadThe test client authenticates once per session and prints responses to stdout. In download mode it displays the course roster before sending the follow-up selection.
examples/test_file_download.py– Guided walkthrough of downloading Canvas files through the agentexamples/direct_file_download_test.py– Low-level Canvas file operationsexamples/test_vector_store_tools.py– Demonstrates vector-store search and listing
- Authentication failed → Verify
CANVAS_WS_SECRETandCANVAS_WS_TOTP_SECRET; update your authenticator if the TOTP window drifts. - Missing dependencies → Re-run
pip install -r requirements.txt. - Canvas 401 errors → Regenerate your Canvas access token or confirm the URL points to the correct subdomain.
- Vector store upload errors → Ensure
openai>=1.20.0and that your account has Assistants v2 access.
This project is provided for educational use. Reach out via GitHub Issues for feedback or questions.