diff --git a/backend/app/core/ai_tree_generator_service.py b/backend/app/core/ai_tree_generator_service.py index 34af11d2..c08f47a3 100644 --- a/backend/app/core/ai_tree_generator_service.py +++ b/backend/app/core/ai_tree_generator_service.py @@ -202,14 +202,23 @@ async def generate_branch_detail( for attempt in range(2): response = await client.messages.create( model=settings.AI_MODEL, - max_tokens=4096, + max_tokens=8192, system=BRANCH_DETAIL_SYSTEM_PROMPT, messages=messages, ) - raw_text = _strip_markdown_fences(response.content[0].text) total_input += response.usage.input_tokens total_output += response.usage.output_tokens + logger.debug( + "branch_detail attempt=%d stop_reason=%s content_blocks=%d output_tokens=%d", + attempt, + response.stop_reason, + len(response.content), + response.usage.output_tokens, + ) + raw_text = _strip_markdown_fences(response.content[0].text) if response.content else "" + if not raw_text: + logger.warning("branch_detail attempt=%d returned empty text, stop_reason=%s", attempt, response.stop_reason) try: branch_tree = json.loads(raw_text)