Study Assistant Agent
Relevant source files
The following files were used as context for generating this wiki page:
The Study Assistant Agent is a LangChain-powered AI module designed to enhance student learning by interacting with lecture transcripts and summaries. It serves as the primary interface for semantic search, educational content generation, and intelligent Q&A within the ClassMate ecosystem.
The agent operates by leveraging a Vector Memory Store to retrieve relevant context from past lectures, allowing it to provide grounded answers, generate study materials like flashcards and quizzes, and explain complex academic concepts in various styles.
Sources: ai_backend/agents/study_assistant.py:1-12, PROJECT_STRUCTURE.md:144-150
Architecture and Core Components
The Study Assistant is built upon a modular architecture that separates retrieval logic, LLM interaction, and content indexing.
Class Structure and Initialization
The primary class, StudyAssistantAgent, inherits from BaseAgent. It lazily initializes its LLM (GPT-4o-mini) and embedding models (text-embedding-3-small) to optimize resource usage. It integrates with VectorMemoryStore for long-term semantic retrieval across different user sessions.
Sources: ai_backend/agents/study_assistant.py:46-70
Semantic Memory and Retrieval
The agent uses a RAG (Retrieval-Augmented Generation) pattern. When a user asks a question, the agent:
- Embeds the query using OpenAI embeddings.
- Performs a similarity search in the
VectorMemoryStorefiltered byuser_id. - Constructs a prompt using the retrieved lecture snippets as context.
The diagram above illustrates the Retrieval-Augmented Generation (RAG) flow used for the Q&A feature.
Functional Capabilities
The agent provides several specialized methods for educational support:
| Feature | Description | Key Method |
|---|---|---|
| Smart Q&A | Answers questions based on lecture context stored in vector memory. | ask_question |
| Flashcard Generation | Extracts key concepts and formats them into question-answer pairs. | generate_flashcards |
| Quiz Creation | Generates multiple-choice questions with explanations. | generate_quiz |
| Study Guide | Creates a comprehensive guide including overview, terms, and tips. | generate_study_guide |
| Concept Explanation | Simplifies or details specific concepts based on chosen styles (e.g., ELI5). | explain_concept |
Sources: ai_backend/agents/study_assistant.py:81-255, ai_backend/api/ai_agent_api.py:46-115
Automated Study Guide Generation
The generate_study_guide method processes transcripts to produce a structured JSON object containing six distinct sections: Overview, Key Concepts, Important Terms, Study Tips, Connections, and Practice Questions.
Sources: ai_backend/agents/study_assistant.py:195-234
Data Flow: Indexing and Storage
To support future retrieval, transcripts and summaries must be indexed into the vector database. This process involves generating embeddings and storing them alongside metadata like session_id and content_type.
The flow shows how raw text is processed and stored for semantic search.
Sources: ai_backend/agents/study_assistant.py:291-340, ai_backend/agents/transcription_post_agents.py:100-135
API Integration
The Study Assistant is exposed via a set of REST endpoints under the /api/v1/ai prefix. These endpoints require user authentication and pass the user_id to the agent to ensure data isolation.
Key Endpoints
POST /ask: Takes aquestionand optionalsession_id.POST /flashcards: Takes atranscriptand desiredcount.POST /index: Manually triggers indexing of content into vector memory.POST /search: Performs semantic search across all user documents.
Sources: ai_backend/api/ai_agent_api.py:18-44, ai_backend/api/ai_agent_api.py:118-142
Background Processing
Study material generation can be offloaded to Celery workers. The NotesWorker utilizes a NotesOrchestrator (which coordinates smaller agents like SummaryAgent and KeyPointsAgent) to process transcripts asynchronously and save results to the database.
Sources: ai_workers/notes_worker.py:34-63, ai_backend/agents/note_agents.py:11-50
This sequence diagram details the asynchronous processing of study notes.
Conclusion
The Study Assistant Agent is a central component of the ClassMate AI backend, transforming raw audio transcriptions into structured educational assets. By combining vector-based retrieval with large language models, it provides a personalized and context-aware learning experience.
Sources: ai_backend/agents/study_assistant.py:46-55, PROJECT_STRUCTURE.md:144-150