innercontext/backend/innercontext
Piotr Oleszczyk 710b53e471 fix(api): resolve function tool UUID mismatch and MAX_TOKENS errors
Two critical bugs identified from production logs:

1. UUID Mismatch Bug (0 products returned from function tools):
   - Context shows 8-char short IDs: '63278801'
   - Function handler expected full UUIDs: '63278801-xxxx-...'
   - LLM requested short IDs, handler couldn't match → 0 products

   Fix: Index products by BOTH full UUID and short ID (first 8 chars)
   in build_product_details_tool_handler. Accept either format.
   Added deduplication to handle duplicate requests.
   Maintains Phase 2 token optimization (no context changes).

2. MAX_TOKENS Error (response truncation):
   - max_output_tokens=4096 includes thinking tokens (~3500)
   - Only ~500 tokens left for JSON response
   - MEDIUM thinking level (Phase 2) consumed budget

   Fix: Increase max_output_tokens from 4096 → 8192 across all
   creative endpoints (routines/suggest, routines/suggest-batch,
   products/suggest). Updated default in get_creative_config().

   Gives headroom: ~3500 thinking + ~4500 response = ~8000 total

From production logs (ai_call_logs):
- Log 71699654: Success but response_text null (function call only)
- Log 2db37c0f: MAX_TOKENS failure, tool returned 0 products

Both issues now resolved.
2026-03-06 10:44:12 +01:00
..
api fix(api): resolve function tool UUID mismatch and MAX_TOKENS errors 2026-03-06 10:44:12 +01:00
models feat(api): implement Phase 2 token optimization and reasoning capture 2026-03-06 10:26:29 +01:00
services feat(backend): move product pricing to async persisted jobs 2026-03-04 22:46:16 +01:00
validators feat(api): add LLM response validation and input sanitization 2026-03-06 10:16:47 +01:00
workers feat(backend): move product pricing to async persisted jobs 2026-03-04 22:46:16 +01:00
llm.py fix(api): resolve function tool UUID mismatch and MAX_TOKENS errors 2026-03-06 10:44:12 +01:00
llm_safety.py feat(api): add LLM response validation and input sanitization 2026-03-06 10:16:47 +01:00