feat: Phase 1 - Fragenergänzung + Strukturierter Container
Backend: - question_augmenter.py (290 Zeilen): Hybrid-Modell für Fragenergänzungen * merge_question_augmentations(): Knotengebundene Fragen überschreiben Prompt-Defaults * augment_prompt_with_questions(): Markdown-formatierte Fragenergänzung * parse_question_augmentations_from_jsonb(): JSONB → QuestionAugmentation[] - result_container_parser.py (250 Zeilen): Markdown-Sektionen-Parsing * parse_result_container(): Extrahiert Analysekern, Entscheidungsanteil, Begründungsanker * validate_decision_signal(): Normalisierung gegen answer_spectrum * Fallback-Parsing bei unstrukturierten Antworten - routers/workflow_questions.py (236 Zeilen): CRUD für workflow_question_catalog * GET /api/workflow/questions (mit active_only Filter) * POST/PUT/DELETE (Admin only, Soft Delete) - prompt_executor.py: Integration in execute_base_prompt() * Fragenergänzung vor LLM-Call (wenn node_questions oder catalog vorhanden) * Result-Container-Parsing nach LLM-Response - main.py: Router-Registrierung (workflow_questions) Tests: - test_phase1_question_augmenter.py (8 Tests): Hybrid-Modell, Formatierung, JSONB-Parsing - test_phase1_result_container_parser.py (17 Tests): Sektion-Extraktion, Decision-Parsing, Validierung Alle 25 Unit-Tests bestanden. version: 0.9j (backend) module: workflow 0.2.0 Konzept: .claude/task/Workflow_engine_prompting_engine/konzept_workflow_engine_konsolidated.md (Phase 1)
This commit is contained in:
1 parent
b5be6e21a5
commit
ca562b7130
8 files changed
+1237
-9
No files matched your search
@@ -205,18 +205,54 @@ async def execute_base_prompt(
|
||||
variables: Dict[str, Any],
|
||||
openrouter_call_func,
|
||||
enable_debug: bool = False,
|
||||
catalog: Optional[Dict] = None
|
||||
catalog: Optional[Dict] = None,
|
||||
node_questions: Optional[list] = None # Phase 1: Knotengebundene Fragen
|
||||
) -> Dict[str, Any]:
|
||||
"""Execute a base-type prompt (single template)."""
|
||||
"""
|
||||
Execute a base-type prompt (single template).
|
||||
|
||||
Phase 1: Unterstützt Fragenergänzungen (Hybridmodell)
|
||||
- node_questions: Knotengebundene Fragen (Priorität 1)
|
||||
- prompt.question_augmentations: Prompt-Defaults (Priorität 2)
|
||||
"""
|
||||
from question_augmenter import (
|
||||
parse_question_augmentations_from_jsonb,
|
||||
merge_question_augmentations,
|
||||
augment_prompt_with_questions
|
||||
)
|
||||
from result_container_parser import parse_result_container_robust
|
||||
|
||||
template = prompt.get('template')
|
||||
if not template:
|
||||
raise HTTPException(400, f"Base prompt missing template: {prompt['slug']}")
|
||||
|
||||
debug_info = {} if enable_debug else None
|
||||
|
||||
# Phase 1: Load question augmentations (Hybridmodell)
|
||||
prompt_default_questions = None
|
||||
if prompt.get('question_augmentations'):
|
||||
try:
|
||||
from workflow_models import QuestionAugmentation
|
||||
prompt_default_questions = parse_question_augmentations_from_jsonb(
|
||||
prompt['question_augmentations']
|
||||
)
|
||||
except Exception as e:
|
||||
if enable_debug:
|
||||
debug_info['question_augmentations_error'] = str(e)
|
||||
|
||||
# Merge question augmentations (Vorrangregel: Knoten > Prompt)
|
||||
questions = merge_question_augmentations(node_questions, prompt_default_questions)
|
||||
|
||||
# Resolve placeholders (with optional catalog for |d modifier)
|
||||
prompt_text = resolve_placeholders(template, variables, debug_info, catalog)
|
||||
|
||||
# Phase 1: Augment prompt with questions (if any)
|
||||
if questions:
|
||||
prompt_text = augment_prompt_with_questions(prompt_text, questions)
|
||||
if enable_debug:
|
||||
debug_info['question_augmentations_count'] = len(questions)
|
||||
debug_info['question_types'] = [q.type for q in questions]
|
||||
|
||||
if enable_debug:
|
||||
debug_info['template'] = template
|
||||
debug_info['final_prompt'] = prompt_text[:500] + ('...' if len(prompt_text) > 500 else '')
|
||||
@@ -229,12 +265,24 @@ async def execute_base_prompt(
|
||||
debug_info['ai_response_length'] = len(response)
|
||||
debug_info['ai_response_preview'] = response[:200] + ('...' if len(response) > 200 else '')
|
||||
|
||||
# Validate JSON if required
|
||||
output_format = prompt.get('output_format', 'text')
|
||||
if output_format == 'json':
|
||||
output = validate_json_output(response, prompt.get('output_schema'), debug_info if enable_debug else None)
|
||||
# Phase 1: Parse structured result if questions were used
|
||||
if questions:
|
||||
expected_question_types = [q.type for q in questions]
|
||||
container = parse_result_container_robust(response, expected_question_types)
|
||||
|
||||
if enable_debug:
|
||||
debug_info['parsing_status'] = container['parsing_status']
|
||||
debug_info['parsing_warnings'] = container.get('warnings', [])
|
||||
|
||||
output = container
|
||||
output_format = 'structured_container' # New format type
|
||||
else:
|
||||
output = response
|
||||
# Legacy behavior: Validate JSON if required
|
||||
output_format = prompt.get('output_format', 'text')
|
||||
if output_format == 'json':
|
||||
output = validate_json_output(response, prompt.get('output_schema'), debug_info if enable_debug else None)
|
||||
else:
|
||||
output = response
|
||||
|
||||
result = {
|
||||
"type": "base",
|
||||
|
||||
Reference in new issue
Block a user