"""Central configuration for the Precalculus EdTech agents. Course: Precalculus, grounded on OpenStax *Precalculus 2e* (the textbook PDF in the repo root) plus two Hugging Face problem banks: - toloka/u-math — only the `precalculus_review` subject (university-level problems with golden answers). - shiwk24/MathCanvas-Instruct — only the `Analytic_Geometry` config (coordinate geometry), filtered to the sub-topics that appear in a precalculus syllabus. Models: - Embeddings: BAAI/bge-m3 via the HF Inference API (not loaded locally). - Agents (Retrieval/Quiz, Research, PLM): Qwen2.5-Coder-32B-Instruct via the HF Inference API. CodeAgent everywhere — the free providers for this model reject native `tools`/`tool_choice` params. Auth: HF token from `hf auth login` or HF_TOKEN. NEVER hard-code tokens in this repo. """ from pathlib import Path # Absolute paths so the app/agents work regardless of the current working directory # (v2 used cwd-relative "data/..." paths, which broke when launched from elsewhere). PROJECT_ROOT = Path(__file__).resolve().parent.parent DATA_DIR = PROJECT_ROOT / "data" COURSE = "PRECALC" COURSE_NAME = "Precalculus" # --- Sources --------------------------------------------------------------------------- TEXTBOOK_PDF = PROJECT_ROOT / "precalculus-2e_-_WEB.pdf" TEXTBOOK_NAME = "OpenStax Precalculus 2e" # Front matter / answer key / index pages are excluded from the RAG corpus: the answer # key in particular would leak exercise answers into "context" retrieval. TEXTBOOK_CONTENT_PAGES = (17, 1250) # 1-indexed inclusive: Ch 1 start .. end of Ch 12 UMATH_DATASET = "toloka/u-math" UMATH_SUBJECTS = ("precalculus_review",) MATHCANVAS_DATASET = "shiwk24/MathCanvas-Instruct" MATHCANVAS_CONFIG = "Analytic_Geometry" # MathCanvas `subknowledge` values kept as precalculus content. Dropped: Linear # Programming (not in the Precalculus 2e syllabus), Dilation & Homothety, Others. MATHCANVAS_SUBKNOWLEDGE = ( "Coordinate System Basics", "Linear Equations & Properties", "Conic Sections (Ellipse, Hyperbola, Parabola)", "Circular Equations & Properties", "Quadratic Functions", "Quadratic Equations & Properties", "Function Basics (Domain, Range, Properties)", "Piecewise & Other Functions", "Inverse Proportional Functions", "Vector Basics & Operations", ) # Question images are ~110 MB per MathCanvas shard (solution images ~350 MB, never # downloaded). Problem *text* is kept for every matching row; images are saved for at # most this many problems per sub-topic. Raise it (or set None) to keep all images. MATHCANVAS_IMAGES_PER_SUBTOPIC: int | None = 300 PROBLEMS_DIR = DATA_DIR / "problems" # normalized JSONL + question images PROBLEM_BANK_FILE = PROBLEMS_DIR / "problem_bank.jsonl" # --- Models ----------------------------------------------------------------------------- RETRIEVAL_EMBEDDING_MODEL = "BAAI/bge-m3" RETRIEVAL_AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct" RESEARCH_AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct" PLM_AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct" # Pin the inference provider: with "auto", the HF router sent this model to Cloudflare # (2026-11-19), which rejects the list-of-parts message content smolagents sends (HTTP 400). # featherless-ai is the provider HF lists as live for Qwen2.5-Coder-32B-Instruct. LLM_PROVIDER = "featherless-ai" # --- Vector store ----------------------------------------------------------------------- CHROMA_PATH = str(DATA_DIR / "chroma") CHROMA_COLLECTIONS = { "textbook": "precalc_textbook", "problems": "precalc_problems", } # --- Learner state / caches --------------------------------------------------------------- LEARNERS_DIR = DATA_DIR / "learners" RESEARCH_CACHE_DIR = DATA_DIR / "research_cache" ITEMS_DIR = DATA_DIR / "items" # --- Retrieval-practice quiz policy (see ARCHITECTURE.md §Learning science) ---------------- QUIZ_DEFAULT_ITEMS = 8 # Share of a quiz given to previously covered topics, as a function of how many topics the # learner has covered (k). Grows with coverage so interleaving increases as more is # learned; capped at 2/3 per Rohrer et al.'s classroom interleaving designs, where roughly # a third of each assignment is on the current lesson and the rest is mixed review. QUIZ_REVIEW_FRACTION_BY_K = {1: 0.0, 2: 0.25, 3: 0.4, 4: 0.5} QUIZ_REVIEW_FRACTION_MAX = 0.67 # Successive relearning (Rawson & Dunlosky): one correct recall per spaced session, ~3 # spaced sessions → treated as durable. Intervals in days after each successful session. RELEARNING_INTERVALS_DAYS = (1, 3, 7, 21, 60) RELEARNING_SESSIONS_FOR_DURABLE = 3 # --- ARTS defaults (PLM drills) ---------------------------------------------------------- RETIRE_STREAK = 4 RT_THRESHOLD_SIMPLE_S = 8.0 RT_THRESHOLD_MAPPING_S = 15.0 SESSION_MINUTES = (10, 15) TRIALS_PER_SESSION_TARGET = 60 # Cap generation length: without it a CodeAgent step on featherless-ai ran 5+ minutes and the # provider returned truncated JSON (JSONDecodeError at ~18k chars). LLM_MAX_TOKENS = 1500 def make_llm(model_id: str): """Single place that builds the agents' LLM client (provider pin + length cap).""" from smolagents import InferenceClientModel return InferenceClientModel(model_id=model_id, provider=LLM_PROVIDER, max_tokens=LLM_MAX_TOKENS, timeout=120) # --- Tutor / judge / vision models (benchmarked 2026-11-19) ----------------------------------- # Judging reasoning and writing explanations needs a stronger model than the 32B coder that # drives the CodeAgents. gpt-oss-120b answered a reasoning-gap probe correctly in 0.5–1.3 s on # cerebras/groq; providers are tried in order. TUTOR_MODEL = "openai/gpt-oss-120b" # fireworks-ai/together returned 402 (payment required) on this account and novita timed out. TUTOR_PROVIDERS = ("cerebras", "groq", "deepinfra") # gpt-oss is a reasoning model: at default effort its hidden reasoning can consume the whole token # budget on long problems and return EMPTY content (observed). Low effort + a larger budget fixes it. TUTOR_REASONING_EFFORT = "low" TUTOR_MAX_TOKENS = 4000 # Handwriting transcription. With a strict "verbatim, never correct" prompt, Qwen3-VL-30B kept a # planted student error (3.3 s); the 235B model silently *fixed* student arithmetic without it. VISION_MODELS = ( ("Qwen/Qwen3-VL-30B-A3B-Instruct", ("novita", "deepinfra", "featherless-ai")), ("Qwen/Qwen2.5-VL-72B-Instruct", ("ovhcloud", "featherless-ai")), ) # --- Handwritten-first quizzes ------------------------------------------------------------------ # Quizzes are mostly constructed-response, worked on paper and submitted as a photo (typed answers # also accepted). Multiple choice is capped so most retrieval is production, not recognition. QUIZ_MAX_MC_FRACTION = 0.25 # --- Placement assessment ------------------------------------------------------------------------- ASSESSMENT_MAX_ITEMS = 10 ASSESSMENT_MIN_TOPIC_ITEMS = 10 # a topic needs at least this many bank problems to be assessed # --- Worked examples (Research Agent tutor) -------------------------------------------------------- WORKED_EXAMPLE_MAX_FADED_ATTEMPTS = 3 # then reveal the remaining steps and start a fresh example TRANSFER_QUIZ_ITEMS = 3