~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
enh(langgraph): honor max_subagent_workers above 5 for overflow subtopic batches (#6790)
LearningCircuit3db10af8662b
diff --git a/changelog.d/5585.feature.md b/changelog.d/5585.feature.mdnew file mode 100644index 0000000000..e905ee525e--- /dev/null+++ b/changelog.d/5585.feature.md@@ -0,0 +1,5 @@+langgraph: `langgraph_agent.max_subagent_workers` above 5 is now honored for overflow subtopic batches — 8 subtopics with 8 configured workers run in a single wave instead of being capped at 5 concurrent workers (as the setting's description stated) and split into two waves. The default pool (4), the 2–5 prompt contract, the 10-topic hard limit, and the 32-thread soft cap are unchanged; the batch size still bounds the pool, so a configured value above the batch size clamps to the batch size as before.++Upgrade note: if you had already set `langgraph_agent.max_subagent_workers` above 5, it was previously capped at 5 concurrent subagents per `research_subtopic` call. It now takes effect up to the batch size (10 subtopics max per call), so you will see higher per-call concurrency — and correspondingly more concurrent LLM/search load — than before. Lower the value if your backend can't sustain it.++Progress metadata change: `overflow_queued_count` (documented in the 1.10.3 release notes) now reports how many subtopics actually wait for a free worker, not how many exceed the preferred limit of 5. With the default 4 workers, an 8-subtopic batch now reports 4 instead of 3; with 6 workers it reports 2. When the pool covers the whole batch, `overflow_strategy` is `"parallel"` and `overflow_queued_count` is omitted.diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.mdindex 3f8e401597..68cd2edec5 100644--- a/docs/CONFIGURATION.md+++ b/docs/CONFIGURATION.md@@ -128,7 +128,7 @@ They are not available in the Web UI because they are needed to start the applic| `langgraph_agent.include_sub_research` | `LDR_LANGGRAPH_AGENT_INCLUDE_SUB_RESEARCH` | `true` | Enable parallel subagent research. When enabled, the agent can decompose complex questions into subtopics and research them simultaneously using separate subagents. | SEARCH || `langgraph_agent.max_iterations` | `LDR_LANGGRAPH_AGENT_MAX_ITERATIONS` | `50` | Maximum number of agent reasoning cycles (each cycle = one LLM call + one tool call). Higher values let the agent search more thoroughly but use more tokens. The agent typically needs 10-20 cycles for simple queries and 30-50 for complex multi-faceted research. | SEARCH || `langgraph_agent.max_sub_iterations` | `LDR_LANGGRAPH_AGENT_MAX_SUB_ITERATIONS` | `8` | Maximum reasoning cycles per subagent when researching subtopics in parallel. Each subagent investigates one aspect of the question independently. | SEARCH |-| `langgraph_agent.max_subagent_workers` | `LDR_LANGGRAPH_AGENT_MAX_SUBAGENT_WORKERS` | `4` | Maximum number of subagents that may run in parallel when the lead agent fans out subtopics via research_subtopic. The effective pool is capped at the preferred per-call size of 5; values above 5 do not increase concurrency. Each worker thread serves one subagent at a time; any surplus subtopics queue and start as workers free up (a queued subagent keeps its own per-task budget — it is NOT killed by a shared loop timer). Tune this to match what your LLM backend can sustain in parallel (Ollama / LMStudio / llama.cpp `OLLAMA_NUM_PARALLEL`, an OpenAI tier limit, etc.). Lower values reduce load; higher values up to 5 increase parallelism at the cost of more concurrent LLM/search traffic. | SEARCH |+| `langgraph_agent.max_subagent_workers` | `LDR_LANGGRAPH_AGENT_MAX_SUBAGENT_WORKERS` | `4` | Maximum number of subagents that may run in parallel within a single research_subtopic call. Each call runs up to min(this setting, the number of subtopics passed to that call) workers; a call accepts at most 10 subtopics, so values above 10 do not increase per-call concurrency. Any subtopics beyond the pool size queue within that call and start as workers free up (a queued subagent keeps its own per-task budget — it is NOT killed by a shared loop timer). The lead agent may issue several research_subtopic calls concurrently in one turn, each with its own worker pool, so total concurrency across calls can be a multiple of this value. Tune this to match what your LLM backend can sustain in parallel (Ollama / LMStudio / llama.cpp `OLLAMA_NUM_PARALLEL`, an OpenAI tier limit, etc.). Lower values reduce concurrent LLM/search load; recommended to keep this low for local LLM backends. | SEARCH || `llm.allowed_local_hostnames` | `LDR_LLM_ALLOWED_LOCAL_HOSTNAMES` | ``[]`` | Hostnames the policy will treat as local in addition to loopback / RFC1918 / link-local. Use for self-hosted services on custom hostnames (e.g. 'ollama.lan'). Public hostnames added here are rejected at save time. | LLM || `llm.anthropic.api_key` | `LDR_LLM_ANTHROPIC_API_KEY` | `` | Your Anthropic API key for Claude models. Get one at console.anthropic.com. Required when using the Anthropic provider. | LLM || `llm.anthropic_endpoint.api_key` | `LDR_LLM_ANTHROPIC_ENDPOINT_API_KEY` | `` | Optional API key for your Anthropic-compatible endpoint. Leave blank for self-hosted servers that don't require authentication. | LLM |diff --git a/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.py b/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.pyindex 179bdbae3c..7a93970d22 100644--- a/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/langgraph_agent_strategy.py@@ -101,7 +101,8 @@ CITATION_FALLBACK_NOTICE = ()MAX_SUBTOPICS = 5 # preferred batch size; must match the "pass 2-5" contract# in the lead prompt and research_subtopic tool description. A bounded-# overflow is queued through the existing worker pool instead of discarded.+# overflow runs through the existing worker pool instead of being discarded+# (queued only when the pool is smaller than the batch).MAX_SUBTOPICS_HARD_LIMIT = 10 # reject larger batches before starting workMAX_SUBAGENT_WORKERS = 4 # default pool size when the user has not set# ``langgraph_agent.max_subagent_workers``. Surplus subtopics queue and@@ -1538,8 +1539,8 @@ def _make_research_subtopic_tool(f"Delegate parallel research on multiple subtopics. Each subtopic is "f"investigated by a separate agent. Pass 2-{MAX_SUBTOPICS} focused "f"research questions. Batches up to {MAX_SUBTOPICS_HARD_LIMIT} are "- f"accepted with surplus questions queued; larger batches are "- f"rejected without starting any subagents."+ f"accepted and run up to the configured worker count at once; "+ f"larger batches are rejected without starting any subagents."))def research_subtopic(subtopics: list[str]) -> str:@@ -1585,20 +1586,24 @@ def _make_research_subtopic_tool(overflow_count = max(0, requested_count - MAX_SUBTOPICS)if overflow_count:logger.warning(- "research_subtopic received {} subtopics; queuing {} above preferred limit {}",+ "research_subtopic received {} subtopics; accepting {} above preferred limit {}",requested_count,overflow_count,MAX_SUBTOPICS,)- # Keep overflow beyond the prompt-facing batch size queued even when- # max_subagent_workers is configured above 5. Before overflow support,- # at most MAX_SUBTOPICS tasks reached this pool, so this preserves the- # established concurrency ceiling while allowing bounded extra work.- # Clamp to >=1 so a bad direct caller cannot create a 0-worker pool.- effective_workers = max(- 1, min(max_subagent_workers, MAX_SUBTOPICS, len(subtopics))- )+ # Honor a ``max_subagent_workers`` configured above MAX_SUBTOPICS:+ # the setting exists so a backend sized for a single big wave can+ # run overflow batches concurrently instead of in multiple waves+ # (#5585). The prompt contract stays at 2-5 per batch; the pool is+ # still bounded by the batch size here and by the 32-thread soft+ # cap in ``_coerce_max_subagent_workers``. Clamp to >=1 so a bad+ # direct caller cannot create a 0-worker pool.+ effective_workers = max(1, min(max_subagent_workers, len(subtopics)))+ # Subtopics that actually wait for a free worker. Tasks are submitted+ # in order to a FIFO pool, so this is what exceeds the pool size, not+ # what exceeds MAX_SUBTOPICS (6 workers, 8 subtopics: 2 wait, not 3).+ queued_count = max(0, requested_count - effective_workers)# Build subagent tools ONCE per ``research_subtopic`` call — reused# across all parallel subagent invocations. Each tool factory creates@@ -1676,16 +1681,34 @@ def _make_research_subtopic_tool("type": "milestone","subtopics": subtopics,}- if overflow_count:- meta["overflow_strategy"] = "queued"- meta["overflow_queued_count"] = overflow_count- progress_message = (- f"Researching {len(subtopics)} subtopics with up to "- f"{effective_workers} in parallel ({overflow_count} above "- f"the preferred limit queued)"- if overflow_count- else f"Researching {len(subtopics)} subtopics in parallel"+ # "Queued" is only accurate when the pool is smaller than the+ # batch. With max_subagent_workers configured >= the batch size+ # (honored above MAX_SUBTOPICS per #5585), every subtopic starts+ # in the same wave and nothing actually waits.+ is_queued = bool(overflow_count) and (+ requested_count > effective_workers)+ if overflow_count:+ meta["overflow_strategy"] = (+ "queued" if is_queued else "parallel"+ )+ if is_queued:+ meta["overflow_queued_count"] = queued_count+ if is_queued:+ progress_message = (+ f"Researching {requested_count} subtopics with up to "+ f"{effective_workers} in parallel ({queued_count} "+ f"queued for a free worker)"+ )+ elif overflow_count:+ progress_message = (+ f"Researching {requested_count} subtopics with up to "+ f"{effective_workers} in parallel"+ )+ else:+ progress_message = (+ f"Researching {requested_count} subtopics in parallel"+ )progress_callback(progress_message,None,@@ -1973,14 +1996,28 @@ def _make_research_subtopic_tool(result_text = "\n\n---\n\n".join(parts)# Tell the lead agent how an over-budget but bounded request was handled.- # Every queued topic has a result section above, including timeout/error+ # Every topic has a result section above, including timeout/error# text when its worker did not complete successfully.+ # Two different quantities: ``overflow_count`` is how far the batch+ # exceeds the preferred limit (MAX_SUBTOPICS); ``queued_count`` is how+ # many subtopics had to wait because the batch exceeds the worker pool.if overflow_count:+ if queued_count:+ handling = (+ "were accepted instead of being dropped. Separately, "+ f"with {effective_workers} worker(s), {queued_count} of "+ f"the {requested_count} subtopics in this batch waited "+ "for a free worker"+ )+ else:+ handling = (+ "ran in parallel with the rest of the batch instead of "+ "being dropped"+ )result_text += (f"\n\nOverflow handling: {overflow_count} subtopic(s) beyond "- f"the preferred per-call limit of {MAX_SUBTOPICS} were queued "- f"for processing instead of being dropped; each appears in "- f"the results above."+ f"the preferred per-call limit of {MAX_SUBTOPICS} {handling}. "+ f"Every subtopic appears in the results above.")return result_text@@ -2776,8 +2813,9 @@ class LangGraphAgentStrategy(BaseSearchStrategy):"2. For complex multi-faceted questions, use research_subtopic to "f"investigate specific aspects in parallel (pass 2-{MAX_SUBTOPICS} "f"focused, non-overlapping questions. Batches of "- f"{MAX_SUBTOPICS + 1}-{MAX_SUBTOPICS_HARD_LIMIT} are queued; "- f"larger batches are rejected without doing work).\n"+ f"{MAX_SUBTOPICS + 1}-{MAX_SUBTOPICS_HARD_LIMIT} are accepted and "+ f"run up to the configured worker count at once; larger batches "+ f"are rejected without doing work).\n"f"{fetch_line}""4. When available, use specialized search_[engine] tools for domain-specific searches ""(search_arxiv for science, search_pubmed for medical, etc.).\n"diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.jsonindex 1070e36101..c1a922081c 100644--- a/src/local_deep_research/defaults/default_settings.json+++ b/src/local_deep_research/defaults/default_settings.json@@ -1151,7 +1151,7 @@},"langgraph_agent.max_subagent_workers": {"category": "langgraph_agent",- "description": "Maximum number of subagents that may run in parallel when the lead agent fans out subtopics via research_subtopic. The effective pool is capped at the preferred per-call size of 5; values above 5 do not increase concurrency. Each worker thread serves one subagent at a time; any surplus subtopics queue and start as workers free up (a queued subagent keeps its own per-task budget — it is NOT killed by a shared loop timer). Tune this to match what your LLM backend can sustain in parallel (Ollama / LMStudio / llama.cpp `OLLAMA_NUM_PARALLEL`, an OpenAI tier limit, etc.). Lower values reduce load; higher values up to 5 increase parallelism at the cost of more concurrent LLM/search traffic.",+ "description": "Maximum number of subagents that may run in parallel within a single research_subtopic call. Each call runs up to min(this setting, the number of subtopics passed to that call) workers; a call accepts at most 10 subtopics, so values above 10 do not increase per-call concurrency. Any subtopics beyond the pool size queue within that call and start as workers free up (a queued subagent keeps its own per-task budget — it is NOT killed by a shared loop timer). The lead agent may issue several research_subtopic calls concurrently in one turn, each with its own worker pool, so total concurrency across calls can be a multiple of this value. Tune this to match what your LLM backend can sustain in parallel (Ollama / LMStudio / llama.cpp `OLLAMA_NUM_PARALLEL`, an OpenAI tier limit, etc.). Lower values reduce concurrent LLM/search load; recommended to keep this low for local LLM backends.","editable": true,"max_value": 32,"min_value": 1,diff --git a/tests/settings/golden_master_settings.json b/tests/settings/golden_master_settings.jsonindex 02ffbed5a6..bcc833c2ee 100644--- a/tests/settings/golden_master_settings.json+++ b/tests/settings/golden_master_settings.json@@ -1164,7 +1164,7 @@},"langgraph_agent.max_subagent_workers": {"category": "langgraph_agent",- "description": "Maximum number of subagents that may run in parallel when the lead agent fans out subtopics via research_subtopic. The effective pool is capped at the preferred per-call size of 5; values above 5 do not increase concurrency. Each worker thread serves one subagent at a time; any surplus subtopics queue and start as workers free up (a queued subagent keeps its own per-task budget — it is NOT killed by a shared loop timer). Tune this to match what your LLM backend can sustain in parallel (Ollama / LMStudio / llama.cpp `OLLAMA_NUM_PARALLEL`, an OpenAI tier limit, etc.). Lower values reduce load; higher values up to 5 increase parallelism at the cost of more concurrent LLM/search traffic.",+ "description": "Maximum number of subagents that may run in parallel within a single research_subtopic call. Each call runs up to min(this setting, the number of subtopics passed to that call) workers; a call accepts at most 10 subtopics, so values above 10 do not increase per-call concurrency. Any subtopics beyond the pool size queue within that call and start as workers free up (a queued subagent keeps its own per-task budget — it is NOT killed by a shared loop timer). The lead agent may issue several research_subtopic calls concurrently in one turn, each with its own worker pool, so total concurrency across calls can be a multiple of this value. Tune this to match what your LLM backend can sustain in parallel (Ollama / LMStudio / llama.cpp `OLLAMA_NUM_PARALLEL`, an OpenAI tier limit, etc.). Lower values reduce concurrent LLM/search load; recommended to keep this low for local LLM backends.","editable": true,"max_value": 32,"min_value": 1,diff --git a/tests/strategies/test_langgraph_agent_strategy.py b/tests/strategies/test_langgraph_agent_strategy.pyindex 999eddd5f8..ea47c4ba91 100644--- a/tests/strategies/test_langgraph_agent_strategy.py+++ b/tests/strategies/test_langgraph_agent_strategy.py@@ -5458,10 +5458,11 @@ class TestResearchSubtopicToolOverflow:assert f"## {topic}" in resultassert max_sub == 5assert captured["meta"]["overflow_strategy"] == "queued"- assert captured["meta"]["overflow_queued_count"] == 3+ # The default pool (4) runs topics 0-3; the other 4 wait.+ assert captured["meta"]["overflow_queued_count"] == 4assert "truncated_from" not in captured["meta"]assert "up to 4 in parallel" in captured["message"]- assert "3 above the preferred limit queued" in captured["message"]+ assert "(4 queued for a free worker)" in captured["message"]log.warning.assert_called_once()warning_args = log.warning.call_args.argsassert len(warning_args) == 4@@ -5490,7 +5491,7 @@ class TestResearchSubtopicToolOverflow:assert "Research on 'topic 6' failed: queued worker failed" in resultassert "Overflow handling: 3 subtopic(s)" in resultassert captured["meta"]["overflow_strategy"] == "queued"- assert captured["meta"]["overflow_queued_count"] == 3+ assert captured["meta"]["overflow_queued_count"] == 4@pytest.mark.parametrize(("topic_count", "configured_workers", "expected_workers"),@@ -5498,7 +5499,16 @@ class TestResearchSubtopicToolOverflow:(3, 0, 1),(3, 1, 1),(4, 3, 3),- (8, 10, 5),+ # A configured pool above the batch size still clamps to the+ # batch size -- workers can never exceed subtopics.+ (3, 10, 3),+ # A pool configured above MAX_SUBTOPICS is honored for overflow+ # batches (#5585): 8 workers run 8 queued subtopics in one wave+ # instead of a 5-wide ceiling forcing two waves.+ (8, 10, 8),+ # The hard-limit batch (10 subtopics) runs fully concurrent at+ # the 32-thread soft cap, the maximum the setting advertises.+ (10, 32, 10),],)def test_worker_pool_clamps_all_boundaries(@@ -5528,9 +5538,73 @@ class TestResearchSubtopicToolOverflow:assert "Overflow handling:" in resultassert "3 subtopic(s)" in result- assert "were queued for processing instead of being dropped" in result+ assert "were accepted instead of being dropped" in result+ assert (+ "with 4 worker(s), 4 of the 8 subtopics in this batch waited "+ "for a free worker" in result+ )assert "not investigated" not in result+ def test_overflow_with_pool_between_preferred_limit_and_batch_reports_waiting_count(+ self,+ ):+ """5 < workers < batch: only the topics beyond the pool wait (#5585).++ 8 subtopics with 6 workers start topics 0-5 immediately, so 2 wait,+ not the 3 that exceed MAX_SUBTOPICS(5).+ """+ captured = {}+ subtopics = [f"topic {i}" for i in range(8)]++ result, _ = self._patched_run(+ subtopics,+ progress_callback=lambda *a: captured.update(+ {"message": a[0], "meta": a[2]}+ ),+ max_subagent_workers=6,+ )++ assert captured["meta"]["overflow_strategy"] == "queued"+ assert captured["meta"]["overflow_queued_count"] == 2+ assert "up to 6 in parallel" in captured["message"]+ assert "(2 queued for a free worker)" in captured["message"]++ assert "Overflow handling: 3 subtopic(s)" in result+ assert (+ "with 6 worker(s), 2 of the 8 subtopics in this batch waited "+ "for a free worker" in result+ )++ def test_overflow_with_pool_at_batch_size_reports_parallel_not_queued(+ self,+ ):+ """A pool >= the batch size (#5585) means nothing actually waits.++ 8 subtopics above MAX_SUBTOPICS(5) still count as "overflow" for the+ prompt-contract warning, but with max_subagent_workers configured to+ 8 every subtopic starts in the same wave -- the "queued" wording+ would be false here, so it must say "parallel" instead.+ """+ captured = {}+ subtopics = [f"topic {i}" for i in range(8)]++ result, _ = self._patched_run(+ subtopics,+ progress_callback=lambda *a: captured.update(+ {"message": a[0], "meta": a[2]}+ ),+ max_subagent_workers=8,+ )++ assert captured["meta"]["overflow_strategy"] == "parallel"+ assert "overflow_queued_count" not in captured["meta"]+ assert "up to 8 in parallel" in captured["message"]+ assert "queued" not in captured["message"]++ assert "Overflow handling: 3 subtopic(s)" in result+ assert "ran in parallel with the rest of the batch" in result+ assert "were queued" not in result+def test_exactly_at_preferred_limit_has_no_overflow_signal(self):from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (MAX_SUBTOPICS,@@ -5541,7 +5615,9 @@ class TestResearchSubtopicToolOverflow:result, _ = self._patched_run(subtopics,- progress_callback=lambda *a: captured.update({"meta": a[2]}),+ progress_callback=lambda *a: captured.update(+ {"message": a[0], "meta": a[2]}+ ),)for i in range(MAX_SUBTOPICS):@@ -5549,8 +5625,14 @@ class TestResearchSubtopicToolOverflow:assert "overflow_strategy" not in captured["meta"]assert "truncated_from" not in captured["meta"]assert "Overflow handling:" not in result+ # The default pool (4) is smaller than this batch, but nothing is+ # above the preferred limit, so the progress text must not claim+ # an overflow was queued.+ assert captured["message"] == (+ f"Researching {MAX_SUBTOPICS} subtopics in parallel"+ )- def test_one_over_preferred_limit_queues_exactly_one(self):+ def test_one_over_preferred_limit_is_accepted(self):from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (MAX_SUBTOPICS,)@@ -5565,7 +5647,8 @@ class TestResearchSubtopicToolOverflow:for i in range(MAX_SUBTOPICS + 1):assert f"## topic {i}" in result- assert captured["meta"]["overflow_queued_count"] == 1+ # Default pool of 4: topics 4 and 5 wait for a free worker.+ assert captured["meta"]["overflow_queued_count"] == 2assert "Overflow handling: 1 subtopic(s)" in resultdef test_exactly_at_hard_limit_is_processed(self):