Skip to content

~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.

fix(langgraph-agent): drift-proof research_subtopic description; add #5013 changelog (#5030)

LearningCircuit3969ee5a8add
diff --git a/changelog.d/5013.bugfix.md b/changelog.d/5013.bugfix.md
new file mode 100644
index 0000000000..11478e8877
--- /dev/null
+++ b/changelog.d/5013.bugfix.md
@@ -0,0 +1 @@
+The LangGraph agent's `research_subtopic` tool no longer silently drops inputs beyond the documented "2-5" limit: the cap is lowered from 8 to 5 to match the lead prompt, and any overflow is now surfaced via a logger warning, a `truncated_from` key in progress metadata, and a model-facing note naming the dropped subtopics so the lead agent can re-issue or avoid citing them.
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.py
index ba924fcb6c..1306045017 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
@@ -572,10 +572,15 @@ def _make_research_subtopic_tool(
library / citation URLs fall through to the egress gate unchanged.
"""
- @tool
+ @tool(
+ description=(
+ f"Delegate parallel research on multiple subtopics. Each subtopic is "
+ f"investigated by a separate agent. Pass 2-{MAX_SUBTOPICS} focused "
+ f"research questions."
+ )
+ )
def research_subtopic(subtopics: list[str]) -> str:
- """Delegate parallel research on multiple subtopics. Each subtopic is
- investigated by a separate agent. Pass 2-5 focused research questions."""
+ """Description passed via ``@tool(description=...)`` above — f-strings can't be docstrings."""
from langchain.agents import create_agent
if not subtopics:
diff --git a/tests/strategies/test_langgraph_agent_strategy.py b/tests/strategies/test_langgraph_agent_strategy.py
index c2dd52c0e4..b6761baa38 100644
--- a/tests/strategies/test_langgraph_agent_strategy.py
+++ b/tests/strategies/test_langgraph_agent_strategy.py
@@ -2487,7 +2487,7 @@ class TestResearchSubtopicToolTruncation:
result = tool.invoke({"subtopics": subtopics})
return result, max_sub
- def test_constant_matches_prompt_contract(self):
+ def test_constant_matches_prompt_and_docstring_contract(self):
from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
MAX_SUBTOPICS,
LangGraphAgentStrategy,
@@ -2496,6 +2496,13 @@ class TestResearchSubtopicToolTruncation:
# The constant must agree with the 'pass 2-5' docstring + lead prompt.
assert MAX_SUBTOPICS == 5
+ # The research_subtopic tool docstring is what the lead LLM sees in
+ # its tool schema, so it must render the same constant — a magic
+ # number here could silently diverge if MAX_SUBTOPICS ever changes
+ # (reviewer note on PR #5013 follow-up).
+ tool, _ = self._make_tool()
+ assert f"2-{MAX_SUBTOPICS}" in tool.description
+
# And the lead prompt must render the *same* constant, so the two
# can't silently drift apart — a magic number in the prompt text
# could otherwise diverge from MAX_SUBTOPICS.