Skip to content

Add LangGraph-based Multi-Agent AI Assistant with RAG, Debugging Support, and Firestore Persistence#400

Open
Rishabh327 wants to merge 10 commits into
c2siorg:developfrom
Rishabh327:develop
Open

Add LangGraph-based Multi-Agent AI Assistant with RAG, Debugging Support, and Firestore Persistence#400
Rishabh327 wants to merge 10 commits into
c2siorg:developfrom
Rishabh327:develop

Conversation

@Rishabh327
Copy link
Copy Markdown

Description

This PR introduces a LangGraph-powered multi-agent AI assistant integrated into CodeLabz labs to enhance the student learning experience.

The assistant supports:

Conceptual Q&A using RAG (ChromaDB)
Code debugging assistance using live editor context
Intelligent routing via LLM-based intent classification
Persistent conversation storage using Firestore
Backend (Python - ai_agent/)
agent_state.py
Defines AgentState TypedDict with:
Auto-appending message history
Routing signal (next_step)
Lab context and code snippet
Retrieved knowledge base documents
graph.py
Implements LangGraph StateGraph:
Router → Documentation Agent | Debugging Agent | Responder
agents/router.py
LLM-based intent classifier
Routes queries to:
Documentation (RAG)
Debugging
Direct response
agents/documentation_agent.py
RAG pipeline using ChromaDB
Retrieves top-k relevant passages
Generates grounded responses
Thread-safe lazy vector store initialization
agents/debugging_agent.py
Performs static code analysis
Uses live editor snippet as context
agents/responder.py
Handles simple queries directly
Acts as pass-through if another agent has already responded
vector_store.py
Wrapper over ChromaDB PersistentClient
Supports indexing and similarity search
main.py
FastAPI service exposing:
POST /chat
POST /index
GET /health
Optional Firestore persistence under cl_ai_conversations
Frontend (React - AIAssistant)
index.jsx
Floating Action Button (FAB) to toggle assistant UI
ChatInterface.jsx
Chat drawer UI with:
Message bubbles
Loading states
Collapsible retrieved-docs panel
Enter-to-send functionality
Sends requests to VITE_AI_SERVICE_URL/chat with:
lab_id
Live code snippet
styles.js
MUI-based styling
Integration
Integrated AIAssistant into TutorialPage
Automatically passes labId from route
Assistant is available on all lab pages with full context
Configuration
Added VITE_AI_SERVICE_URL to .env.sample (default: http://localhost:8000)
Backend .env.sample includes:
OPENAI_API_KEY
CHROMA_PERSIST_DIR
FIREBASE_CRED_PATH
Related Issue
(#366)

Closes #366

Motivation and Context

This feature improves the learning experience in CodeLabz by:

Providing context-aware assistance inside labs
Reducing dependency on external help/resources
Helping users debug code in real-time
Enabling scalable AI support using a modular multi-agent system
How Has This Been Tested?
Backend Testing
Tested all API endpoints (/chat, /index, /health) via Postman
Verified routing logic across:
Documentation queries
Debugging queries
Simple queries
Validated RAG retrieval correctness with ChromaDB
Confirmed Firestore persistence of conversations
Frontend Testing
Verified UI rendering across different lab pages
Tested chat interactions with:
Conceptual questions
Code debugging scenarios
Ensured correct API integration using environment variables
Integration Testing
Confirmed correct passing of lab_id and code snippet
Verified end-to-end flow from UI → API → LangGraph → response
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
My code follows the code style of this project.
My change requires a change to the documentation.
I have updated the documentation accordingly.
I have added tests to cover my changes.
All new and existing tests passed.

Copilot AI and others added 3 commits April 14, 2026 08:29
…siorg#366)

- Add ai_agent/ Python package with LangGraph multi-agent workflow
  - agent_state.py: AgentState TypedDict with message history, routing state,
    lab context, and retrieved KB docs
  - graph.py: LangGraph StateGraph wiring Router → specialist agents → Responder
  - agents/router.py: classifies student messages into documentation/debugging/respond
  - agents/documentation_agent.py: RAG over ChromaDB-indexed lab guides
  - agents/debugging_agent.py: static code analysis and fix suggestions
  - agents/responder.py: synthesises or passes through the final reply
  - vector_store.py: ChromaDB persistence wrapper
  - main.py: FastAPI service with /chat, /index, /health endpoints + Firestore
    conversation persistence
  - requirements.txt, .env.sample, README.md

- Add src/components/AIAssistant/ React UI
  - index.jsx: fixed-position FAB that toggles the chat panel
  - ChatInterface.jsx: chat UI with message bubbles, loading state, and
    collapsible retrieved-docs panel
  - styles.js: MUI makeStyles definitions

- Integrate AIAssistant into TutorialPage
- Add VITE_AI_SERVICE_URL to .env.sample

Agent-Logs-Url: https://github.com/Rishabh327/Codelabz/sessions/e6e9886c-3869-45e5-90a1-38a50a6624ee

Co-authored-by: Rishabh327 <115366218+Rishabh327@users.noreply.github.com>
…ector store, version bounds, docstring)

Agent-Logs-Url: https://github.com/Rishabh327/Codelabz/sessions/e6e9886c-3869-45e5-90a1-38a50a6624ee

Co-authored-by: Rishabh327 <115366218+Rishabh327@users.noreply.github.com>
…k-issue-366

feat: Agentic AI Framework for CodeLabz using LangGraph
Copilot AI review requested due to automatic review settings April 14, 2026 08:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an in-app AI assistant to CodeLabz labs, with a new FastAPI/LangGraph backend (multi-agent routing + RAG + optional Firestore persistence) and a React floating chat UI integrated into TutorialPage.

Changes:

  • Add AIAssistant frontend (FAB + chat drawer) that calls an AI service via VITE_AI_SERVICE_URL.
  • Add ai_agent/ backend service (FastAPI /chat, /index, /health) implementing LangGraph Router → (Documentation RAG | Debugging) → Responder.
  • Add environment samples and backend docs for configuring the service (OpenAI key, Chroma persistence, optional Firebase creds).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/components/TutorialPage/index.jsx Mounts the AIAssistant on tutorial pages with labId context.
src/components/AIAssistant/styles.js Adds styling for the FAB, chat drawer, message bubbles, and docs panel.
src/components/AIAssistant/index.jsx Implements the toggle FAB and conditional rendering of the chat UI.
src/components/AIAssistant/ChatInterface.jsx Implements chat UX and POST /chat integration, including retrieved-docs display.
ai_agent/vector_store.py Adds ChromaDB-backed vector store manager for indexing and similarity search.
ai_agent/requirements.txt Introduces backend Python dependencies (LangGraph/LangChain/FastAPI/Chroma/Firebase).
ai_agent/main.py Adds FastAPI app, CORS config, /chat, /index, /health, and Firestore persistence helper.
ai_agent/graph.py Defines and compiles the LangGraph StateGraph workflow.
ai_agent/agents/router.py Adds LLM-based intent routing logic (documentation/debugging/respond).
ai_agent/agents/responder.py Adds final response node (direct reply or pass-through).
ai_agent/agents/documentation_agent.py Adds RAG retrieval + grounded response generation with lazy vector store init.
ai_agent/agents/debugging_agent.py Adds code-debugging response generation using injected code snippet context.
ai_agent/agents/init.py Marks agents as a package.
ai_agent/agent_state.py Defines the shared AgentState TypedDict with message reducer.
ai_agent/init.py Marks ai_agent as a package.
ai_agent/README.md Documents architecture, setup, env vars, and API usage for the AI service.
ai_agent/.env.sample Provides backend env sample for OpenAI/Chroma/Firebase/CORS.
.env.sample Adds VITE_AI_SERVICE_URL sample for the frontend to reach the backend.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/AIAssistant/index.jsx Outdated
Comment thread src/components/AIAssistant/ChatInterface.jsx Outdated
Comment thread ai_agent/vector_store.py
Comment thread ai_agent/vector_store.py
Comment thread ai_agent/main.py
Comment on lines +88 to +91
app.add_middleware(
CORSMiddleware,
allow_origins=os.getenv("ALLOWED_ORIGINS", "*").split(","),
allow_credentials=True,
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CORS config defaults ALLOWED_ORIGINS to "*" while also setting allow_credentials=True. This combination effectively allows credentialed cross-origin requests from any origin (or leads to non-compliant CORS behavior depending on middleware implementation). Use an explicit allowlist by default, or set allow_credentials=False when using *.

Suggested change
app.add_middleware(
CORSMiddleware,
allow_origins=os.getenv("ALLOWED_ORIGINS", "*").split(","),
allow_credentials=True,
allowed_origins = [origin.strip() for origin in os.getenv("ALLOWED_ORIGINS", "*").split(",") if origin.strip()]
allow_credentials = "*" not in allowed_origins
app.add_middleware(
CORSMiddleware,
allow_origins=allowed_origins,
allow_credentials=allow_credentials,

Copilot uses AI. Check for mistakes.
Comment thread ai_agent/main.py
Comment thread ai_agent/main.py
Comment thread ai_agent/main.py Outdated
Copilot AI and others added 5 commits April 14, 2026 11:08
… mediaPropType before first use

Agent-Logs-Url: https://github.com/Rishabh327/Codelabz/sessions/26c6bfa4-c820-4c55-abe4-5a5c20ba67c8

Co-authored-by: Rishabh327 <115366218+Rishabh327@users.noreply.github.com>
feat: complete pre-GSoC evaluation tasks – UI, Dockerization, media upload, TypeScript
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Rishabh327
Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

Rishabh327 and others added 2 commits April 15, 2026 02:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Agentic AI Framework for CodeLabz using LangGraph

3 participants