innercontext/backend
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
..
alembic feat(api): implement Phase 2 token optimization and reasoning capture 2026-03-06 10:26:29 +01:00
innercontext fix(api): resolve function tool UUID mismatch and MAX_TOKENS errors 2026-03-06 10:44:12 +01:00
tests style: apply black and isort formatting 2026-03-06 10:17:00 +01:00
.env.example fix: load .env via python-dotenv; SQLite default for local dev 2026-02-26 20:51:13 +01:00
.python-version Initial commit: backend API, data models, and test suite 2026-02-26 15:10:24 +01:00
alembic.ini feat(backend): add Alembic migrations 2026-02-28 20:14:57 +01:00
db.py Initial commit: backend API, data models, and test suite 2026-02-26 15:10:24 +01:00
main.py style: apply black and isort formatting 2026-03-06 10:17:00 +01:00
pyproject.toml chore(backend): enable psycopg binary dependency 2026-03-04 21:46:38 +01:00
README.md Initial commit: backend API, data models, and test suite 2026-02-26 15:10:24 +01:00
skincare.yaml Initial commit: backend API, data models, and test suite 2026-02-26 15:10:24 +01:00
test_query.py refactor(llm): optimize Gemini config profiles for extraction and creativity 2026-03-03 21:24:23 +01:00
uv.lock chore(backend): enable psycopg binary dependency 2026-03-04 21:46:38 +01:00

See the root README for setup and usage instructions.