Skip to content

Package: tutor

Generated from api/packages/tutor

Source: api/packages/tutor. The sections after the README are extracted from the code on every docs build.

A learner asks a question inside a course and gets a short answer built only from that course’s own content, with citations that link back to the lesson. Outside the course it says so. During an open quiz attempt it never gives or confirms quiz answers. Off by default per tenant (tutor.enabled). Records: ADR 0060 (proposed), ADR 0061 (privacy); plan docs/plans/phase-4.md section 8.

  • TutorIndexer: chunks of the applied blueprint (lesson blocks and the source text they cite) for Course Builder courses, rich text topics split at headings for other courses, with a PostgreSQL tsvector and a GIN index. Quiz questions, options, explanations and final tests are never indexed. The index rebuilds itself when the applied version or the topic content changes (tutor:index forces it).
  • PostgresRetriever: the words of the question OR-ed, ranked with ts_rank_cd, plus up to four chunks of the open topic; LikeRetriever is the fallback for databases without full-text search. No embeddings, no vector database.
  • TutorService: checks the switch, course access and limits (30 questions per learner and day, 6 per minute, a monthly tenant budget), asks the tutor task (profile light) with the chunks, the last six messages and the question, each learner text inside an escaped <learner_message> wrapper. The answer must cite chunks that were provided; an in-scope answer needs a citation. While the learner has a quiz attempt open (AttemptGuard), the mode is attempt_active and an answer that contains a correct option (Support/Leak, 80 % of the words of a longer option, the phrase of a short one) is replaced by a standard refusal and flagged. ai_calls.user_id is null; the subject is the conversation.
  • Streamed answers (ADR 0105): POST messages with stream: true stores the question, writes RUN_STARTED to tutor_events and queues AnswerJob (202 with a run id; 409 while the conversation has an answer running). The job reuses TutorService::answer() with LlmClient::stream() and appends grouped text events and a tutor.final event with the checked answer and citations; nothing streams during an open quiz attempt. GET /api/tutor/runs/{run}/events tails the log with the SSE loop in core (Ulams\Core\Http\Sse\EventStream). Events are pruned a day after the run ends or with their conversation. tutor.stream.enabled switches it off.
  • Conversations belong to the learner (list, show, delete) and are deleted after 90 days (tutor:prune) or with the account. Analytics for authors and admins are counts only, for groups of at least learner_insights.min_group_size learners.
Terminal window
vendor/bin/phpunit --testsuite tutor # fake driver, a course built through the real builder pipeline
php artisan tutor:index --course=1
php artisan tutor:eval --fixtures=all --author=1 # golden questions on the fake driver; --live for the real model

tutor:eval and learner-insights:eval are documented in front/docs-site/src/content/docs/developers/learner-evals.mdx.

  • Settings, env variables, privacy: front/docs-site/src/content/docs/admin/tutor.mdx
Method Path Auth Action
GET /api/tutor/courses/{course}/status yes TutorController@status
POST /api/tutor/courses/{course}/messages yes TutorController@ask
GET /api/tutor/courses/{course}/conversations yes TutorController@conversations
GET /api/tutor/conversations/{conversation} yes TutorController@show
DELETE /api/tutor/conversations/{conversation} yes TutorController@destroy
GET /api/tutor/runs/{run}/events yes RunEventsController@stream
GET /api/admin/tutor/courses/{course}/analytics yes TutorController@analytics

None.

Registered with AdministrableConfig::registerConfig (editable in the admin panel under Configuration → Settings).

Key Rules Public Read-only
tutor.enabled boolean no
tutor.limits.daily_questions integer, min:1, max:1000 no
tutor.stream.enabled boolean no
tutor.retention_days integer, min:1, max:3650 no

None.

Command Description Signature
tutor:eval Evaluate the course tutor on golden questions (fake driver by default, –live for the real model) tutor:eval {--fixtures=all : all, or a comma list of coffee, git, injection} {--live : call the real model} {--record : write cassettes (tests/cassettes) from this run} {--author= : user id that owns the eval sessions (default: the first admin)} {--max-p95-seconds=20 : the latency check of a live run} {--max-usd-per-answer=0.03 : the cost check of a live run}
tutor:index Rebuild the tutor search index of one course or of every course tutor:index {--course= : Only this course id}
tutor:prune Delete expired tutor conversations tutor:prune
Kind Target Frequency
command 'tutor:prune' dailyAt('02:50')->withoutOverlapping())

AI_TASK_TUTOR_PROFILE, TUTOR_DAILY_QUESTIONS, TUTOR_ENABLED, TUTOR_EVAL_MONTHLY_USD, TUTOR_PER_MINUTE, TUTOR_RETENTION_DAYS, TUTOR_STREAM_COALESCE_MS, TUTOR_STREAM_ENABLED, TUTOR_STREAM_EVENTS_RETENTION_DAYS, TUTOR_STREAM_POLL_MS, TUTOR_STREAM_QUEUE, TUTOR_STREAM_QUEUE_CONNECTION, TUTOR_STREAM_SSE_SECONDS, TUTOR_STREAM_TIMEOUT_SECONDS, TUTOR_TENANT_MONTHLY_USD