Enhance Planning Exercise Functionality and LLM Integration
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m15s

- Added support for the new planning exercise expectation profile slug in the AI prompt runtime.
- Refactored SQL parameter handling in the planning exercise retrieval process to ensure correct binding for full-text search.
- Updated the planning exercise suggestion logic to incorporate LLM expectation handling, improving the accuracy of exercise recommendations.
- Introduced new functions to determine when to run the LLM expectation pipeline, enhancing the decision-making process for exercise suggestions.
- Incremented version to 0.8.176 and updated changelog to reflect these enhancements in planning AI capabilities.
This commit is contained in:
Lars committed 2026-05-22 23:08:53 +02:00
1 parent 04cc77d501
commit 5c882985e0
10 files changed
+332 -15

No files matched your search

+66 -6
View File
@@ -12,6 +12,7 @@ from __future__ import annotations
import re
from typing import Any, Dict, List, Mapping, Optional, Tuple
from planning_exercise_expectation import try_build_planning_expectation_from_context
from planning_exercise_intent import (
PlanningQueryIntentParsed,
resolve_query_intent_catalog_ids,
@@ -37,6 +38,7 @@ _SIMPLE_PRESET_PATTERNS = (
r"^(vorschlag|vorschlagen|empfehl\w*)\s*(für|fuer)?\s*(die\s+)?(n[aä]chste|naechste)?\s*(übung|uebung)?\.?$",
r"^n[aä]chste\s+übung$",
r"^n[aä]chste\s+uebung$",
r"^(n[aä]chste|naechste)\s+(übung|uebung)\s+planen\.?$",
)
_ADDITIVE_MARKERS = (
@@ -89,6 +91,20 @@ def classify_planning_scenario(
return SCENARIO_FREE_SEARCH
def should_run_llm_expectation_pipeline(
scenario: str,
*,
include_llm_intent: bool,
has_planning_reference: bool,
) -> bool:
"""Preset/leere Anfrage mit Planungsbezug → LLM-Erwartungsprofil statt Query-Intent."""
if not include_llm_intent:
return False
if not has_planning_reference:
return False
return scenario == SCENARIO_PRESET_NEXT
def should_run_llm_intent_pipeline(
query: Optional[str],
scenario: str,
@@ -125,15 +141,16 @@ def should_run_llm_rank_pipeline(
*,
include_llm_rank: bool,
query_intent_applied: bool,
llm_expectation_applied: bool = False,
hits: Sequence[Mapping[str, Any]],
) -> bool:
"""
Maximal ein LLM-Call pro Request: wenn Intent-LLM lief, kein Rerank.
Maximal ein LLM-Call pro Request: wenn Intent- oder Erwartungs-LLM lief, kein Rerank.
Rerank nur bei längerer, komplexer Anfrage und unklarem Hybrid-Ranking.
"""
if not include_llm_rank:
return False
if query_intent_applied:
if query_intent_applied or llm_expectation_applied:
return False
if scenario == SCENARIO_PRESET_NEXT:
return False
@@ -241,7 +258,9 @@ def build_planning_target_with_query_pipeline(
scenario = classify_planning_scenario(query, heuristic_intent)
resolved_intent = heuristic_intent
llm_applied = False
llm_expectation_applied = False
parsed: Optional[PlanningQueryIntentParsed] = None
expectation_parsed: Optional[PlanningQueryIntentParsed] = None
resolved_skills: List[Dict[str, Any]] = []
if has_planning_reference:
@@ -257,8 +276,44 @@ def build_planning_target_with_query_pipeline(
base = PlanningTargetProfile(sources=["query_only"])
base_summary = base.to_summary_dict(cur)
target = base
if should_run_llm_intent_pipeline(query, scenario, include_llm_intent=include_llm_intent):
if should_run_llm_expectation_pipeline(
scenario,
include_llm_intent=include_llm_intent,
has_planning_reference=has_planning_reference,
):
expectation_parsed, llm_expectation_applied = try_build_planning_expectation_from_context(
cur,
heuristic_intent=heuristic_intent,
context_summary=context_summary,
target_profile_summary=base_summary,
)
parsed = expectation_parsed
if parsed and llm_expectation_applied:
if parsed.intent in {
"suggest_next",
"progression_next",
"deepen_exercise",
"continue_plan_goal",
"free_search",
}:
resolved_intent = parsed.intent
focus, style, tt, tg, skills, resolved_skills = resolve_query_intent_catalog_ids(cur, parsed)
if focus or style or tt or tg or skills or parsed.rationale:
target = merge_query_overlay_into_target(
base,
focus=focus,
style=style,
tt=tt,
tg=tg,
skills=skills,
emphasis=parsed.emphasis or "additive",
scenario=SCENARIO_PRESET_NEXT,
)
if "context_expectation" not in target.sources:
target.sources.append("context_expectation")
elif should_run_llm_intent_pipeline(query, scenario, include_llm_intent=include_llm_intent):
parsed, llm_applied = try_parse_planning_query_intent(
cur,
query=_normalize_query(query),
@@ -268,8 +323,7 @@ def build_planning_target_with_query_pipeline(
target_profile_summary=base_summary,
)
target = base
if parsed and llm_applied:
if parsed and llm_applied and not llm_expectation_applied:
if parsed.intent in {
"suggest_next",
"progression_next",
@@ -307,6 +361,8 @@ def build_planning_target_with_query_pipeline(
"intent": resolved_intent,
"heuristic_intent": heuristic_intent,
"llm_applied": llm_applied,
"llm_expectation_applied": llm_expectation_applied,
"profile_llm_applied": llm_applied or llm_expectation_applied,
"emphasis": parsed.emphasis if parsed else None,
"rationale": (parsed.rationale if parsed else None),
"skill_hints_resolved": resolved_skills,
@@ -331,12 +387,15 @@ def compose_retrieval_phase(
*,
profile_preselect: bool = False,
query_intent: bool = False,
llm_expectation: bool = False,
llm_rank: bool = False,
) -> str:
parts = ["profile_v1"]
if profile_preselect:
parts.append("profile_preselect")
if query_intent:
if llm_expectation:
parts.append("llm_expectation")
elif query_intent:
parts.append("query_intent")
if llm_rank:
parts.append("llm_rank")
@@ -351,6 +410,7 @@ __all__ = [
"compose_retrieval_phase",
"is_simple_preset_query",
"merge_query_overlay_into_target",
"should_run_llm_expectation_pipeline",
"should_run_llm_intent_pipeline",
"should_run_llm_rank_pipeline",
"deterministic_rank_confident",