deer-flow/backend/tests/test_subagent_thinking_config.py
Totoro 8d11aeb97b
feat(subagents): configure thinking and reasoning effort for native workers (#7668)
* feat(subagents): add thinking_enabled and reasoning_effort config for sub-agents (#4875)

(cherry picked from commit b1083728b23504cb0f1d1a463f8db70c5ec1c5a7)

* fix: resolve CI failures for subagent thinking config PR

- Fix UnboundLocalError in task_tool.py: initialize parent_thinking_enabled
  and parent_reasoning_effort before the if runtime block
- Remove unused imports from test_subagent_thinking_config.py
  (SimpleNamespace, pytest, resolve_subagent_model_name)
- Fix import sorting in subagents_config.py and test file
- Add reasoning_effort: None to executor test assertion

(cherry picked from commit 187851e307b871937e48bb67ae1b34b8b69bf92d)

* fix: address review comments - remove parent inheritance, supports_thinking clamp, Literal type

- Remove parent_thinking_enabled/parent_reasoning_effort from metadata
  extraction in task_tool.py (backward compatible: subagents only think
  when explicitly configured)
- Add supports_thinking clamp in _create_agent to prevent cross-model
  mismatch errors
- Change SubagentConfig.reasoning_effort to Literal type
- Fix sandbox_state assignment that was accidentally removed
- Fix syntax errors in subagents_config.py (missing closing parens)
- Update all docstrings/comments from "inherit" to "no override"
- Simplify test helper and remove parent inheritance tests

(cherry picked from commit 74f9c659ef4a98bd1756109929ab0748fab82317)

* feat(subagents): adapt reasoning settings to current native workers

* fix(subagents): retain model context on reasoning rejection

* fix(subagents): preserve model-factory reasoning diagnostics

---------

Co-authored-by: Neon549 <neon549@users.noreply.github.com>
Co-authored-by: Totoro-qaq <279883115+Totoro-qaq@users.noreply.github.com>
2026-10-29 22:26:12 +08:00

42 lines
2.3 KiB
Python

"""Native registry coverage for per-worker reasoning defaults and overrides."""
import pytest
from deerflow.config.subagents_config import CustomSubagentConfig, SubagentOverrideConfig, SubagentsAppConfig
from deerflow.persistence.managed_subagents import ManagedSubagentDefinition
from deerflow.subagents import registry
@pytest.mark.parametrize("source", ["builtin", "config", "managed"])
def test_reasoning_settings_flow_through_registry_without_mutating_definitions(monkeypatch, source):
name = "general-purpose" if source == "builtin" else "researcher"
settings = {"thinking_enabled": True, "reasoning_effort": "deep"}
app_config = SubagentsAppConfig()
monkeypatch.setattr(registry, "_managed_definitions", lambda **_: [])
if source == "builtin":
app_config.agents[name] = SubagentOverrideConfig(**settings)
original = registry.BUILTIN_SUBAGENTS[name]
elif source == "config":
original = CustomSubagentConfig(description="Research", system_prompt="Research the task.", **settings)
app_config.custom_agents[name] = original
else:
original = ManagedSubagentDefinition(name=name, description="Research", system_prompt="Research the task.", **settings)
monkeypatch.setattr(registry, "_managed_definitions", lambda **_: [original])
configured = registry.get_subagent_config(name, app_config=app_config)
assert (configured.thinking_enabled, configured.reasoning_effort) == (True, "deep")
app_config.agents[name] = SubagentOverrideConfig(thinking_enabled=False, reasoning_effort="lite")
overridden = registry.get_subagent_config(name, app_config=app_config)
assert (overridden.thinking_enabled, overridden.reasoning_effort) == (False, "lite")
assert (configured.thinking_enabled, configured.reasoning_effort) == (True, "deep")
assert original.thinking_enabled is (None if source == "builtin" else True)
assert original.reasoning_effort == (None if source == "builtin" else "deep")
def test_unconfigured_workers_keep_reasoning_defaults(monkeypatch):
monkeypatch.setattr(registry, "_managed_definitions", lambda **_: [])
configured = registry.get_subagent_config("general-purpose", app_config=SubagentsAppConfig())
assert configured.thinking_enabled is None
assert configured.reasoning_effort is None