Mentor IA: Code Walkthrough
Template walkthrough of repository organization, API design, retrieval flow, and deployment practices.
Repository Layout
mentor-ia/
├── api/
│ ├── routes/
│ │ ├── mentor.py
│ │ └── health.py
│ ├── services/
│ │ ├── retrieval.py
│ │ ├── orchestration.py
│ │ └── evaluation.py
│ └── main.py
├── frontend/
│ ├── src/
│ └── public/
├── infra/
│ ├── docker/
│ └── ci/
└── docs/
└── architecture.md
Key Modules
| Module | Responsibility | Notes |
|---|---|---|
api/routes/mentor.py |
Public mentoring endpoints | Validates input, applies policy checks, returns structured guidance |
services/retrieval.py |
Context retrieval | Fetches relevant course and user context for grounding |
services/orchestration.py |
Prompt + LLM orchestration | Composes system prompt, user state, and constraints |
services/evaluation.py |
Quality and latency checks | Captures rubric metrics and fallback events |
API Example (FastAPI)
from fastapi import APIRouter
from pydantic import BaseModel
router = APIRouter(prefix="/mentor", tags=["mentor"])
class MentorRequest(BaseModel):
learner_id: str
goal: str
topic: str
@router.post("/next-step")
def next_step(payload: MentorRequest):
recommendation = {
"next_action": "Review week-3 exercises",
"confidence": 0.86,
"reasoning_trace_id": "trace_1029",
}
return recommendation
RAG / Retrieval Flow
def mentor_response(query, learner_state):
context = retrieve_top_k(query, learner_state.course_id, k=5)
prompt = build_prompt(query=query, state=learner_state, context=context)
answer = llm_generate(prompt, temperature=0.2)
scored = evaluate_answer(answer, rubric="mentoring_v1")
if scored.quality < 0.7:
return fallback_template(query, context)
return answer
Deployment Notes
- API and worker services are containerized and deployed by environment (`dev`, `staging`, `prod`).
- CI pipeline runs lint + tests + build before deployment promotion.
- Runtime metrics include p95 latency, error rate, and retrieval hit quality.
name: mentor-ia-ci
steps:
- run: pytest
- run: docker build -t mentor-ia-api:${GIT_SHA} .
- run: docker push registry/mentor-ia-api:${GIT_SHA}
- run: deploy --env=staging --image=registry/mentor-ia-api:${GIT_SHA}