refactor: thread app_config through lead and subagent task path (#2666)

* refactor: thread app config through lead prompt

* fix: honor explicit app config across runtime paths

* style: format subagent executor tests

* fix: thread resolved app config and guard subagents-only fallback

Address two PR review findings:

1. _create_summarization_middleware passed the original (possibly None)
   app_config into create_chat_model, forcing the model factory back to
   ambient get_app_config() and risking config drift between the
   middleware's resolved view and the model's view. Pass the resolved
   AppConfig instance through end-to-end.

2. get_available_subagent_names accepted Any-typed config and forwarded
   it to is_host_bash_allowed, which reads ``.sandbox``. A
   SubagentsAppConfig (also accepted upstream as a sum-type input) has
   no ``.sandbox`` attribute and would be silently treated as "no
   sandbox configured", incorrectly disabling the bash subagent. Guard
   on hasattr and fall back to ambient lookup otherwise.

Adds regression tests for both paths.

* chore: simplify hasattr guard and tighten regression tests

- Collapse if/else into ternary in get_available_subagent_names; hasattr(None, ...) is False so the explicit None check was redundant.
- Drop comments that narrate the change rather than explain non-obvious WHY (test names already convey intent).
- Replace stringly-typed sentinel "no-arg" in regression test with direct args tuple comparison.

---------

Co-authored-by: greatmengqi <chenmengqi.0376@bytedance.com>
This commit is contained in:
greatmengqi
2026-05-02 06:37:49 +08:00
committed by GitHub
parent 189b82405c
commit 8ba01dfd83
19 changed files with 769 additions and 153 deletions
@@ -9,6 +9,8 @@ Covers:
- Skills filter passthrough in task_tool config assembly
"""
from types import SimpleNamespace
import pytest
from deerflow.config.subagents_config import (
@@ -343,12 +345,54 @@ class TestRegistryCustomAgentLookup:
assert config.timeout_seconds == 600
assert config.model == "inherit"
def test_custom_agent_found_from_explicit_app_config_without_global_config(self, monkeypatch):
from deerflow.subagents.registry import get_subagent_config
def fail_get_subagents_app_config():
raise AssertionError("ambient get_subagents_app_config() must not be used when app_config is explicit")
monkeypatch.setattr("deerflow.config.subagents_config.get_subagents_app_config", fail_get_subagents_app_config)
app_config = SimpleNamespace(
subagents=SubagentsAppConfig(
custom_agents={
"analysis": CustomSubagentConfig(
description="Data analysis specialist",
system_prompt="You are a data analysis subagent.",
skills=["data-analysis"],
)
}
)
)
config = get_subagent_config("analysis", app_config=app_config)
assert config is not None
assert config.name == "analysis"
assert config.skills == ["data-analysis"]
def test_custom_agent_not_found(self):
from deerflow.subagents.registry import get_subagent_config
_reset_subagents_config()
assert get_subagent_config("nonexistent") is None
def test_get_available_subagent_names_falls_back_when_subagents_app_config_lacks_sandbox(self, monkeypatch):
from deerflow.subagents import registry as registry_module
from deerflow.subagents.registry import get_available_subagent_names
captured: dict[str, tuple] = {}
def fake_is_host_bash_allowed(*args, **kwargs):
captured["args"] = args
return True
monkeypatch.setattr(registry_module, "is_host_bash_allowed", fake_is_host_bash_allowed)
get_available_subagent_names(app_config=SubagentsAppConfig())
assert captured["args"] == ()
def test_builtin_takes_priority_over_custom(self):
"""If a custom agent has the same name as a builtin, builtin wins."""
from deerflow.subagents.builtins import BUILTIN_SUBAGENTS