From a925415ef7cf0cb71066ff850e8517ee45349fb7 Mon Sep 17 00:00:00 2001 From: davegilligan Date: Mon, 25 May 2026 21:09:01 +0200 Subject: [PATCH] Fix advocate brief truncation: raise synthesis max_tokens to 6K Haiku synthesis had a hard cap of 2500 tokens which truncated the advocate JSON response (~4-6K tokens), causing decodeJsonObject() to fail and rendering the raw JSON string as the brief. Fix: remove the 2500-token Haiku override; introduce a per-mode limit (6000 for advocate, 4000 for deep-research) in $opts before the engine branch so all paths benefit. Co-Authored-By: Claude Sonnet 4.6 --- includes/DeepResearchAgent.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/DeepResearchAgent.php b/includes/DeepResearchAgent.php index eab2f5f..45a2236 100644 --- a/includes/DeepResearchAgent.php +++ b/includes/DeepResearchAgent.php @@ -1133,7 +1133,10 @@ PROMPT; ['role' => 'user', 'content' => $prompt], ]; $synthTemp = ($advocateRole !== '') ? min($temperature, 0.20) : $temperature; - $opts = ['json' => true, 'temperature' => $synthTemp, 'max_tokens' => 4000, 'timeout' => 180]; + // Advocate briefs require ~4-6K tokens (brief + strengths + weaknesses + uncertainty). + // Non-advocate deep-research responses are shorter (~2-3K). Use separate limits. + $synthMaxTokens = ($advocateRole !== '') ? 6000 : 4000; + $opts = ['json' => true, 'temperature' => $synthTemp, 'max_tokens' => $synthMaxTokens, 'timeout' => 180]; $thinkingTrace = null; try { @@ -1153,9 +1156,9 @@ PROMPT; $raw = $this->azure->withDeployment('gpt-4o')->chatText($messages, $opts); $deployLabel = 'gpt-4o'; } elseif ($engine === 'azure_mini' && $this->azure instanceof DbnBedrockGateway) { - // When Bedrock enabled, azure_mini → Haiku (fast, ~20-40s synthesis) + // When Bedrock enabled, azure_mini → Haiku (fast, ~20-50s synthesis) $haiku = $this->azure->withDeployment(DbnBedrockModelRouter::LITELLM_HAIKU); - $raw = $haiku->chatText($messages, array_merge($opts, ['max_tokens' => 2500, 'timeout' => 90])); + $raw = $haiku->chatText($messages, array_merge($opts, ['timeout' => 90])); $deployLabel = 'Claude Haiku 4.5 (AWS Bedrock)'; $thinkingTrace = null; } elseif ($engine === 'claude_sonnet' || ($this->azure instanceof DbnBedrockGateway)) {