From 71dda5b106b79759777a789680ccad8b2bd7efcc Mon Sep 17 00:00:00 2001 From: michaelxer <52305679+michaelxer@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:49:42 +0700 Subject: [PATCH] fix: respect user round count in deep research (#2896) The STOP_PROMPT did not include the target round count, so the LLM could decide to stop after 2-3 rounds even when the user requested 8. Additionally, min_rounds was capped at 3 regardless of max_rounds. - Add max_rounds to STOP_PROMPT so the LLM knows the target - Change min_rounds from min(3, max_rounds) to max(2, max_rounds - 2) Fixes #2863 Co-authored-by: michaelxer --- src/deep_research.py | 6 +++++- src/research_handler.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/deep_research.py b/src/deep_research.py index 7a314229b..204de7217 100644 --- a/src/deep_research.py +++ b/src/deep_research.py @@ -107,7 +107,7 @@ You are deciding whether a research report is comprehensive enough. **Current report:** {report} -**Rounds completed:** {round_num} +**Rounds completed:** {round_num} of {max_rounds} Based on the report so far, do we have enough information to answer the question \ comprehensively? Consider: @@ -115,6 +115,9 @@ comprehensively? Consider: - Are there obvious gaps or unanswered sub-questions? - Is the evidence sufficient and from multiple sources? +If rounds completed is well below the target, prefer continuing unless the \ +report is already exhaustive. + Reply with ONLY "YES" or "NO" followed by a brief one-sentence reason. Example: "YES — The report covers all major aspects with evidence from multiple sources." Example: "NO — We still lack information about the economic impact." @@ -698,6 +701,7 @@ class DeepResearcher: question=question, report=report, round_num=round_num, + max_rounds=self.max_rounds, ) try: diff --git a/src/research_handler.py b/src/research_handler.py index 4a721cd5e..70433b61b 100644 --- a/src/research_handler.py +++ b/src/research_handler.py @@ -777,7 +777,7 @@ class ResearchHandler: llm_model=llm_model, llm_headers=llm_headers, max_rounds=max_rounds, - min_rounds=min(3, max_rounds), + min_rounds=max(2, max_rounds - 2), max_time=max_time, max_report_tokens=_max_report_tokens, extraction_timeout=_extraction_timeout,