Add Structured Roadmap Inputs and Enhance Goal Analysis Features
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m14s
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m14s
- Introduced `RoadmapStructuredInput` to encapsulate structured inputs for start situation, target state, and roadmap notes. - Updated `ProgressionPathSuggestRequest` to include new fields for structured roadmap inputs. - Implemented parsing logic for goal queries to extract start and target states, enhancing the goal analysis process. - Enhanced `build_goal_analysis` to utilize structured inputs, improving the clarity and relevance of generated goals. - Updated the `ExerciseProgressionPathBuilder` component to support new structured input fields, enhancing user experience. - Incremented application version to 0.8.210 to reflect these changes.
This commit is contained in:
1 parent
87f258be38
commit
9dd44ce3ca
5 files changed
+428
-18
No files matched your search
@@ -109,6 +109,14 @@ class StageSpecArtifact(BaseModel):
|
||||
anti_patterns: List[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
class RoadmapStructuredInput(BaseModel):
|
||||
"""Optionale Strukturierung: Start, Ziel, Ergänzungen (Progressionsgraph, kein Gruppen-Tracking)."""
|
||||
|
||||
start_situation: Optional[str] = Field(default=None, max_length=2000)
|
||||
target_state: Optional[str] = Field(default=None, max_length=2000)
|
||||
roadmap_notes: Optional[str] = Field(default=None, max_length=2000)
|
||||
|
||||
|
||||
class RoadmapOverridePayload(BaseModel):
|
||||
"""Vom Trainer bearbeitete Major Steps — steuert Retrieval ohne erneute Roadmap-KI."""
|
||||
|
||||
@@ -116,6 +124,9 @@ class RoadmapOverridePayload(BaseModel):
|
||||
stage_specs: Optional[List[StageSpecArtifact]] = None
|
||||
|
||||
|
||||
_GENERIC_START_MARKER = "Voraussetzungen der Zielgruppe werden im Progressionsgraphen nicht analysiert"
|
||||
|
||||
|
||||
class ProgressionRoadmapContext(BaseModel):
|
||||
goal_query: str
|
||||
max_steps: int = Field(ge=2, le=10, default=5)
|
||||
@@ -268,34 +279,177 @@ def _topic_label(brief: PlanningSemanticBrief) -> str:
|
||||
return (brief.primary_topic or brief.retrieval_query or "Technik").strip()
|
||||
|
||||
|
||||
_PHASE_TOPIC_WORDS = frozenset(
|
||||
{"einstieg", "grundlage", "vertiefung", "anwendung", "perfektion", "technik"}
|
||||
)
|
||||
|
||||
|
||||
def _extract_topic_from_goal_query(goal_query: str, brief: PlanningSemanticBrief) -> str:
|
||||
q = (goal_query or "").strip()
|
||||
m = re.match(r"^(.+?)\s+von\s+(?:der|die|dem|das|einer?|einem)\s+", q, flags=re.IGNORECASE)
|
||||
if m:
|
||||
cand = m.group(1).strip().rstrip(".,;")
|
||||
if len(cand) >= 3:
|
||||
return cand
|
||||
topic = _topic_label(brief)
|
||||
if topic and topic.lower() not in _PHASE_TOPIC_WORDS and len(topic) >= 4:
|
||||
return topic
|
||||
return topic or "Technik"
|
||||
|
||||
|
||||
def parse_start_target_from_goal_query(goal_query: str) -> Tuple[Optional[str], Optional[str]]:
|
||||
"""„von … bis …“ aus Freitext (z. B. Kumite Beinarbeit von X bis Y)."""
|
||||
q = (goal_query or "").strip()
|
||||
if not q:
|
||||
return None, None
|
||||
m = re.search(
|
||||
r"\bvon\s+((?:(?:der|die|dem|das|einer?|einem)\s+)?.+?)\s+bis\s+"
|
||||
r"(?:zur?|zum|zu der|zu einem)?\s*(.+?)\s*$",
|
||||
q,
|
||||
flags=re.IGNORECASE | re.DOTALL,
|
||||
)
|
||||
if not m:
|
||||
return None, None
|
||||
start = m.group(1).strip().rstrip(".,;")
|
||||
target = m.group(2).strip().rstrip(".,;")
|
||||
if len(start) < 4 or len(target) < 4:
|
||||
return None, None
|
||||
return start[:800], target[:800]
|
||||
|
||||
|
||||
def _roadmap_llm_goal_block(
|
||||
goal_query: str,
|
||||
*,
|
||||
structured: Optional[RoadmapStructuredInput] = None,
|
||||
parsed_start: Optional[str] = None,
|
||||
parsed_target: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Reicher Kontext für Roadmap-LLM ohne zwingend neue Prompt-Migration."""
|
||||
lines = [f"Gesamtanfrage: {(goal_query or '').strip()}"]
|
||||
start = (structured.start_situation if structured else None) or parsed_start
|
||||
target = (structured.target_state if structured else None) or parsed_target
|
||||
notes = structured.roadmap_notes if structured else None
|
||||
if start:
|
||||
lines.append(f"Ausgangslage/Startpunkt: {start.strip()}")
|
||||
if target:
|
||||
lines.append(f"Zielzustand: {target.strip()}")
|
||||
if notes and notes.strip():
|
||||
lines.append(f"Ergänzungen (Fokus, Gruppe, Besonderheiten): {notes.strip()}")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def build_goal_analysis(
|
||||
goal_query: str,
|
||||
brief: PlanningSemanticBrief,
|
||||
*,
|
||||
structured: Optional[RoadmapStructuredInput] = None,
|
||||
) -> GoalAnalysisArtifact:
|
||||
"""Phase A — deterministisch aus Anfrage + Semantic Brief."""
|
||||
topic = _topic_label(brief)
|
||||
target = goal_query.strip() or f"Entwicklung {topic}"
|
||||
"""Phase A — aus Anfrage, optionalen Feldern und Semantic Brief."""
|
||||
topic = _extract_topic_from_goal_query(goal_query, brief)
|
||||
parsed_start, parsed_target = parse_start_target_from_goal_query(goal_query)
|
||||
|
||||
start = (structured.start_situation if structured else None) or parsed_start
|
||||
target = (structured.target_state if structured else None) or parsed_target
|
||||
notes = (structured.roadmap_notes if structured else None) or ""
|
||||
|
||||
if not target:
|
||||
target = goal_query.strip() or f"Entwicklung {topic}"
|
||||
|
||||
arc = list(brief.development_arc or [])
|
||||
start_phase = arc[0] if arc else "grundlage"
|
||||
target_phase = arc[-1] if arc else "perfektion"
|
||||
|
||||
if start:
|
||||
start_assumption = start.strip()
|
||||
else:
|
||||
start_assumption = (
|
||||
f"Einstieg auf Niveau „{start_phase}“ — {_GENERIC_START_MARKER} "
|
||||
"(erst Trainingsplanung)."
|
||||
)
|
||||
|
||||
criteria: List[str] = []
|
||||
if brief.must_phrases:
|
||||
criteria.extend(brief.must_phrases[:3])
|
||||
if topic:
|
||||
criteria.append(f"klarer Bezug zu {topic}")
|
||||
if start and target:
|
||||
criteria.append(f"nachvollziehbarer Übergang von „{start[:80]}“ zu „{target[:80]}“")
|
||||
if notes.strip():
|
||||
criteria.append(f"Berücksichtigung: {notes.strip()[:200]}")
|
||||
|
||||
constraints: Dict[str, Any] = {"partner_required": False, "group_analysis": False}
|
||||
if notes.strip():
|
||||
constraints["trainer_notes"] = notes.strip()[:500]
|
||||
|
||||
return GoalAnalysisArtifact(
|
||||
primary_topic=topic,
|
||||
start_assumption=(
|
||||
f"Einstieg auf Niveau „{start_phase}“ — Voraussetzungen der Zielgruppe werden im "
|
||||
"Progressionsgraphen nicht analysiert (erst Trainingsplanung)."
|
||||
),
|
||||
target_state=target,
|
||||
start_assumption=start_assumption,
|
||||
target_state=target.strip(),
|
||||
success_criteria=criteria or [f"sichere Entwicklung Richtung {target_phase}"],
|
||||
constraints={"partner_required": False, "group_analysis": False},
|
||||
constraints=constraints,
|
||||
)
|
||||
|
||||
|
||||
def _has_specific_start_target(goal_analysis: GoalAnalysisArtifact) -> bool:
|
||||
start = (goal_analysis.start_assumption or "").strip()
|
||||
target = (goal_analysis.target_state or "").strip()
|
||||
if _GENERIC_START_MARKER in start:
|
||||
return False
|
||||
return len(start) >= 6 and len(target) >= 6 and start != target
|
||||
|
||||
|
||||
def _target_facets(target: str) -> List[str]:
|
||||
parts = re.split(r"\s+und\s+|\s+mit\s+|,\s*", target, flags=re.IGNORECASE)
|
||||
out: List[str] = []
|
||||
for p in parts:
|
||||
s = p.strip().rstrip(".,;")
|
||||
if len(s) >= 5 and s.lower() not in {x.lower() for x in out}:
|
||||
out.append(s[:200])
|
||||
return out[:6]
|
||||
|
||||
|
||||
def develop_micro_objectives_from_start_target(
|
||||
goal_analysis: GoalAnalysisArtifact,
|
||||
*,
|
||||
min_count: int,
|
||||
) -> List[MicroObjective]:
|
||||
"""Zwischenziele entlang Start → Ziel (heuristisch, themenspezifisch)."""
|
||||
topic = goal_analysis.primary_topic or "Technik"
|
||||
start = goal_analysis.start_assumption.strip()
|
||||
target = goal_analysis.target_state.strip()
|
||||
facets = _target_facets(target)
|
||||
phases = ["einstieg", "grundlage", "vertiefung", "anwendung", "perfektion"]
|
||||
|
||||
titles: List[str] = [f"{topic}: Ausgang — {start}"]
|
||||
n_middle = max(0, min_count - 2)
|
||||
for i in range(n_middle):
|
||||
if facets and i < len(facets):
|
||||
titles.append(f"{topic}: {facets[i]} — schrittweise einführen")
|
||||
else:
|
||||
titles.append(
|
||||
f"{topic}: Übergangsschritt {i + 1} — Annäherung vom Ausgang zum Ziel"
|
||||
)
|
||||
titles.append(f"{topic}: Ziel — {target}")
|
||||
|
||||
while len(titles) < min_count:
|
||||
titles.insert(max(1, len(titles) - 1), f"{topic}: Vertiefung vor Zielerreichung")
|
||||
|
||||
titles = titles[:max(min_count, 2)]
|
||||
micro: List[MicroObjective] = []
|
||||
for i, title in enumerate(titles):
|
||||
phase = phases[min(i, len(phases) - 1)]
|
||||
micro.append(
|
||||
MicroObjective(
|
||||
id=f"m{i + 1}",
|
||||
phase=phase,
|
||||
title=title,
|
||||
weight=0.9 if i in (0, len(titles) - 1) else 0.85,
|
||||
depends_on=[f"m{i}"] if i > 0 else [],
|
||||
)
|
||||
)
|
||||
return micro
|
||||
|
||||
|
||||
def _micro_title_for_phase(phase: str, topic: str) -> str:
|
||||
p = (phase or "vertiefung").lower()
|
||||
labels = {
|
||||
@@ -314,7 +468,10 @@ def develop_micro_objectives(
|
||||
goal_analysis: GoalAnalysisArtifact,
|
||||
min_count: int = 6,
|
||||
) -> List[MicroObjective]:
|
||||
"""Phase B1 — Zwischenziele (heuristisch aus development_arc)."""
|
||||
"""Phase B1 — Zwischenziele (Start→Ziel oder development_arc-Fallback)."""
|
||||
if _has_specific_start_target(goal_analysis):
|
||||
return develop_micro_objectives_from_start_target(goal_analysis, min_count=min_count)
|
||||
|
||||
topic = goal_analysis.primary_topic or _topic_label(brief)
|
||||
arc = [str(p).lower() for p in (brief.development_arc or []) if str(p).strip()]
|
||||
seen_phases: set = set()
|
||||
@@ -592,11 +749,12 @@ def roadmap_context_from_override(
|
||||
max_steps: int,
|
||||
semantic_brief: PlanningSemanticBrief,
|
||||
override: RoadmapOverridePayload,
|
||||
structured: Optional[RoadmapStructuredInput] = None,
|
||||
) -> ProgressionRoadmapContext:
|
||||
"""Phase F4: bearbeitete Roadmap → stage_specs → Retrieval (ohne LLM-Roadmap)."""
|
||||
majors = normalize_major_steps_for_override(override.major_steps, max_steps=max_steps)
|
||||
effective_max = len(majors)
|
||||
goal_analysis = build_goal_analysis(goal_query, semantic_brief)
|
||||
goal_analysis = build_goal_analysis(goal_query, semantic_brief, structured=structured)
|
||||
stage_specs: List[StageSpecArtifact]
|
||||
if override.stage_specs and len(override.stage_specs) >= effective_max:
|
||||
stage_specs = []
|
||||
@@ -632,6 +790,31 @@ def roadmap_context_from_override(
|
||||
)
|
||||
|
||||
|
||||
def _merge_structured_into_goal_analysis(
|
||||
llm_ga: GoalAnalysisArtifact,
|
||||
*,
|
||||
goal_query: str,
|
||||
brief: PlanningSemanticBrief,
|
||||
structured: Optional[RoadmapStructuredInput],
|
||||
) -> GoalAnalysisArtifact:
|
||||
ga_struct = build_goal_analysis(goal_query, brief, structured=structured)
|
||||
if not _has_specific_start_target(ga_struct):
|
||||
return llm_ga
|
||||
merged_criteria = list(
|
||||
dict.fromkeys((llm_ga.success_criteria or []) + (ga_struct.success_criteria or []))
|
||||
)[:6]
|
||||
merged_constraints = {**(llm_ga.constraints or {}), **(ga_struct.constraints or {})}
|
||||
return llm_ga.model_copy(
|
||||
update={
|
||||
"primary_topic": ga_struct.primary_topic or llm_ga.primary_topic,
|
||||
"start_assumption": ga_struct.start_assumption,
|
||||
"target_state": ga_struct.target_state,
|
||||
"success_criteria": merged_criteria,
|
||||
"constraints": merged_constraints,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def run_progression_roadmap_pipeline(
|
||||
goal_query: str,
|
||||
*,
|
||||
@@ -639,20 +822,33 @@ def run_progression_roadmap_pipeline(
|
||||
semantic_brief: Optional[PlanningSemanticBrief] = None,
|
||||
cur=None,
|
||||
include_llm_roadmap: bool = False,
|
||||
structured: Optional[RoadmapStructuredInput] = None,
|
||||
) -> ProgressionRoadmapContext:
|
||||
"""Workflow-lite: Phase A → B → C. LLM über ai_prompts-Slugs; deterministischer Fallback."""
|
||||
brief = semantic_brief or build_semantic_brief(goal_query)
|
||||
parsed_start, parsed_target = parse_start_target_from_goal_query(goal_query)
|
||||
llm_goal_query = _roadmap_llm_goal_block(
|
||||
goal_query,
|
||||
structured=structured,
|
||||
parsed_start=parsed_start,
|
||||
parsed_target=parsed_target,
|
||||
)
|
||||
ctx = ProgressionRoadmapContext(
|
||||
goal_query=goal_query.strip(),
|
||||
max_steps=max_steps,
|
||||
semantic_brief=brief_to_summary_dict(brief),
|
||||
)
|
||||
|
||||
goal_analysis = build_goal_analysis(goal_query, brief)
|
||||
goal_analysis = build_goal_analysis(goal_query, brief, structured=structured)
|
||||
if include_llm_roadmap and cur is not None:
|
||||
llm_ga, ga_ok = try_llm_goal_analysis(cur, goal_query=goal_query, brief=brief)
|
||||
llm_ga, ga_ok = try_llm_goal_analysis(cur, goal_query=llm_goal_query, brief=brief)
|
||||
if ga_ok and llm_ga:
|
||||
goal_analysis = llm_ga
|
||||
goal_analysis = _merge_structured_into_goal_analysis(
|
||||
llm_ga,
|
||||
goal_query=goal_query,
|
||||
brief=brief,
|
||||
structured=structured,
|
||||
)
|
||||
ctx.llm_goal_analysis_applied = True
|
||||
ctx.prompt_slugs.append(PROMPT_SLUG_GOAL_ANALYSIS)
|
||||
ctx.goal_analysis = goal_analysis
|
||||
@@ -661,7 +857,7 @@ def run_progression_roadmap_pipeline(
|
||||
if include_llm_roadmap and cur is not None:
|
||||
llm_rm, rm_ok = try_llm_roadmap(
|
||||
cur,
|
||||
goal_query=goal_query,
|
||||
goal_query=llm_goal_query,
|
||||
brief=brief,
|
||||
goal_analysis=goal_analysis,
|
||||
max_steps=max_steps,
|
||||
@@ -689,7 +885,7 @@ def run_progression_roadmap_pipeline(
|
||||
if include_llm_roadmap and cur is not None:
|
||||
llm_specs, spec_ok = try_llm_stage_specs(
|
||||
cur,
|
||||
goal_query=goal_query,
|
||||
goal_query=llm_goal_query,
|
||||
goal_analysis=goal_analysis,
|
||||
major_steps=roadmap.major_steps,
|
||||
)
|
||||
@@ -734,7 +930,9 @@ __all__ = [
|
||||
"ProgressionRoadmapContext",
|
||||
"RoadmapArtifact",
|
||||
"RoadmapOverridePayload",
|
||||
"RoadmapStructuredInput",
|
||||
"normalize_major_steps_for_override",
|
||||
"parse_start_target_from_goal_query",
|
||||
"roadmap_context_from_override",
|
||||
"StageSpecArtifact",
|
||||
"build_goal_analysis",
|
||||
|
||||
Reference in new issue
Block a user