Skip to content

Update AI Tutor in Python Lab#73297

Draft
fisher-alice wants to merge 16 commits into
stagingfrom
alice/pythonlab-aitutor-setting
Draft

Update AI Tutor in Python Lab#73297
fisher-alice wants to merge 16 commits into
stagingfrom
alice/pythonlab-aitutor-setting

Conversation

@fisher-alice

@fisher-alice fisher-alice commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This PR updates AI Tutor in Python Lab:

  • levelbuilders can customize the answer types expected from the model (added to level edite page),
  • uses structure response
  • fine-tunes the project context passed to AI Tutor

Links

Jira:

Testing story

Deployment notes

Privacy and security

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 wires AI Tutor prompt settings into Python Lab (and updates Web Lab 2’s levelbuilder prompt settings integration), adding Python Lab–specific prompt assets and structured response handling, while also renaming the shouldShowAiTutor option flag for clarity and removing an unused aiTutorContextHelper prop from Codebridge plumbing.

Changes:

  • Add Python Lab AI Tutor prompt settings editor + persistence/validation, and use those settings to control tutor visibility and system prompt generation.
  • Introduce Python Lab prompt-building infrastructure (answer types, triggers/contracts markdown, prompt generator) and Python Lab structured-response schema formatting.
  • Rename shouldShowAiTutor option tutorLevelisTutorLevel across call sites/tests and split Web Lab 2’s levelbuilder entrypoint for prompt settings.

Reviewed changes

Copilot reviewed 56 out of 56 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
dashboard/config/levels/custom/pythonlab/Allthethings Python Lab 1.level Publishes/updates a Python Lab level to include ai_tutor_prompt_settings and related properties.
dashboard/app/views/levels/editors/fields/_weblab2_ai_tutor_prompt_settings.html.haml Web Lab 2 levelbuilder field for editing AI Tutor prompt settings via a dedicated webpack entry.
dashboard/app/views/levels/editors/fields/_pythonlab_ai_tutor_prompt_settings.html.haml New Python Lab levelbuilder field for editing AI Tutor prompt settings.
dashboard/app/views/levels/editors/_weblab2.html.haml Switch Web Lab 2 editor to render the new Web Lab 2 prompt settings partial.
dashboard/app/views/levels/editors/_pythonlab.html.haml Switch Python Lab editor to render the new Python Lab prompt settings partial (replacing the old checkbox-only partial).
dashboard/app/models/levels/pythonlab.rb Persist/validate ai_tutor_prompt_settings on Python Lab levels.
apps/webpackEntryPoints.js Add new levelbuilder entrypoints for Web Lab 2 + Python Lab prompt settings; remove the old shared entry.
apps/test/unit/lab2/levelEditors/aiTutorPromptSettings/EditAiTutorPromptSettingsTest.tsx Update unit tests to pass newly-required props to the shared prompt settings editor component.
apps/test/unit/aichat/helpers/aiChatAccessTest.ts Update tests for renamed shouldShowAiTutor parameter (isTutorLevel).
apps/src/weblab2/Weblab2View.tsx Stop passing the removed aiTutorContextHelper prop into Codebridge.
apps/src/weblab2/helpers/aiTutorStructuredResponseHelper.ts Document that accept/reject formatting includes buildJSON.
apps/src/templates/instructions/InstructionsWithWorkspace.jsx Update shouldShowAiTutor call to use isTutorLevel.
apps/src/sites/studio/pages/levels/editors/fields/_weblab2_ai_tutor_prompt_settings.js New Web Lab 2 levelbuilder entrypoint for prompt settings editor with explicit contracts/labels/defaults.
apps/src/sites/studio/pages/levels/editors/fields/_pythonlab_ai_tutor_prompt_settings.js New Python Lab levelbuilder entrypoint for prompt settings editor with Python Lab answer types and instructions.
apps/src/sites/studio/pages/levels/editors/fields/_ai_tutor_prompt_settings.js Remove the old shared levelbuilder entrypoint.
apps/src/pythonlab/types.ts Add Python Lab AI Tutor answer type constants/types.
apps/src/pythonlab/PythonlabView.tsx Use prompt settings to determine tutor visibility and generate the system prompt + response schema settings.
apps/src/pythonlab/prompts/promptMaps.ts Map Python Lab answer types to trigger/contract markdown.
apps/src/pythonlab/prompts/environment.md Add Python Lab environment context for the system prompt.
apps/src/pythonlab/prompts/basePrompt.md Add Python Lab base tutor role/policy prompt.
apps/src/pythonlab/prompts/answerTypeTriggers/ask.md Add trigger text for ask.
apps/src/pythonlab/prompts/answerTypeTriggers/buildCSV.md Add trigger text for buildCSV.
apps/src/pythonlab/prompts/answerTypeTriggers/buildJSON.md Add trigger text for buildJSON.
apps/src/pythonlab/prompts/answerTypeTriggers/buildPython.md Add trigger text for buildPython.
apps/src/pythonlab/prompts/answerTypeTriggers/debug.md Add trigger text for debug.
apps/src/pythonlab/prompts/answerTypeTriggers/documentation.md Add trigger text for documentation.
apps/src/pythonlab/prompts/answerTypeTriggers/example.md Add trigger text for example.
apps/src/pythonlab/prompts/answerTypeTriggers/explainCode.md Add trigger text for explainCode.
apps/src/pythonlab/prompts/answerTypeTriggers/hint.md Add trigger text for hint.
apps/src/pythonlab/prompts/answerTypeTriggers/pseudocode.md Add trigger text for pseudocode.
apps/src/pythonlab/prompts/answerTypeTriggers/refusal.md Add trigger text for refusal.
apps/src/pythonlab/prompts/answerTypeTriggers/refusalPythonSnippets.md Add trigger text for refusalPythonSnippets.
apps/src/pythonlab/prompts/answerTypeTriggers/testCase.md Add trigger text for testCase.
apps/src/pythonlab/prompts/answerTypeContracts/ask.md Add contract text for ask.
apps/src/pythonlab/prompts/answerTypeContracts/buildCSV.md Add contract text for buildCSV.
apps/src/pythonlab/prompts/answerTypeContracts/buildJSON.md Add contract text for buildJSON.
apps/src/pythonlab/prompts/answerTypeContracts/buildPython.md Add contract text for buildPython.
apps/src/pythonlab/prompts/answerTypeContracts/debug.md Add contract text for debug.
apps/src/pythonlab/prompts/answerTypeContracts/documentation.md Add contract text for documentation.
apps/src/pythonlab/prompts/answerTypeContracts/example.md Add contract text for example.
apps/src/pythonlab/prompts/answerTypeContracts/explainCode.md Add contract text for explainCode.
apps/src/pythonlab/prompts/answerTypeContracts/hint.md Add contract text for hint.
apps/src/pythonlab/prompts/answerTypeContracts/pseudocode.md Add contract text for pseudocode.
apps/src/pythonlab/prompts/answerTypeContracts/refusal.md Add contract text for refusal.
apps/src/pythonlab/prompts/answerTypeContracts/refusalPythonSnippets.md Add contract text for refusalPythonSnippets.
apps/src/pythonlab/prompts/answerTypeContracts/testCase.md Add contract text for testCase.
apps/src/pythonlab/hooks/useAiTutorResponseSchemaSettings.ts Add Python Lab hook to provide JSON schema + response formatting callback.
apps/src/pythonlab/helpers/aiTutorStructuredResponseHelper.ts Add Python Lab structured-output schema and formatting helpers (copy/paste flow).
apps/src/pythonlab/helpers/aiTutorPromptGenerator.ts Add Python Lab system prompt generator from selected answer types + customizations.
apps/src/pythonlab/helpers/aiTutorContextHelper.ts Improve Python Lab tutor context: file paths, exclude md, truncate large data files, etc.
apps/src/lab2/views/components/Instructions/ResourcePanel/index.tsx Consider prompt settings answerTypes when deciding whether to show AI Tutor tab in Resource Panel.
apps/src/lab2/levelEditors/aiTutorPromptSettings/EditAiTutorPromptSettings.tsx Refactor shared prompt settings editor to accept lab-provided answer-type config (labels/contracts/defaults).
apps/src/codebridge/codebridgeContext/codebridgeContext.tsx Remove aiTutorContextHelper from Codebridge context type.
apps/src/codebridge/Codebridge.tsx Remove aiTutorContextHelper prop and stop passing it through context.
apps/src/aiTutor/views/legacyLabs/AiTutorContainer.tsx Update shouldShowAiTutor call to use isTutorLevel.
apps/src/aichat/helpers/aiChatAccess.ts Rename shouldShowAiTutor option tutorLevelisTutorLevel.
Comments suppressed due to low confidence (1)

dashboard/app/views/levels/editors/fields/_weblab2_ai_tutor_prompt_settings.html.haml:9

  • @level.properties["ai_tutor_prompt_settings"].to_json || "{}" will return the string "null" when the property is nil (since nil.to_json is truthy), so the fallback never applies. Prefer serializing an empty object when the setting is missing so the client consistently receives {}.

Comment on lines +8 to +9
%script{src: webpack_asset_path('js/levels/editors/fields/_pythonlab_ai_tutor_prompt_settings.js'),
data: {promptsettings: @level.properties["ai_tutor_prompt_settings"].to_json || "{}"}}
Comment on lines +18 to +24
responseCallback: (response: string) => {
const jsonResponse = JSON.parse(response);
console.log('🤖: AI Tutor response (in jsonSchema callback):', {
jsonResponse,
});
return formatCopyPasteResponse(jsonResponse.answer);
},
Comment on lines +226 to +236
const systemPrompt = useMemo(() => {
const answerTypes: AiTutorAnswerType[] =
(levelProperties.aiTutorPromptSettings
?.answerTypes as AiTutorAnswerType[]) || DEFAULT_ANSWER_TYPES;
return generateAiTutorPrompt(
answerTypes,
levelProperties.aiTutorPromptSettings?.answerTypeCustomizations as
| Partial<Record<AiTutorAnswerType, string>>
| undefined
);
}, [levelProperties.aiTutorPromptSettings]);
Comment on lines +131 to +137
private def validate_ai_tutor_prompt_settings
return if ai_tutor_prompt_settings.nil?
answer_types = ai_tutor_prompt_settings['answerTypes']
unless answer_types.is_a?(Array) && answer_types.all?(String)
errors.add(:ai_tutor_prompt_settings, 'answerTypes must be an array of strings.')
end
end
Comment on lines +93 to +97
export const generateAiTutorPrompt = (
answerTypes: AiTutorAnswerType[],
answerTypeCustomizations?: Partial<Record<AiTutorAnswerType, string>>
): string => {
const parsedAnswerTypes = generateFinalAnswerTypeList(answerTypes);
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.

2 participants