fix(routines): include product safety and usage signals in prompts

Expose leave-on behavior, contraindications, safety alerts, and compact usage notes in AVAILABLE PRODUCTS so Gemini can make safer routine decisions with real-world product constraints.
This commit is contained in:
Piotr Oleszczyk 2026-03-04 02:42:16 +01:00
parent 9bbc34ffd2
commit c0eeb0425d

View file

@ -342,6 +342,7 @@ def _build_products_context(
entry = (
f' - id={ctx["id"]} name="{ctx["name"]}" brand="{ctx["brand"]}"'
f" category={ctx.get('category', '')} recommended_time={ctx.get('recommended_time', '')}"
f" leave_on={ctx.get('leave_on', '')}"
f" targets={ctx.get('targets', [])}"
)
if "actives" in ctx:
@ -378,14 +379,27 @@ def _build_products_context(
entry += f" effects={notable}"
if ctx.get("incompatible_with"):
entry += f" incompatible_with={ctx['incompatible_with']}"
if ctx.get("contraindications"):
entry += f" contraindications={ctx['contraindications']}"
if ctx.get("context_rules"):
entry += f" context_rules={ctx['context_rules']}"
safety = ctx.get("safety") or {}
if isinstance(safety, dict):
not_safe = {k: v for k, v in safety.items() if v is False}
if not_safe:
entry += f" safety_alerts={not_safe}"
if ctx.get("min_interval_hours"):
entry += f" min_interval_hours={ctx['min_interval_hours']}"
if ctx.get("max_frequency_per_week"):
entry += f" max_frequency_per_week={ctx['max_frequency_per_week']}"
usage_count = recent_usage_counts.get(p.id, 0)
entry += f" used_in_last_7_days={usage_count}"
usage_notes = ctx.get("usage_notes")
if usage_notes:
compact_notes = " ".join(str(usage_notes).split())
if len(compact_notes) > 260:
compact_notes = compact_notes[:257] + "..."
entry += f' usage_notes="{compact_notes}"'
lines.append(entry)
return "\n".join(lines) + "\n"