diff --git a/backend/packages/harness/deerflow/community/ddg_search/tools.py b/backend/packages/harness/deerflow/community/ddg_search/tools.py index a91aec1975..7cbdbe79d0 100644 --- a/backend/packages/harness/deerflow/community/ddg_search/tools.py +++ b/backend/packages/harness/deerflow/community/ddg_search/tools.py @@ -33,10 +33,14 @@ WIKIPEDIA_LANGUAGE_ALIASES = { def _coerce_max_results(value: object) -> int: """Normalize config/parameter values before passing them to DDGS.""" - try: - count = int(value) # type: ignore[call-overload] - except (TypeError, ValueError, OverflowError): + if isinstance(value, bool) or (isinstance(value, float) and not value.is_integer()): + # int() accepts booleans and silently truncates a YAML value such as 3.5. count = 0 + else: + try: + count = int(value) # type: ignore[call-overload] + except (TypeError, ValueError, OverflowError): + count = 0 if count <= 0: logger.warning("Invalid DDG Search max_results=%r; using default %s", value, DEFAULT_MAX_RESULTS) return DEFAULT_MAX_RESULTS diff --git a/backend/tests/test_ddg_search_tools.py b/backend/tests/test_ddg_search_tools.py index be37a9eedf..dca29aca89 100644 --- a/backend/tests/test_ddg_search_tools.py +++ b/backend/tests/test_ddg_search_tools.py @@ -22,6 +22,8 @@ from deerflow.community.ddg_search import tools pytest.param("$DDG_TEST_MAX_RESULTS", "abc", {"max_results": 2}, 5, True, id="invalid-env"), pytest.param("$DDG_TEST_MAX_RESULTS", "", {"max_results": 2}, 5, True, id="empty-env"), pytest.param("$DDG_TEST_MAX_RESULTS", "3.5", {"max_results": 2}, 5, True, id="fractional-env"), + pytest.param(3.5, "3", {"max_results": 2}, 5, True, id="fractional-config"), + pytest.param(True, "3", {"max_results": 2}, 5, True, id="boolean-config"), pytest.param("$DDG_TEST_MAX_RESULTS", "0", {"max_results": 2}, 5, True, id="zero-env"), pytest.param("$DDG_TEST_MAX_RESULTS", "-2", {"max_results": 2}, 5, True, id="negative-env"), pytest.param(0, "3", {}, 5, True, id="zero-config"),