update
This commit is contained in:
@@ -137,6 +137,38 @@ def _card_facts(env: _Env, block_title: str) -> str:
|
||||
return grounding or env.fallback_facts
|
||||
|
||||
|
||||
async def _card_examples(env: _Env, block_norm: str, subs: list[dict],
|
||||
include_unmatched: bool = True) -> str:
|
||||
"""Verified worked examples of the block as writer input, matched to `subs` via
|
||||
sub_norm (a split half gets only its own). Rows whose sub does not match (generation
|
||||
mismatch) go to the full writer / split part 1 so they never vanish silently."""
|
||||
rows = await db.get_sub_artefakte(env.topic, type="example", block_norm=block_norm)
|
||||
if not rows:
|
||||
return ""
|
||||
wanted = {_norm_title(s["title"]) for s in subs}
|
||||
out = []
|
||||
for r in rows:
|
||||
matched = r["sub_norm"] in wanted
|
||||
if not matched and not include_unmatched:
|
||||
continue
|
||||
data = json.loads(r["data"]) if isinstance(r["data"], str) else (r["data"] or {})
|
||||
steps = " ".join(f"{i}) {s}" for i, s in enumerate(data.get("steps") or [], 1))
|
||||
where = (f"Subbaustein „{r['sub_title']}“" if matched
|
||||
else "Subbaustein unklar — dort einweben, wo es fachlich passt")
|
||||
out.append(f"- {where}:\n Problem: {data.get('problem', '')}\n"
|
||||
f" Schritte: {steps}\n Ergebnis: {data.get('result', '')}")
|
||||
if not out:
|
||||
return ""
|
||||
return ("VERIFIED WORKED EXAMPLES (already fact-checked; each belongs to ONE subblock):\n"
|
||||
+ "\n".join(out) + "\n"
|
||||
"Weave each example into the ausführlich text of EXACTLY its subblock, right "
|
||||
"after the concept it applies has been explained — as a short worked-through "
|
||||
"passage (problem → steps → result recognizable, flowing prose or a compact "
|
||||
"numbered list). Take all values and results over VERBATIM, never recompute "
|
||||
"or alter them. NEVER put examples into the compact layer. Subblocks without "
|
||||
"an example get none.")
|
||||
|
||||
|
||||
def _card_assignment(env: _Env, card: dict) -> str:
|
||||
from guide import _level_label
|
||||
lines = [f"- {card['block']}"]
|
||||
@@ -254,7 +286,10 @@ async def _write_split(env: _Env, card: dict, ziele_text: str):
|
||||
prompt=_prompt("Guide-Writer-Board", topic=env.topic, format_name=env.format,
|
||||
chapter=card.get("chapter") or "Inhalte",
|
||||
assignment=assignment, ziele=ziele_text,
|
||||
facts=_card_facts(env, card["block"]), gaps="\n" + hints[i] + "\n",
|
||||
facts=_card_facts(env, card["block"]),
|
||||
examples=await _card_examples(env, norm, parts[i],
|
||||
include_unmatched=(i == 0)),
|
||||
gaps="\n" + hints[i] + "\n",
|
||||
spec=env.spec, out_path=path, extra=_extra(env.instructions)),
|
||||
role="guide", capabilities="files", payload=_payload,
|
||||
timeout=_timeout("writer", 1))
|
||||
@@ -300,7 +335,9 @@ async def _stage_writer(env: _Env, card: dict) -> bool:
|
||||
prompt=_prompt("Guide-Writer-Board", topic=env.topic, format_name=env.format,
|
||||
chapter=card.get("chapter") or "Inhalte",
|
||||
assignment=_card_assignment(env, card), ziele=ziele_text,
|
||||
facts=_card_facts(env, card["block"]), gaps=gaps, spec=env.spec,
|
||||
facts=_card_facts(env, card["block"]),
|
||||
examples=await _card_examples(env, norm, env.subs_by_title.get(card["block"], [])),
|
||||
gaps=gaps, spec=env.spec,
|
||||
out_path=path, extra=_extra(env.instructions)),
|
||||
role="guide", capabilities="files", payload=_payload,
|
||||
timeout=_timeout("writer", 1))
|
||||
@@ -320,6 +357,9 @@ async def _stage_fakten_gate(env: _Env, card: dict) -> bool:
|
||||
await _set(env, card, status="error", gate_info="Writer-Fragment unlesbar")
|
||||
return False
|
||||
facts = _card_facts(env, card["block"])
|
||||
ex = await _card_examples(env, norm, env.subs_by_title.get(card["block"], []))
|
||||
if ex: # the fix agent sees the same facts variable — examples survive the fix pass
|
||||
facts += "\n\nVERIFIED WORKED EXAMPLES (count as verified facts for this check):\n" + ex
|
||||
path = env.slot(f"gate-{_safe(norm)}-r{card['writer_rounds']}.json")
|
||||
status, claims = await run_single_slot(
|
||||
env.ctx, f"Fakten-Gate {card['block']}", key=f"{env.guide_id}-gate-{_safe(norm)}-r{card['writer_rounds']}",
|
||||
|
||||
Reference in New Issue
Block a user