fix(subagent): inherit parent tool configuration

Preserve configured tool settings when building subagent registries while retaining the effective workspace restriction.

Co-authored-by: BillDwyer <BillDwyer@users.noreply.github.com>
This commit is contained in:
chengyongruandBillDwyer authored and chengyongru committed 2026-11-04 18:26:47 +08:00
1 parent 1c66b90088
commit 84d96d8a1e
2 files changed
+50 -5

No files matched your search

+2 -5
View File
@@ -507,11 +507,8 @@ class SubagentManager:
)
def _subagent_tools_config(self) -> ToolsConfig:
return ToolsConfig(
exec=self.tools_config.exec,
web=self.tools_config.web,
file=self.tools_config.file,
restrict_to_workspace=self.restrict_to_workspace,
return self.tools_config.model_copy(
update={"restrict_to_workspace": self.restrict_to_workspace},
)
def _build_tools(
+48
View File
@@ -7,6 +7,8 @@ import pytest
from nanobot.agent.memory import Consolidator
from nanobot.agent.runner import AgentRunResult
from nanobot.agent.subagent import SubagentManager
from nanobot.agent.tools.cli_apps import CliAppsTool
from nanobot.agent.tools.cli_apps_config import CliAppsToolConfig
from nanobot.agent.tools.filesystem import FileToolsConfig
from nanobot.bus.queue import MessageBus
from nanobot.config.schema import ToolsConfig
@@ -89,6 +91,50 @@ def test_subagent_respects_file_tool_toggle(tmp_path):
assert file_tools.isdisjoint(tools.tool_names)
@pytest.mark.asyncio
@pytest.mark.parametrize("project_scoped", [False, True])
async def test_subagent_respects_disabled_cli_apps_in_model_tools(tmp_path, project_scoped, monkeypatch):
monkeypatch.setattr("nanobot.apps.cli.service.get_runtime_subdir", lambda name: tmp_path / name)
provider = MagicMock(spec=LLMProvider)
provider.chat_stream_with_retry = AsyncMock(return_value=LLMResponse(content="done"))
manager = SubagentManager(
workspace=tmp_path,
bus=MessageBus(),
max_tool_result_chars=16_000,
consolidator=MagicMock(spec=Consolidator),
tools_config=ToolsConfig(cli_apps=CliAppsToolConfig(enable=False)),
)
scope = build_workspace_scope(tmp_path, "restricted") if project_scoped else None
result = await manager.run_inline(
task="inspect the workspace",
session_key="test:direct",
runtime=_runtime(provider),
workspace_scope=scope,
)
assert result == "done"
definitions = provider.chat_stream_with_retry.await_args.kwargs["tools"]
tool_names = {definition["function"]["name"] for definition in definitions}
assert "read_file" in tool_names
assert "run_cli_app" not in tool_names
def test_subagent_inherits_cli_app_runtime_settings(tmp_path):
manager = SubagentManager(
workspace=tmp_path,
bus=MessageBus(),
max_tool_result_chars=16_000,
consolidator=MagicMock(spec=Consolidator),
tools_config=ToolsConfig(cli_apps=CliAppsToolConfig(run_timeout=17)),
)
tool = manager._build_tools().get("run_cli_app")
assert isinstance(tool, CliAppsTool)
assert tool.runtime.run_timeout == 17
def test_subagent_prompt_keeps_agent_paths_for_selected_project(tmp_path):
agent_workspace = tmp_path / "agent"
project = tmp_path / "project"
@@ -166,6 +212,8 @@ async def test_subagent_keeps_project_runtime_scope_with_agent_owned_tools(tmp_p
spec = manager.runner.run.call_args.args[0]
assert spec.workspace == project
assert spec.tools.get("read_file")._workspace == agent_workspace.resolve()
assert spec.tools.get("read_file")._restrict_to_workspace is True
assert manager.tools_config.restrict_to_workspace is False
@pytest.mark.asyncio