Spaces:
Runtime error
Runtime error
File size: 3,419 Bytes
c8b1c88 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | """Centralized prompts for the Generator and Reviewer agents.
All prompts live here to keep the rest of the code clean and deterministic.
We are very strict about JSON-only outputs.
"""
from __future__ import annotations
import json
from typing import Any, Dict, List, Optional
JSON_ONLY_RULES = (
"You MUST respond with valid JSON only. "
"Do NOT include markdown. Do NOT include any extra keys. "
"Do NOT add commentary outside the JSON."
)
def generator_system_prompt() -> str:
schema_example = {
"explanation": "string",
"mcqs": [
{
"question": "string",
"options": [
"Option 1 text",
"Option 2 text",
"Option 3 text",
"Option 4 text",
],
"answer": "Option 2 text",
}
],
}
return (
"You are the Generator Agent. Your job is to create accurate, age-appropriate educational content. "
+ JSON_ONLY_RULES
+ "\n\n"
+ "Output schema (MUST match exactly):\n"
+ json.dumps(schema_example, ensure_ascii=False)
+ "\n\n"
+ "Hard rules:\n"
+ "- Keep language appropriate for the given grade.\n"
+ "- Explanation must only cover concepts you will test in MCQs.\n"
+ "- MCQs must have exactly 4 options (strings).\n"
+ "- `answer` MUST be EXACTLY one of the strings in `options` (copy/paste match).\n"
+ "- Do NOT return A/B/C/D as the answer unless the option text is literally 'A', 'B', 'C', or 'D'.\n"
+ "- Do not vary the structure.\n"
)
def generator_user_prompt(grade: int, topic: str, feedback: Optional[List[str]] = None) -> str:
payload: Dict[str, Any] = {"grade": grade, "topic": topic}
if feedback:
payload["reviewer_feedback"] = feedback
return (
"Generate educational content for the following input (JSON):\n"
+ json.dumps(payload, ensure_ascii=False)
+ "\n\n"
+ "If reviewer_feedback is provided, fix those issues while keeping the SAME output schema."
)
def reviewer_system_prompt() -> str:
schema_example = {
"status": "pass",
"feedback": ["Sentence 2 is too complex for Grade 4"],
}
return (
"You are the Reviewer Agent. You evaluate the Generator's JSON output. "
+ JSON_ONLY_RULES
+ "\n\n"
+ "Output schema (MUST match exactly):\n"
+ json.dumps(schema_example, ensure_ascii=False)
+ "\n\n"
+ "Evaluation criteria:\n"
+ "- Age appropriateness for the given grade\n"
+ "- Conceptual correctness\n"
+ "- Clarity\n"
+ "- Alignment between explanation and MCQs (MCQs must only test introduced concepts)\n"
+ "\n"
+ "If anything is wrong, set status='fail' and list concrete issues in feedback. "
+ "If everything is good, status='pass' and feedback should be an empty list."
)
def reviewer_user_prompt(grade: int, topic: str, generator_output: Dict[str, Any]) -> str:
"""Provide review context, including grade/topic, so the reviewer can judge appropriateness."""
payload = {
"grade": grade,
"topic": topic,
"generator_output": generator_output,
}
return "Review the following (JSON):\n" + json.dumps(payload, ensure_ascii=False)
|