innercontext/backend/alembic/versions
Piotr Oleszczyk c87d1b8581 feat(api): implement Phase 2 token optimization and reasoning capture
- Add tiered context system (summary/detailed/full) to reduce token usage by 70-80%
- Replace old _build_products_context with build_products_context_summary_list (Tier 1: ~15 tokens/product vs 150)
- Optimize function tool responses: exclude INCI list by default (saves ~15KB/product)
- Reduce actives from 24 to top 5 in function tools
- Add reasoning_chain field to AICallLog model for observability
- Implement _extract_thinking_content to capture LLM reasoning (MEDIUM thinking level)
- Strengthen prompt enforcement for prohibited fields (dose, amount, quantity)
- Update get_creative_config to use MEDIUM thinking level instead of LOW

Token Savings:
- Routine suggestions: 9,613 → ~1,300 tokens (-86%)
- Batch planning: 12,580 → ~1,800 tokens (-86%)
- Function tool responses: ~15KB → ~2KB per product (-87%)

Breaks discovered in log analysis (ai_call_log.json):
- Lines 10, 27, 61, 78: LLM returned prohibited dose field
- Line 85: MAX_TOKENS failure (output truncated)

Phase 2 complete. Next: two-phase batch planning with safety verification.
2026-03-06 10:26:29 +01:00
..
1f7e3b9c4a2d_add_user_profile_table.py feat(profile): add profile settings and LLM user context 2026-03-05 15:57:21 +01:00
7c91e4b2af38_replace_price_tier_with_objective_price_fields.py feat(products): compute price tiers from objective price/use 2026-03-04 14:47:18 +01:00
8e4c1b7a9d2f_drop_usage_notes_and_contraindications_from_products.py refactor(products): remove usage notes and contraindications fields 2026-03-05 10:11:24 +01:00
60c8e1ade29d_add_validation_fields_to_ai_call_logs.py feat(api): add LLM response validation and input sanitization 2026-03-06 10:16:47 +01:00
2697b4f1972d_add_reasoning_chain_to_ai_call_logs.py feat(api): implement Phase 2 token optimization and reasoning capture 2026-03-06 10:26:29 +01:00
a1b2c3d4e5f6_add_ai_call_logs.py feat(routines): add minoxidil beard/mustache option to routine suggestions 2026-03-01 19:46:07 +01:00
b2c3d4e5f6a1_add_finish_reason_to_ai_call_logs.py fix(llm): log and handle non-STOP finish_reason from Gemini 2026-03-01 20:08:22 +01:00
c2d626a2b36c_initial_schema.py fix(backend): apply black/isort formatting and fix ruff noqa annotations 2026-03-01 17:27:07 +01:00
d3e4f5a6b7c8_add_tool_trace_to_ai_call_logs.py feat(api): add INCI tool-calling with normalized tool traces 2026-03-04 11:35:19 +01:00
e4f5a6b7c8d9_drop_product_interaction_columns.py refactor(products): remove obsolete interaction fields across stack 2026-03-04 12:42:12 +01:00
f1a2b3c4d5e6_add_async_pricing_jobs_and_snapshot_fields.py fix(backend): create pricetier enum before migration 2026-03-04 23:16:55 +01:00